From: Julien Lancelot Date: Tue, 13 Sep 2016 15:30:57 +0000 (+0200) Subject: SONAR-7855 Index active rules when creating profile from a configuration file X-Git-Tag: 6.1-RC1~87 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F1245%2Fhead;p=sonarqube.git SONAR-7855 Index active rules when creating profile from a configuration file --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java index 0e88a06abd1..66c258ffbae 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java @@ -61,18 +61,22 @@ public class CreateAction implements QProfileWsAction { private final ProfileImporter[] importers; private final UserSession userSession; + private final ActiveRuleIndexer activeRuleIndexer; + public CreateAction(DbClient dbClient, QProfileFactory profileFactory, QProfileExporters exporters, - Languages languages, ProfileImporter[] importers, UserSession userSession) { + Languages languages, ProfileImporter[] importers, UserSession userSession, ActiveRuleIndexer activeRuleIndexer) { this.dbClient = dbClient; this.profileFactory = profileFactory; this.exporters = exporters; this.languages = languages; this.importers = importers; this.userSession = userSession; + this.activeRuleIndexer = activeRuleIndexer; } - public CreateAction(DbClient dbClient, QProfileFactory profileFactory, QProfileExporters exporters, Languages languages, UserSession userSession) { - this(dbClient, profileFactory, exporters, languages, new ProfileImporter[0], userSession); + public CreateAction(DbClient dbClient, QProfileFactory profileFactory, QProfileExporters exporters, Languages languages, UserSession userSession, + ActiveRuleIndexer activeRuleIndexer) { + this(dbClient, profileFactory, exporters, languages, new ProfileImporter[0], userSession, activeRuleIndexer); } @Override @@ -127,6 +131,7 @@ public class CreateAction implements QProfileWsAction { } } dbSession.commit(); + activeRuleIndexer.index(result.getChanges()); return buildResponse(result); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java index 035496e1645..ae22a92b04c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java @@ -51,6 +51,7 @@ import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; import org.sonar.server.rule.index.RuleIndex; import org.sonar.server.rule.index.RuleIndexDefinition; import org.sonar.server.rule.index.RuleIndexer; +import org.sonar.server.rule.index.RuleQuery; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.TestResponse; @@ -100,7 +101,7 @@ public class CreateActionTest { new RuleActivator(mock(System2.class), dbClient, ruleIndex, new RuleActivatorContextFactory(dbClient), null, activeRuleIndexer, userSession), profileImporters); - CreateAction underTest = new CreateAction(dbClient, new QProfileFactory(dbClient), qProfileExporters, newLanguages(XOO_LANGUAGE), profileImporters, userSession); + CreateAction underTest = new CreateAction(dbClient, new QProfileFactory(dbClient), qProfileExporters, newLanguages(XOO_LANGUAGE), profileImporters, userSession, activeRuleIndexer); WsActionTester wsTester = new WsActionTester(underTest); @Test @@ -134,8 +135,7 @@ public class CreateActionTest { QualityProfileDto dto = dbClient.qualityProfileDao().selectByNameAndLanguage("New Profile", XOO_LANGUAGE, dbSession); assertThat(dto.getKey()).isNotNull(); assertThat(dbClient.activeRuleDao().selectByProfileKey(dbSession, dto.getKey())).hasSize(1); - // FIXME - // assertThat(ruleIndex.searchAll(new RuleQuery().setQProfileKey(profile.getKey()).setActivation(true))).hasSize(1); + assertThat(ruleIndex.searchAll(new RuleQuery().setQProfileKey(dto.getKey()).setActivation(true))).hasSize(1); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java index 44571cc9cde..0ff190f5a8a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java @@ -66,7 +66,7 @@ public class QProfilesWsTest { new BulkRuleActivationActions(profileService, null, i18n, userSessionRule), new AddProjectAction(projectAssociationParameters, null, null, null), new RemoveProjectAction(projectAssociationParameters, null, null, null), - new CreateAction(null, null, null, languages, importers, userSessionRule), + new CreateAction(null, null, null, languages, importers, userSessionRule, null), new ImportersAction(importers), new RestoreBuiltInAction(null, languages), new SearchAction(null, languages),