From 3f31a1c20bc8dcf8bfdb986f225e5921b19fd64d Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Wed, 19 Jul 2017 17:33:18 +0200 Subject: [PATCH] SONAR-9551 Select APP when searching for views and subviews at the component db layer --- .../java/org/sonar/db/purge/PurgeMapper.java | 2 +- .../sonar/db/component/ComponentMapper.xml | 2 +- .../org/sonar/db/purge/PurgeMapper.xml | 2 +- .../sonar/db/component/ComponentDaoTest.java | 19 ++++++++++++++----- .../sonar/db/component/ComponentDbTester.java | 9 +++++++-- .../org/sonar/db/purge/PurgeMapperTest.java | 9 +++++++++ 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java index ec9b49e737c..5bf39fe7fe3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -28,7 +28,7 @@ public interface PurgeMapper { List 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 selectRootAndModulesOrSubviewsByProjectUuid(@Param("rootUuid") String rootUuid); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 43450db333a..1c5a72ff24c 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -212,7 +212,7 @@ 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} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index c78741c94cc..5e66eba3bc5 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -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') ) diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 4aa72117939..6ab736148a5 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -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 diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDbTester.java index e434b210da7..799352afe4a 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDbTester.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDbTester.java @@ -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 dtoPopulator) { - return insertComponentImpl(newApplication(organizationDto), false, dtoPopulator); + public ComponentDto insertApplication(OrganizationDto organizationDto, Consumer... dtoPopulators) { + return insertComponentImpl(newApplication(organizationDto), false, dtoPopulators); + } + + public ComponentDto insertSubView(ComponentDto view, Consumer dtoPopulator) { + return insertComponentImpl(newSubView(view), false, dtoPopulator); } private static Consumer noExtraConfiguration() { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java index f9da4da6e68..cb636633575 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java @@ -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(); -- 2.39.5