]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9551 Index applications when indexing views
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 27 Jul 2017 08:06:19 +0000 (10:06 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 31 Jul 2017 09:27:51 +0000 (11:27 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java

index 7caca7706ba9eff76790ad72a49d0c0d19f052b6..bf9ccb18a7c477f9f03db2511743ad237c5842a8 100644 (file)
@@ -216,7 +216,7 @@ public class ComponentDao implements Dao {
   }
 
   public List<UuidWithProjectUuidDto> selectAllViewsAndSubViews(DbSession session) {
-    return mapper(session).selectUuidsForQualifiers(Qualifiers.VIEW, Qualifiers.SUBVIEW);
+    return mapper(session).selectUuidsForQualifiers(Qualifiers.APP, Qualifiers.VIEW, Qualifiers.SUBVIEW);
   }
 
   public List<String> selectProjectsFromView(DbSession session, String viewUuid, String projectViewUuid) {
index 6ab736148a534f071ef41d634a04b0aee25303ab..21889265e7d9a31a54c9d169d27986ef5ff0ae18 100644 (file)
@@ -519,11 +519,9 @@ public class ComponentDaoTest {
     ComponentDto application = db.components().insertApplication(organization);
 
     assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getUuid)
-      .containsExactlyInAnyOrder("ABCD", "EFGH", "FGHI", "IJKL")
-      .doesNotContain(application.uuid());
+      .containsExactlyInAnyOrder("ABCD", "EFGH", "FGHI", "IJKL", application.uuid());
     assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getProjectUuid)
-      .containsOnly("ABCD", "EFGH", "IJKL")
-      .doesNotContain(application.projectUuid());
+      .containsOnly("ABCD", "EFGH", "IJKL", application.projectUuid());
   }
 
   @Test
index e416e031fa0bff9c7617706589e25599037735a8..024605c79cf8285d4f296c83bd572fe66ecd821f 100644 (file)
@@ -51,6 +51,7 @@ import org.sonar.server.tester.UserSessionRule;
 import static com.google.common.collect.Lists.newArrayList;
 import static java.util.Collections.emptySet;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 
 public class ViewIndexerTest {
 
@@ -78,7 +79,7 @@ public class ViewIndexerTest {
   }
 
   @Test
-  public void index() {
+  public void index_on_startup() {
     dbTester.prepareDbUnit(getClass(), "index.xml");
 
     underTest.indexOnStartup(emptySet());
@@ -113,14 +114,44 @@ public class ViewIndexerTest {
   public void index_view_doc() {
     underTest.index(new ViewDoc().setUuid("EFGH").setProjects(newArrayList("KLMN", "JKLM")));
 
-    List<ViewDoc> docs = esTester.getDocuments(ViewIndexDefinition.INDEX_TYPE_VIEW, ViewDoc.class);
-    assertThat(docs).hasSize(1);
+    List<ViewDoc> result = esTester.getDocuments(ViewIndexDefinition.INDEX_TYPE_VIEW, ViewDoc.class);
 
-    ViewDoc view = docs.get(0);
+    assertThat(result).hasSize(1);
+    ViewDoc view = result.get(0);
     assertThat(view.uuid()).isEqualTo("EFGH");
     assertThat(view.projects()).containsOnly("KLMN", "JKLM");
   }
 
+  @Test
+  public void index_application() {
+    ComponentDto application = dbTester.components().insertApplication(dbTester.getDefaultOrganization());
+    ComponentDto project = dbTester.components().insertPrivateProject();
+    dbTester.components().insertComponent(newProjectCopy("PC1", project, application));
+
+    underTest.index(application.uuid());
+    List<ViewDoc> result = esTester.getDocuments(ViewIndexDefinition.INDEX_TYPE_VIEW, ViewDoc.class);
+
+    assertThat(result).hasSize(1);
+    ViewDoc resultApp = result.get(0);
+    assertThat(resultApp.uuid()).isEqualTo(application.uuid());
+    assertThat(resultApp.projects()).containsExactlyInAnyOrder(project.uuid());
+  }
+
+  @Test
+  public void index_application_on_startup() {
+    ComponentDto application = dbTester.components().insertApplication(dbTester.getDefaultOrganization());
+    ComponentDto project = dbTester.components().insertPrivateProject();
+    dbTester.components().insertComponent(newProjectCopy("PC1", project, application));
+
+    underTest.indexOnStartup(emptySet());
+    List<ViewDoc> result = esTester.getDocuments(ViewIndexDefinition.INDEX_TYPE_VIEW, ViewDoc.class);
+
+    assertThat(result).hasSize(1);
+    ViewDoc resultApp = result.get(0);
+    assertThat(resultApp.uuid()).isEqualTo(application.uuid());
+    assertThat(resultApp.projects()).containsExactlyInAnyOrder(project.uuid());
+  }
+
   @Test
   public void clear_views_lookup_cache_on_index_view_uuid() {
     IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
@@ -136,7 +167,7 @@ public class ViewIndexerTest {
 
     OrganizationDto organizationDto = dbTester.organizations().insert();
     ComponentDto view = ComponentTesting.newView(organizationDto, "ABCD");
-    ComponentDto techProject1 = ComponentTesting.newProjectCopy("CDEF", project1, view);
+    ComponentDto techProject1 = newProjectCopy("CDEF", project1, view);
     dbClient.componentDao().insert(dbSession, view, techProject1);
     dbSession.commit();
 
@@ -152,7 +183,7 @@ public class ViewIndexerTest {
     issueIndexer.indexOnStartup(issueIndexer.getIndexTypes());
     permissionIndexer.indexOnStartup(permissionIndexer.getIndexTypes());
 
-    ComponentDto techProject2 = ComponentTesting.newProjectCopy("EFGH", project2, view);
+    ComponentDto techProject2 = newProjectCopy("EFGH", project2, view);
     dbClient.componentDao().insert(dbSession, techProject2);
     dbSession.commit();
     underTest.index(viewUuid);