DbClient db;
RulesWs ws;
RuleDao ruleDao;
- DbSession session;
+ DbSession dbSession;
int softReliabilityId;
int hardReliabilityId;
db = tester.get(DbClient.class);
ruleDao = tester.get(RuleDao.class);
ws = tester.get(RulesWs.class);
- session = tester.get(DbClient.class).openSession(false);
+ dbSession = tester.get(DbClient.class).openSession(false);
}
@After
public void after() {
- session.close();
+ dbSession.close();
}
@Test
@Test
public void filter_by_key_rules() throws Exception {
- ruleDao.insert(session, RuleTesting.newXooX1());
- ruleDao.insert(session, RuleTesting.newXooX2());
- session.commit();
+ ruleDao.insert(dbSession, RuleTesting.newXooX1());
+ ruleDao.insert(dbSession, RuleTesting.newXooX2());
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(SearchAction.PARAM_KEY, RuleTesting.XOO_X1.toString());
@Test
public void search_2_rules() throws Exception {
- ruleDao.insert(session, RuleTesting.newXooX1());
- ruleDao.insert(session, RuleTesting.newXooX2());
- session.commit();
+ ruleDao.insert(dbSession, RuleTesting.newXooX1());
+ ruleDao.insert(dbSession, RuleTesting.newXooX2());
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
WsTester.Result result = request.execute();
@Test
public void search_2_rules_with_field_selection() throws Exception {
- ruleDao.insert(session, RuleTesting.newXooX1());
- ruleDao.insert(session, RuleTesting.newXooX2().setDescription("A *Xoo* rule").setDescriptionFormat(RuleDto.Format.MARKDOWN));
- session.commit();
+ ruleDao.insert(dbSession, RuleTesting.newXooX1());
+ ruleDao.insert(dbSession, RuleTesting.newXooX2().setDescription("A *Xoo* rule").setDescriptionFormat(RuleDto.Format.MARKDOWN));
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(WebService.Param.FIELDS, "name,htmlDesc,mdDesc");
WsTester.Result result = request.execute();
@Test
public void return_lang_field() throws Exception {
- ruleDao.insert(session, RuleTesting.newXooX1());
- session.commit();
+ ruleDao.insert(dbSession, RuleTesting.newXooX1());
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(WebService.Param.FIELDS, "lang");
WsTester.Result result = request.execute();
@Test
public void return_lang_name_field() throws Exception {
- ruleDao.insert(session, RuleTesting.newXooX1());
- session.commit();
+ ruleDao.insert(dbSession, RuleTesting.newXooX1());
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(WebService.Param.FIELDS, "langName");
WsTester.Result result = request.execute();
@Test
public void return_lang_key_field_when_language_name_is_not_available() throws Exception {
- ruleDao.insert(session, RuleTesting.newDto(RuleKey.of("other", "rule"))).setLanguage("unknown");
- session.commit();
+ ruleDao.insert(dbSession, RuleTesting.newDto(RuleKey.of("other", "rule"))).setLanguage("unknown");
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD).setParam(WebService.Param.FIELDS, "langName");
WsTester.Result result = request.execute();
@Test
public void search_debt_rules() throws Exception {
- insertDebtCharacteristics(session);
+ insertDebtCharacteristics(dbSession);
- ruleDao.insert(session, RuleTesting.newXooX1()
+ ruleDao.insert(dbSession, RuleTesting.newXooX1()
.setDefaultSubCharacteristicId(hardReliabilityId)
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
.setDefaultRemediationCoefficient("1h")
.setRemediationCoefficient(null)
.setRemediationOffset(null)
);
- session.commit();
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
@Test
public void search_debt_rules_with_default_and_overridden_debt_values() throws Exception {
- insertDebtCharacteristics(session);
+ insertDebtCharacteristics(dbSession);
- ruleDao.insert(session, RuleTesting.newXooX1()
+ ruleDao.insert(dbSession, RuleTesting.newXooX1()
.setDefaultSubCharacteristicId(hardReliabilityId)
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
.setDefaultRemediationCoefficient("1h")
.setRemediationCoefficient("2h")
.setRemediationOffset("25min")
);
- session.commit();
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
@Test
public void search_debt_rules_with_default_linear_offset_and_overridden_constant_debt() throws Exception {
- insertDebtCharacteristics(session);
+ insertDebtCharacteristics(dbSession);
- ruleDao.insert(session, RuleTesting.newXooX1()
+ ruleDao.insert(dbSession, RuleTesting.newXooX1()
.setDefaultSubCharacteristicId(hardReliabilityId)
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
.setDefaultRemediationCoefficient("1h")
.setRemediationCoefficient(null)
.setRemediationOffset("5min")
);
- session.commit();
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
@Test
public void search_debt_rules_with_default_linear_offset_and_overridden_linear_debt() throws Exception {
- insertDebtCharacteristics(session);
+ insertDebtCharacteristics(dbSession);
- ruleDao.insert(session, RuleTesting.newXooX1()
+ ruleDao.insert(dbSession, RuleTesting.newXooX1()
.setDefaultSubCharacteristicId(hardReliabilityId)
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
.setDefaultRemediationCoefficient("1h")
.setRemediationCoefficient("1h")
.setRemediationOffset(null)
);
- session.commit();
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn");
@Test
public void debt_characteristics_is_sticky_facet() throws Exception {
- insertDebtCharacteristics(session);
+ insertDebtCharacteristics(dbSession);
- ruleDao.insert(session, RuleTesting.newXooX1()
+ ruleDao.insert(dbSession, RuleTesting.newXooX1()
.setDefaultSubCharacteristicId(hardReliabilityId)
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
.setDefaultRemediationCoefficient("1h")
.setRemediationCoefficient(null)
.setRemediationOffset(null)
);
- ruleDao.insert(session, RuleTesting.newXooX2()
+ ruleDao.insert(dbSession, RuleTesting.newXooX2()
.setDefaultSubCharacteristicId(hardReliabilityId)
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
.setDefaultRemediationCoefficient("1h")
.setRemediationCoefficient("30min")
.setRemediationOffset("5min")
);
- ruleDao.insert(session, RuleTesting.newXooX3()
+ ruleDao.insert(dbSession, RuleTesting.newXooX3()
.setDefaultSubCharacteristicId(null)
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
.setDefaultRemediationCoefficient("2min")
.setRemediationCoefficient(null)
.setRemediationOffset(null)
);
- ruleDao.insert(session, RuleTesting.newDto(RuleKey.of("xoo", "x4")).setLanguage("xoo")
+ ruleDao.insert(dbSession, RuleTesting.newDto(RuleKey.of("xoo", "x4")).setLanguage("xoo")
.setDefaultSubCharacteristicId(softReliabilityId)
.setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name())
.setDefaultRemediationCoefficient("2min")
.setRemediationCoefficient(null)
.setRemediationOffset(null)
);
- session.commit();
+ dbSession.commit();
WsTester.Result result = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD)
.setParam(WebService.Param.FIELDS, "debtChar,debtCharName,debtSubChar,debtSubCharName,debtRemFn,debtOverloaded,defaultDebtChar,defaultDebtSubChar,defaultDebtRemFn")
@Test
public void search_template_rules() throws Exception {
RuleDto templateRule = RuleTesting.newXooX1().setIsTemplate(true);
- ruleDao.insert(session, templateRule);
- ruleDao.insert(session, RuleTesting.newXooX2()).setTemplateId(templateRule.getId());
- session.commit();
+ ruleDao.insert(dbSession, templateRule);
+ ruleDao.insert(dbSession, RuleTesting.newXooX2()).setTemplateId(templateRule.getId());
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.FIELDS, "isTemplate");
@Test
public void search_custom_rules_from_template_key() throws Exception {
RuleDto templateRule = RuleTesting.newXooX1().setIsTemplate(true);
- ruleDao.insert(session, templateRule);
- ruleDao.insert(session, RuleTesting.newXooX2()).setTemplateId(templateRule.getId());
- session.commit();
+ ruleDao.insert(dbSession, templateRule);
+ ruleDao.insert(dbSession, RuleTesting.newXooX2()).setTemplateId(templateRule.getId());
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.FIELDS, "templateKey");
@Test
public void search_all_active_rules() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1();
- tester.get(QualityProfileDao.class).insert(session, profile);
+ tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDto rule = RuleTesting.newXooX1();
- ruleDao.insert(session, rule);
+ ruleDao.insert(dbSession, rule);
ActiveRuleDto activeRule = newActiveRule(profile, rule);
- tester.get(ActiveRuleDao.class).insert(session, activeRule);
- session.commit();
+ tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.TEXT_QUERY, "x1");
@Test
public void search_profile_active_rules() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1();
- tester.get(QualityProfileDao.class).insert(session, profile);
+ tester.get(QualityProfileDao.class).insert(dbSession, profile);
QualityProfileDto profile2 = QProfileTesting.newXooP2();
- tester.get(QualityProfileDao.class).insert(session, profile2);
+ tester.get(QualityProfileDao.class).insert(dbSession, profile2);
- session.commit();
+ dbSession.commit();
RuleDto rule = RuleTesting.newXooX1();
- ruleDao.insert(session, rule);
+ ruleDao.insert(dbSession, rule);
+
+ RuleParamDto param = RuleParamDto.createFor(rule)
+ .setDefaultValue("some value")
+ .setType("string")
+ .setDescription("My small description")
+ .setName("my_var");
+ ruleDao.insertRuleParam(dbSession, rule, param);
+
+ RuleParamDto param2 = RuleParamDto.createFor(rule)
+ .setDefaultValue("other value")
+ .setType("integer")
+ .setDescription("My small description")
+ .setName("the_var");
+ ruleDao.insertRuleParam(dbSession, rule, param2);
+
+ // SONAR-7083
+ RuleParamDto param3 = RuleParamDto.createFor(rule)
+ .setDefaultValue(null)
+ .setType("string")
+ .setDescription("Empty Param")
+ .setName("empty_var");
+ ruleDao.insertRuleParam(dbSession, rule, param3);
ActiveRuleDto activeRule = newActiveRule(profile, rule);
- tester.get(ActiveRuleDao.class).insert(session, activeRule);
+ tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
ActiveRuleDto activeRule2 = newActiveRule(profile2, rule);
- tester.get(ActiveRuleDao.class).insert(session, activeRule2);
+ tester.get(ActiveRuleDao.class).insert(dbSession, activeRule2);
+
+ ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param)
+ .setValue("The VALUE");
+ tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule2, activeRuleParam);
+
+ ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(param2)
+ .setValue("The Other Value");
+ tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule2, activeRuleParam2);
+
+ ActiveRuleParamDto activeRuleParam3 = ActiveRuleParamDto.createFor(param3)
+ .setValue(null);
+ tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule2, activeRuleParam3);
- session.commit();
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.TEXT_QUERY, "x1");
@Test
public void search_profile_active_rules_with_inheritance() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1();
- tester.get(QualityProfileDao.class).insert(session, profile);
+ tester.get(QualityProfileDao.class).insert(dbSession, profile);
QualityProfileDto profile2 = QProfileTesting.newXooP2().setParentKee(profile.getKee());
- tester.get(QualityProfileDao.class).insert(session, profile2);
+ tester.get(QualityProfileDao.class).insert(dbSession, profile2);
- session.commit();
+ dbSession.commit();
RuleDto rule = RuleTesting.newXooX1();
- ruleDao.insert(session, rule);
+ ruleDao.insert(dbSession, rule);
ActiveRuleDto activeRule = newActiveRule(profile, rule);
- tester.get(ActiveRuleDao.class).insert(session, activeRule);
+ tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
ActiveRuleDto activeRule2 = newActiveRule(profile2, rule).setInheritance(ActiveRuleDto.OVERRIDES).setSeverity(Severity.CRITICAL);
- tester.get(ActiveRuleDao.class).insert(session, activeRule2);
+ tester.get(ActiveRuleDao.class).insert(dbSession, activeRule2);
- session.commit();
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.TEXT_QUERY, "x1");
@Test
public void search_all_active_rules_params() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1();
- tester.get(QualityProfileDao.class).insert(session, profile);
+ tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDto rule = RuleTesting.newXooX1();
- ruleDao.insert(session, rule);
- session.commit();
+ ruleDao.insert(dbSession, rule);
+ dbSession.commit();
RuleParamDto param = RuleParamDto.createFor(rule)
.setDefaultValue("some value")
.setType("string")
.setDescription("My small description")
.setName("my_var");
- ruleDao.insertRuleParam(session, rule, param);
+ ruleDao.insertRuleParam(dbSession, rule, param);
RuleParamDto param2 = RuleParamDto.createFor(rule)
.setDefaultValue("other value")
.setType("integer")
.setDescription("My small description")
.setName("the_var");
- ruleDao.insertRuleParam(session, rule, param2);
+ ruleDao.insertRuleParam(dbSession, rule, param2);
ActiveRuleDto activeRule = newActiveRule(profile, rule);
- tester.get(ActiveRuleDao.class).insert(session, activeRule);
+ tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param)
.setValue("The VALUE");
- tester.get(ActiveRuleDao.class).insertParam(session, activeRule, activeRuleParam);
+ tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule, activeRuleParam);
ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(param2)
.setValue("The Other Value");
- tester.get(ActiveRuleDao.class).insertParam(session, activeRule, activeRuleParam2);
- session.commit();
+ tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule, activeRuleParam2);
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.TEXT_QUERY, "x1");
@Test
public void get_note_as_markdown_and_html() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1();
- tester.get(QualityProfileDao.class).insert(session, profile);
+ tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDto rule = RuleTesting.newXooX1().setNoteData("this is *bold*");
- ruleDao.insert(session, rule);
- session.commit();
+ ruleDao.insert(dbSession, rule);
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.FIELDS, "htmlNote, mdNote");
@Test
public void filter_by_tags() throws Exception {
- ruleDao.insert(session, RuleTesting.newXooX1()
+ ruleDao.insert(dbSession, RuleTesting.newXooX1()
.setTags(Collections.<String>emptySet())
.setSystemTags(ImmutableSet.of("tag1")));
- ruleDao.insert(session, RuleTesting.newXooX2()
+ ruleDao.insert(dbSession, RuleTesting.newXooX2()
.setTags(Collections.<String>emptySet())
.setSystemTags(ImmutableSet.of("tag2")));
- session.commit();
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(SearchAction.PARAM_TAGS, "tag1");
@Test
public void statuses_facet_should_be_sticky() throws Exception {
- ruleDao.insert(session, RuleTesting.newXooX1());
- ruleDao.insert(session, RuleTesting.newXooX2().setStatus(RuleStatus.BETA));
- ruleDao.insert(session, RuleTesting.newXooX3().setStatus(RuleStatus.DEPRECATED));
- session.commit();
+ ruleDao.insert(dbSession, RuleTesting.newXooX1());
+ ruleDao.insert(dbSession, RuleTesting.newXooX2().setStatus(RuleStatus.BETA));
+ ruleDao.insert(dbSession, RuleTesting.newXooX3().setStatus(RuleStatus.DEPRECATED));
+ dbSession.commit();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(SearchAction.PARAM_STATUSES, "DEPRECATED");
@Test
public void sort_by_name() throws Exception {
- ruleDao.insert(session, RuleTesting.newXooX1().setName("Dodgy - Consider returning a zero length array rather than null "));
- ruleDao.insert(session, RuleTesting.newXooX2().setName("Bad practice - Creates an empty zip file entry"));
- ruleDao.insert(session, RuleTesting.newXooX3().setName("XPath rule"));
- session.commit();
+ ruleDao.insert(dbSession, RuleTesting.newXooX1().setName("Dodgy - Consider returning a zero length array rather than null "));
+ ruleDao.insert(dbSession, RuleTesting.newXooX2().setName("Bad practice - Creates an empty zip file entry"));
+ ruleDao.insert(dbSession, RuleTesting.newXooX3().setName("XPath rule"));
+ dbSession.commit();
// 1. Sort Name Asc
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
@Test
public void available_since() throws Exception {
- ruleDao.insert(session, RuleTesting.newXooX1());
- ruleDao.insert(session, RuleTesting.newXooX2());
- session.commit();
- session.clearCache();
+ ruleDao.insert(dbSession, RuleTesting.newXooX1());
+ ruleDao.insert(dbSession, RuleTesting.newXooX2());
+ dbSession.commit();
+ dbSession.clearCache();
Date since = new Date();