Search in sources :

Example 51 with QualityProfileDto

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");
}
Also used : QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 52 with QualityProfileDto

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");
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleParamDto(org.sonar.db.rule.RuleParamDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 53 with QualityProfileDto

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");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) QualityProfileTesting.newQualityProfileDto(org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Date(java.util.Date) Test(org.junit.Test)

Example 54 with QualityProfileDto

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");
}
Also used : Locale(java.util.Locale) WsTester(org.sonar.server.ws.WsTester) Language(org.sonar.api.resources.Language) RuleRepositoryDto(org.sonar.db.rule.RuleRepositoryDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 55 with QualityProfileDto

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());
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) RuleActivation(org.sonar.server.qualityprofile.RuleActivation) RuleQuery(org.sonar.server.rule.index.RuleQuery) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Aggregations

QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)126 Test (org.junit.Test)76 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)37 RuleDto (org.sonar.db.rule.RuleDto)29 WsTester (org.sonar.server.ws.WsTester)21 RuleQuery (org.sonar.server.rule.index.RuleQuery)14 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)13 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)12 DbSession (org.sonar.db.DbSession)11 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)9 SearchOptions (org.sonar.server.es.SearchOptions)9 ComponentDto (org.sonar.db.component.ComponentDto)8 OrganizationDto (org.sonar.db.organization.OrganizationDto)7 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)6 Date (java.util.Date)5 QualityProfileTesting.newQualityProfileDto (org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfileDto)5 RuleParamDto (org.sonar.db.rule.RuleParamDto)5 RulesProfile (org.sonar.api.profiles.RulesProfile)4 Language (org.sonar.api.resources.Language)4 RuleKey (org.sonar.api.rule.RuleKey)4