]> source.dussan.org Git - sonarqube.git/commitdiff
VIEWS-323 make IndexComponentsStepTest support indexing a View
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 15 Sep 2015 12:23:40 +0000 (14:23 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 16 Sep 2015 09:00:08 +0000 (11:00 +0200)
server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java

index 4da0ef5d678769e19ae48350fed745c404190130..923d19bdb203dcab4a34f04341cd72223714fe4d 100644 (file)
@@ -26,11 +26,14 @@ import org.sonar.db.component.ResourceIndexDao;
 import org.sonar.server.computation.batch.BatchReportReaderRule;
 import org.sonar.server.computation.batch.TreeRootHolderRule;
 import org.sonar.server.computation.component.Component;
-import org.sonar.server.computation.component.DbIdsRepositoryImpl;
+import org.sonar.server.computation.component.MutableDbIdsRepositoryRule;
 import org.sonar.server.computation.component.ReportComponent;
+import org.sonar.server.computation.component.ViewsComponent;
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.sonar.server.computation.component.Component.Type.PROJECT;
+import static org.sonar.server.computation.component.Component.Type.VIEW;
 
 public class IndexComponentsStepTest extends BaseStepTest {
 
@@ -38,17 +41,17 @@ public class IndexComponentsStepTest extends BaseStepTest {
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
-
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
+  @Rule
+  public MutableDbIdsRepositoryRule dbIdsRepository = MutableDbIdsRepositoryRule.create(treeRootHolder);
 
   ResourceIndexDao resourceIndexDao = mock(ResourceIndexDao.class);
-  DbIdsRepositoryImpl dbIdsRepository = new DbIdsRepositoryImpl();
   IndexComponentsStep underTest = new IndexComponentsStep(resourceIndexDao, dbIdsRepository, treeRootHolder);
 
   @Test
-  public void call_indexProject_of_dao() {
-    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("PROJECT_UUID").setKey(PROJECT_KEY).build();
+  public void call_indexProject_of_dao_for_project() {
+    Component project = ReportComponent.builder(PROJECT, 1).setUuid("PROJECT_UUID").setKey(PROJECT_KEY).build();
     dbIdsRepository.setComponentId(project, 123L);
     treeRootHolder.setRoot(project);
 
@@ -57,6 +60,17 @@ public class IndexComponentsStepTest extends BaseStepTest {
     verify(resourceIndexDao).indexProject(123L);
   }
 
+  @Test
+  public void call_indexProject_of_dao_for_view() {
+    Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid("PROJECT_UUID").build();
+    dbIdsRepository.setComponentId(view, 123L);
+    treeRootHolder.setRoot(view);
+
+    underTest.execute();
+
+    verify(resourceIndexDao).indexProject(123L);
+  }
+
   @Override
   protected ComputationStep step() {
     return underTest;