use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class SearchActionMediumTest method get_note_as_markdown_and_html.
@Test
public void get_note_as_markdown_and_html() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDto rule = RuleTesting.newXooX1().setNoteData("this is *bold*");
ruleDao.insert(dbSession, rule);
dbSession.commit();
ruleIndexer.index();
activeRuleIndexer.index();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.FIELDS, "htmlNote, mdNote");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "get_note_as_markdown_and_html.json");
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class SearchActionMediumTest method search_all_active_rules_params.
@Test
public void search_all_active_rules_params() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDto rule = RuleTesting.newXooX1();
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(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);
ActiveRuleDto activeRule = newActiveRule(profile, rule);
tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param).setValue("The VALUE");
tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule, activeRuleParam);
ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(param2).setValue("The Other Value");
tester.get(ActiveRuleDao.class).insertParam(dbSession, activeRule, activeRuleParam2);
dbSession.commit();
ruleIndexer.index();
activeRuleIndexer.index();
WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
request.setParam(WebService.Param.TEXT_QUERY, "x1");
request.setParam(PARAM_ACTIVATION, "true");
request.setParam(WebService.Param.FIELDS, "params");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_active_rules_params.json");
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class SearchActionTest method search_by_profile_name.
@Test
public void search_by_profile_name() {
OrganizationDto org = db.organizations().insert();
QualityProfileDto qualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-12345").setOrganizationUuid(org.getUuid()).setLanguage(xoo1.getKey()).setRulesUpdatedAtAsDate(new Date()).setName("Sonar way");
QualityProfileDto qualityProfileOnXoo2 = QualityProfileDto.createFor("sonar-way-xoo2-12345").setOrganizationUuid(org.getUuid()).setLanguage(xoo2.getKey()).setRulesUpdatedAtAsDate(new Date()).setName("Sonar way");
QualityProfileDto anotherQualityProfileOnXoo1 = QualityProfileDto.createFor("sonar-way-xoo1-45678").setOrganizationUuid(org.getUuid()).setLanguage(xoo1.getKey()).setRulesUpdatedAtAsDate(new Date()).setName("Another way");
qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1);
ComponentDto project = componentDb.insertComponent(newProjectDto(org, "project-uuid"));
String result = ws.newRequest().setParam(PARAM_PROJECT_KEY, project.key()).setParam(PARAM_PROFILE_NAME, "Sonar way").execute().getInput();
assertThat(result).contains("sonar-way-xoo1-12345", "sonar-way-xoo2-12345").doesNotContain("sonar-way-xoo1-45678");
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class AppActionTest method should_generate_app_init_info.
@Test
public void should_generate_app_init_info() throws Exception {
AppAction app = new AppAction(languages, db.getDbClient(), i18n, userSessionRule, defaultOrganizationProvider);
WsTester tester = new WsTester(new RulesWs(app));
userSessionRule.addPermission(ADMINISTER_QUALITY_PROFILES, defaultOrganizationProvider.get().getUuid());
QualityProfileDto profile1 = QProfileTesting.newXooP1("org-123");
QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123").setParentKee(QProfileTesting.XOO_P1_KEY);
db.getDbClient().qualityProfileDao().insert(db.getSession(), profile1);
db.getDbClient().qualityProfileDao().insert(db.getSession(), profile2);
db.commit();
Language xoo = mock(Language.class);
when(xoo.getKey()).thenReturn("xoo");
when(xoo.getName()).thenReturn("Xoo");
Language whitespace = mock(Language.class);
when(whitespace.getKey()).thenReturn("ws");
when(whitespace.getName()).thenReturn("Whitespace");
when(languages.get("xoo")).thenReturn(xoo);
when(languages.all()).thenReturn(new Language[] { xoo, whitespace });
RuleRepositoryDto repo1 = new RuleRepositoryDto("xoo", "xoo", "SonarQube");
RuleRepositoryDto repo2 = new RuleRepositoryDto("squid", "ws", "SonarQube");
db.getDbClient().ruleRepositoryDao().insert(db.getSession(), asList(repo1, repo2));
db.getSession().commit();
when(i18n.message(isA(Locale.class), anyString(), anyString())).thenAnswer(invocation -> invocation.getArguments()[1]);
tester.newGetRequest("api/rules", "app").execute().assertJson(this.getClass(), "app.json");
}
use of org.sonar.db.qualityprofile.QualityProfileDto in project sonarqube by SonarSource.
the class RuleDeleterMediumTest method delete_custom_rule.
@Test
public void delete_custom_rule() {
// Create template rule
RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("xoo", "T1")).setLanguage("xoo").setCreatedAt(PAST).setUpdatedAt(PAST);
dao.insert(dbSession, templateRule);
// Create custom rule
RuleDto customRule = RuleTesting.newCustomRule(templateRule).setLanguage("xoo").setCreatedAt(PAST).setUpdatedAt(PAST);
dao.insert(dbSession, customRule);
// Create a quality profile
QualityProfileDto profileDto = QProfileTesting.newXooP1("org-123");
db.qualityProfileDao().insert(dbSession, profileDto);
dbSession.commit();
dbSession.clearCache();
ruleIndexer.index();
activeRuleIndexer.index();
// Activate the custom rule
activate(new RuleActivation(customRule.getKey()).setSeverity(Severity.BLOCKER), QProfileTesting.XOO_P1_KEY);
// Delete custom rule
deleter.delete(customRule.getKey());
// Verify custom rule have status REMOVED
RuleDto customRuleReloaded = dao.selectOrFailByKey(dbSession, customRule.getKey());
assertThat(customRuleReloaded).isNotNull();
assertThat(customRuleReloaded.getStatus()).isEqualTo(RuleStatus.REMOVED);
assertThat(customRuleReloaded.getUpdatedAt()).isNotEqualTo(PAST);
// Verify there's no more active rule from custom rule
assertThat(index.searchAll(new RuleQuery().setQProfileKey(profileDto.getKey()).setActivation(true))).isEmpty();
// Verify in index
assertThat(index.searchAll(new RuleQuery())).containsOnly(templateRule.getKey());
}
Aggregations