]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9551 Select APP when searching for views and subviews at the component db layer
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 19 Jul 2017 15:33:18 +0000 (17:33 +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/purge/PurgeMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java

index ec9b49e737c943fea69bdef7ed10684c51310bc2..5bf39fe7fe387e88b961983f41a2100c03a3a23b 100644 (file)
@@ -28,7 +28,7 @@ public interface PurgeMapper {
   List<IdUuidPair> selectAnalysisIdsAndUuids(PurgeSnapshotQuery query);
 
   /**
-   * Returns the list of modules/subviews and the view/project for the specified project_uuid.
+   * Returns the list of modules/subviews and the application/view/project for the specified project_uuid.
    */
   List<IdUuidPair> selectRootAndModulesOrSubviewsByProjectUuid(@Param("rootUuid") String rootUuid);
 
index 43450db333a74b56f2f7a87dd4c96517721f3672..1c5a72ff24ccab97da04ae1027aa45f80d509ace 100644 (file)
     from projects p
     where
       p.scope='PRJ'
-      and (p.qualifier='TRK' or p.qualifier='VW')
+    and (p.qualifier='TRK' or p.qualifier='VW' or p.qualifier='APP')
       and p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
   </select>
 
index c78741c94cc1fbc791798d296bb59b62c1f102a6..5e66eba3bc54a21e9c0e44584f23cbe9f761b0e5 100644 (file)
@@ -63,7 +63,7 @@
       )
       or (
         uuid=#{rootUuid,jdbcType=VARCHAR}
-        and p.scope = 'PRJ' and p.qualifier in ('VW','TRK')
+        and p.scope = 'PRJ' and p.qualifier in ('APP', 'VW','TRK')
       )
   </select>
 
index 4aa72117939d060a1291a995828071392b27a5eb..6ab736148a534f071ef41d634a04b0aee25303ab 100644 (file)
@@ -510,11 +510,20 @@ public class ComponentDaoTest {
   }
 
   @Test
-  public void select_views_and_sub_views() {
-    db.prepareDbUnit(getClass(), "shared_views.xml");
-
-    assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting("uuid").containsOnly("ABCD", "EFGH", "FGHI", "IJKL");
-    assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting("projectUuid").containsOnly("ABCD", "EFGH", "IJKL");
+  public void select_views_and_sub_views_and_applications() {
+    OrganizationDto organization = db.organizations().insert();
+    db.components().insertView(organization, "ABCD");
+    db.components().insertView(organization, "IJKL");
+    ComponentDto view = db.components().insertView(organization, "EFGH");
+    db.components().insertSubView(view, dto -> dto.setUuid("FGHI"));
+    ComponentDto application = db.components().insertApplication(organization);
+
+    assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getUuid)
+      .containsExactlyInAnyOrder("ABCD", "EFGH", "FGHI", "IJKL")
+      .doesNotContain(application.uuid());
+    assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getProjectUuid)
+      .containsOnly("ABCD", "EFGH", "IJKL")
+      .doesNotContain(application.projectUuid());
   }
 
   @Test
index e434b210da766d11b9b9231cb427b1d439dd5f88..799352afe4a44861a17e9843e5cf1161eee0ad5c 100644 (file)
@@ -32,6 +32,7 @@ import static java.util.Arrays.asList;
 import static org.sonar.db.component.ComponentTesting.newApplication;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.component.ComponentTesting.newPublicProjectDto;
+import static org.sonar.db.component.ComponentTesting.newSubView;
 import static org.sonar.db.component.ComponentTesting.newView;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 
@@ -138,8 +139,12 @@ public class ComponentDbTester {
     return insertComponentImpl(newApplication(organizationDto), false, noExtraConfiguration());
   }
 
-  public ComponentDto insertApplication(OrganizationDto organizationDto, Consumer<ComponentDto> dtoPopulator) {
-    return insertComponentImpl(newApplication(organizationDto), false, dtoPopulator);
+  public ComponentDto insertApplication(OrganizationDto organizationDto, Consumer<ComponentDto>... dtoPopulators) {
+    return insertComponentImpl(newApplication(organizationDto), false, dtoPopulators);
+  }
+
+  public ComponentDto insertSubView(ComponentDto view, Consumer<ComponentDto> dtoPopulator) {
+    return insertComponentImpl(newSubView(view), false, dtoPopulator);
   }
 
   private static <T> Consumer<T> noExtraConfiguration() {
index f9da4da6e6817fd630d2c14615cae34da4e83639..cb63663357590ef3e2f44b08293f5588d4100b0e 100644 (file)
@@ -92,6 +92,15 @@ public class PurgeMapperTest {
       .containsOnly(view.uuid());
   }
 
+  @Test
+  public void selectRootAndModulesOrSubviewsByProjectUuid_returns_application_with_specified_uuid() {
+    ComponentDto view = db.components().insertApplication(db.getDefaultOrganization());
+
+    assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
+      .extracting(IdUuidPair::getUuid)
+      .containsOnly(view.uuid());
+  }
+
   @Test
   public void selectRootAndModulesOrSubviewsByProjectUuid_returns_subviews_with_specified_project_uuid_and_view() {
     ComponentDto view = db.components().insertView();