Search in sources :

Example 1 with RuleIndex

use of org.sonar.server.rule.index.RuleIndex in project sonarqube by SonarSource.

the class QProfileComparisonTest method before.

@Before
public void before() {
    DbClient db = dbTester.getDbClient();
    dbSession = db.openSession(false);
    RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
    ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(db, es.client());
    QualityProfileChangeEventService qualityProfileChangeEventService = mock(QualityProfileChangeEventService.class);
    RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, db, new TypeValidations(singletonList(new IntegerTypeValidation())), userSession);
    qProfileRules = new QProfileRulesImpl(db, ruleActivator, ruleIndex, activeRuleIndexer, qualityProfileChangeEventService);
    comparison = new QProfileComparison(db);
    xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR").getDefinition();
    xooRule2 = RuleTesting.newXooX2().setSeverity("MAJOR").getDefinition();
    db.ruleDao().insert(dbSession, xooRule1);
    db.ruleDao().insert(dbSession, xooRule2);
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("max").setType(RuleParamType.INTEGER.type()));
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("min").setType(RuleParamType.INTEGER.type()));
    left = QualityProfileTesting.newQualityProfileDto().setLanguage("xoo");
    right = QualityProfileTesting.newQualityProfileDto().setLanguage("xoo");
    db.qualityProfileDao().insert(dbSession, left, right);
    dbSession.commit();
}
Also used : ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) QualityProfileChangeEventService(org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService) RuleIndex(org.sonar.server.rule.index.RuleIndex) DbClient(org.sonar.db.DbClient) IntegerTypeValidation(org.sonar.server.util.IntegerTypeValidation) RuleActivator(org.sonar.server.qualityprofile.builtin.RuleActivator) TypeValidations(org.sonar.server.util.TypeValidations) Before(org.junit.Before)

Example 2 with RuleIndex

use of org.sonar.server.rule.index.RuleIndex in project sonarqube by SonarSource.

the class ShowActionTest method json_example.

@Test
public void json_example() {
    Language cs = newLanguage("cs", "C#");
    QProfileDto parentProfile = db.qualityProfiles().insert(p -> p.setKee("AU-TpxcA-iU5OvuD2FL1").setName("Parent Company Profile").setLanguage(cs.getKey()));
    QProfileDto profile = db.qualityProfiles().insert(p -> p.setKee("AU-TpxcA-iU5OvuD2FL3").setName("My Company Profile").setLanguage(cs.getKey()).setIsBuiltIn(false).setRulesUpdatedAt("2016-12-22T19:10:03+0100").setParentKee(parentProfile.getKee()));
    // Active rules
    range(0, 10).mapToObj(i -> db.rules().insertRule(r -> r.setLanguage(cs.getKey())).getDefinition()).forEach(r -> db.qualityProfiles().activateRule(profile, r));
    // Projects
    range(0, 7).mapToObj(i -> db.components().insertPrivateProjectDto()).forEach(project -> db.qualityProfiles().associateWithProject(project, profile));
    ws = new WsActionTester(new ShowAction(db.getDbClient(), new QProfileWsSupport(db.getDbClient(), userSession), new Languages(cs), ruleIndex));
    String result = ws.newRequest().setParam(PARAM_KEY, profile.getKee()).execute().getInput();
    assertJson(result).ignoreFields("rulesUpdatedAt", "lastUsed", "userUpdatedAt").isSimilarTo(ws.getDef().responseExampleAsString());
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) IntStream.range(java.util.stream.IntStream.range) EsTester(org.sonar.server.es.EsTester) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) DateUtils(org.sonar.api.utils.DateUtils) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_COMPARE_TO_SONAR_WAY(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_COMPARE_TO_SONAR_WAY) ShowResponse(org.sonarqube.ws.Qualityprofiles.ShowResponse) MediaTypes(org.sonarqube.ws.MediaTypes) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) Language(org.sonar.api.resources.Language) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) QualityProfile(org.sonarqube.ws.Qualityprofiles.ShowResponse.QualityProfile) System2(org.sonar.api.utils.System2) LanguageTesting.newLanguage(org.sonar.server.language.LanguageTesting.newLanguage) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) RuleIndex(org.sonar.server.rule.index.RuleIndex) WsActionTester(org.sonar.server.ws.WsActionTester) DEPRECATED(org.sonar.api.rule.RuleStatus.DEPRECATED) NotFoundException(org.sonar.server.exceptions.NotFoundException) CompareToSonarWay(org.sonarqube.ws.Qualityprofiles.ShowResponse.CompareToSonarWay) Rule(org.junit.Rule) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) PARAM_KEY(org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Language(org.sonar.api.resources.Language) LanguageTesting.newLanguage(org.sonar.server.language.LanguageTesting.newLanguage) Languages(org.sonar.api.resources.Languages) WsActionTester(org.sonar.server.ws.WsActionTester) Test(org.junit.Test)

Example 3 with RuleIndex

use of org.sonar.server.rule.index.RuleIndex in project sonarqube by SonarSource.

the class RegisterRulesTest method before.

@Before
public void before() {
    ruleIndexer = new RuleIndexer(es.client(), dbClient);
    ruleIndex = new RuleIndex(es.client(), system);
    activeRuleIndexer = new ActiveRuleIndexer(dbClient, es.client());
}
Also used : ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) RuleIndex(org.sonar.server.rule.index.RuleIndex) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) Before(org.junit.Before)

