]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7855 Index active rules when creating profile from a configuration file 1245/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 13 Sep 2016 15:30:57 +0000 (17:30 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 14 Sep 2016 09:10:52 +0000 (11:10 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CreateActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfilesWsTest.java

index 0e88a06abd1fc8799792f6a99574a11c2d887efd..66c258ffbae1e44f44eee402b036cc0a23bb9751 100644 (file)
@@ -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);
   }
 
index 035496e1645c8b9e44968321d78083ea1d3d6cd9..ae22a92b04cc9aef0f66d8fa72837246da824559 100644 (file)
@@ -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
index 44571cc9cdebc63f52665589f3c9152ee2f1a118..0ff190f5a8aafec8a1c8f485d7f3f9e442ac02a6 100644 (file)
@@ -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),