Example 4 with RuleIndex

use of org.sonar.server.rule.index.RuleIndex in project sonarqube by SonarSource.

the class ChangeParentActionTest method setUp.

@Before
public void setUp() {
    dbClient = db.getDbClient();
    dbSession = db.getSession();
    EsClient esClient = es.client();
    ruleIndex = new RuleIndex(esClient, System2.INSTANCE);
    ruleIndexer = new RuleIndexer(esClient, dbClient);
    activeRuleIndexer = new ActiveRuleIndexer(dbClient, esClient);
    TypeValidations typeValidations = new TypeValidations(Collections.emptyList());
    RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, dbClient, typeValidations, userSession);
    qProfileTree = new QProfileTreeImpl(dbClient, ruleActivator, System2.INSTANCE, activeRuleIndexer, mock(QualityProfileChangeEventService.class));
    ChangeParentAction underTest = new ChangeParentAction(dbClient, qProfileTree, new Languages(), new QProfileWsSupport(dbClient, userSession), userSession);
    ws = new WsActionTester(underTest);
    userSession.logIn().addPermission(ADMINISTER_QUALITY_PROFILES);
}
Also used : ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) RuleIndex(org.sonar.server.rule.index.RuleIndex) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) TypeValidations(org.sonar.server.util.TypeValidations) RuleActivator(org.sonar.server.qualityprofile.builtin.RuleActivator) QProfileTreeImpl(org.sonar.server.qualityprofile.QProfileTreeImpl) Languages(org.sonar.api.resources.Languages) EsClient(org.sonar.server.es.EsClient) WsActionTester(org.sonar.server.ws.WsActionTester) Before(org.junit.Before)

Aggregations

ActiveRuleIndexer (org.sonar.server.qualityprofile.index.ActiveRuleIndexer)4 RuleIndex (org.sonar.server.rule.index.RuleIndex)4 Before (org.junit.Before)3 RuleIndexer (org.sonar.server.rule.index.RuleIndexer)3 Languages (org.sonar.api.resources.Languages)2 RuleActivator (org.sonar.server.qualityprofile.builtin.RuleActivator)2 TypeValidations (org.sonar.server.util.TypeValidations)2 WsActionTester (org.sonar.server.ws.WsActionTester)2 IntStream.range (java.util.stream.IntStream.range)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 Language (org.sonar.api.resources.Language)1 DEPRECATED (org.sonar.api.rule.RuleStatus.DEPRECATED)1 WebService (org.sonar.api.server.ws.WebService)1 DateUtils (org.sonar.api.utils.DateUtils)1 DateUtils.parseDateTime (org.sonar.api.utils.DateUtils.parseDateTime)1 System2 (org.sonar.api.utils.System2)1 DbClient (org.sonar.db.DbClient)1