]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19850 Fix tests after enabling different uuids for project and branch
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>
Wed, 12 Jul 2023 09:17:24 +0000 (11:17 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 19 Jul 2023 20:03:06 +0000 (20:03 +0000)
13 files changed:
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterIT.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectExportTaskProcessor.java
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentUpdaterIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/CreateActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/BulkDeleteAction.java

index 45d0ef5e8a53909ac5d8b2122b05755ec828d73c..99b0f40403e5248f3a7f7d11d719fabdda20401d 100644 (file)
@@ -77,9 +77,9 @@ public class ProjectPersisterIT {
     ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID",
       p -> p.setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription("OLD_DESC")).getProjectDto();
 
-    assertProject("OLD_DESC", ROOT.getName(), p1.getUpdatedAt());
+    assertProject(p1.getUuid(), "OLD_DESC", ROOT.getName(), p1.getUpdatedAt());
     underTest.persist(dbTester.getSession());
-    assertProject(ROOT.getDescription(), ROOT.getName(), 1000L);
+    assertProject(ROOT.getUuid(), ROOT.getDescription(), ROOT.getName(), 1000L);
   }
 
   @Test
@@ -87,9 +87,9 @@ public class ProjectPersisterIT {
     ProjectDto p1 = dbTester.components().insertPublicProject("PROJECT_UUID",
       p -> p.setKey(ROOT.getKey()).setName("OLD_NAME").setDescription(ROOT.getDescription())).getProjectDto();
 
-    assertProject(ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt());
+    assertProject(p1.getUuid(), ROOT.getDescription(), "OLD_NAME", p1.getUpdatedAt());
     underTest.persist(dbTester.getSession());
-    assertProject(ROOT.getDescription(), ROOT.getName(), 1000L);
+    assertProject(ROOT.getUuid(), ROOT.getDescription(), ROOT.getName(), 1000L);
   }
 
   @Test
@@ -97,15 +97,15 @@ public class ProjectPersisterIT {
     ProjectDto p1 = dbTester.components().insertPublicProject(
       c -> c.setUuid("PROJECT_UUID").setKey(ROOT.getKey()).setName(ROOT.getName()).setDescription(ROOT.getDescription())).getProjectDto();
 
-    assertProject(ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt());
+    assertProject(p1.getUuid(), ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt());
     underTest.persist(dbTester.getSession());
-    assertProject(ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt());
+    assertProject(p1.getUuid(), ROOT.getDescription(), ROOT.getName(), p1.getUpdatedAt());
   }
 
-  private void assertProject(String description, String name, long updated) {
+  private void assertProject(String uuid, String description, String name, long updated) {
     assertThat(dbTester.getDbClient().projectDao().selectProjectByKey(dbTester.getSession(), ROOT.getKey()).get())
-      .extracting(ProjectDto::getName, ProjectDto::getDescription, ProjectDto::getUpdatedAt)
-      .containsExactly(name, description, updated);
+      .extracting(ProjectDto::getUuid, ProjectDto::getName, ProjectDto::getDescription, ProjectDto::getUpdatedAt)
+      .containsExactly(uuid, name, description, updated);
 
   }
 }
index e18d97a589bd0a765e7c4db8ad4c752cf321c8c9..fc94024b6ce6fc55a750a09a24fccd254b5e4e07 100644 (file)
@@ -52,7 +52,9 @@ public class ProjectExportTaskProcessor implements CeTaskProcessor {
 
   private void processProjectExport(CeTask task) {
     CeTask.Component exportComponent = mandatoryComponent(task, PROJECT_EXPORT);
-    ProjectDescriptor projectExportDescriptor = new ProjectDescriptor(task.getEntity().get().getUuid(),
+    CeTask.Component entity = task.getEntity()
+      .orElseThrow(() -> new IllegalStateException("Compute engine task for project export doesn't contain entity"));
+    ProjectDescriptor projectExportDescriptor = new ProjectDescriptor(entity.getUuid(),
       mandatoryKey(exportComponent), mandatoryName(exportComponent));
 
     try (TaskContainer taskContainer = new TaskContainerImpl(componentContainer,
index 9094851bb2ae77602929054fd5512d84252f2f73..ec0bb78cd87cafb9e9e26ae6dfe1fe7518cc59ed 100644 (file)
@@ -100,7 +100,10 @@ import static java.util.Collections.singletonList;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.groups.Tuple.tuple;
+import static org.mockito.ArgumentMatchers.anyList;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.only;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoInteractions;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.ce.CeTaskTypes.REPORT;
@@ -1219,6 +1222,7 @@ public class PurgeDaoIT {
 
   @Test
   public void should_delete_old_closed_issues() {
+    PurgeListener listener = mock(PurgeListener.class);
     RuleDto rule = db.rules().insert();
     ProjectData projectData = db.components().insertPublicProject();
     ComponentDto mainBranch = projectData.getMainBranchComponent();
@@ -1241,7 +1245,7 @@ public class PurgeDaoIT {
     db.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(notClosed));
 
     when(system2.now()).thenReturn(new Date().getTime());
-    underTest.purge(dbSession, newConfigurationWith30Days(system2, mainBranch.uuid(), projectData.projectUuid()), PurgeListener.EMPTY, new PurgeProfiler());
+    underTest.purge(dbSession, newConfigurationWith30Days(system2, mainBranch.uuid(), projectData.projectUuid()), listener, new PurgeProfiler());
     dbSession.commit();
 
     // old closed got deleted
@@ -1260,6 +1264,8 @@ public class PurgeDaoIT {
 
     Optional<IssueDto> oldClosedFromQuery = db.getDbClient().issueDao().selectByKey(dbSession, oldClosed.getKey());
     assertThat(oldClosedFromQuery).isEmpty();
+
+    verify(listener, only()).onIssuesRemoval(projectData.projectUuid(), List.of(oldClosed.getKee()));
   }
 
   @Test
index 3c9c3338e67ce82ed68be81b8b9038f1beb851e5..3cb3ffb9f389e08b9ee298ba8d8cc6c184cb8929 100644 (file)
@@ -93,7 +93,7 @@ public class ImportAzureProjectActionIT {
 
   private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), i18n, System2.INSTANCE,
     mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(),
-    defaultBranchNameResolver, true);
+    defaultBranchNameResolver);
 
   private final Encryption encryption = mock(Encryption.class);
   private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession);
index 79053120c5264b149fddb0d7dc2b1483071cbb2e..08a147ec483709496da290109c56783488acd070 100644 (file)
@@ -93,7 +93,7 @@ public class ImportBitbucketCloudRepoActionIT {
   DefaultBranchNameResolver defaultBranchNameResolver = mock(DefaultBranchNameResolver.class);
   private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), i18n, System2.INSTANCE,
     mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(),
-    defaultBranchNameResolver, true);
+    defaultBranchNameResolver);
 
   private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession);
   private final ProjectKeyGenerator projectKeyGenerator = mock(ProjectKeyGenerator.class);
index a615c9a50beba861c0e83a4b498cf8a38394b18a..8b674f338f3ecc21cc521d23a01a7c954689cf00 100644 (file)
@@ -100,7 +100,7 @@ public class ImportBitbucketServerProjectActionIT {
 
   private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), i18n, System2.INSTANCE,
     mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(),
-    defaultBranchNameResolver, true);
+    defaultBranchNameResolver);
 
   private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession);
   private final ProjectKeyGenerator projectKeyGenerator = mock(ProjectKeyGenerator.class);
index df056b47dd6f41aa92cbe6255763c93120a5b6f3..dd35ab3cb4b38942cfa9957318c241216382714f 100644 (file)
@@ -94,7 +94,7 @@ public class ImportGithubProjectActionIT {
   private final PermissionTemplateService permissionTemplateService = mock(PermissionTemplateService.class);
   private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), mock(I18n.class), System2.INSTANCE,
     permissionTemplateService, new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(),
-    defaultBranchNameResolver, true);
+    defaultBranchNameResolver);
 
   private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession);
   private final ProjectKeyGenerator projectKeyGenerator = mock(ProjectKeyGenerator.class);
index db88cbdc36e50c38940c527ac076b4c0494c8a3a..e257bcc044ff6793725b5fc6fde8ffce5b54d914 100644 (file)
@@ -84,7 +84,7 @@ public class ImportGitLabProjectActionIT {
 
   private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), mock(I18n.class), System2.INSTANCE,
     mock(PermissionTemplateService.class), new FavoriteUpdater(db.getDbClient()), new TestIndexers(), new SequenceUuidFactory(),
-    defaultBranchNameResolver, true);
+    defaultBranchNameResolver);
 
   private final GitlabHttpClient gitlabHttpClient = mock(GitlabHttpClient.class);
   private final ImportHelper importHelper = new ImportHelper(db.getDbClient(), userSession);
index 748ed942153161fbc0d1e616b3c164ca7ee66566..6bdf633aba7511a8582a18340f85ce163bfd73ae 100644 (file)
@@ -93,7 +93,7 @@ public class ReportSubmitterIT {
   private final PermissionTemplateService permissionTemplateService = mock(PermissionTemplateService.class);
 
   private final ComponentUpdater componentUpdater = new ComponentUpdater(db.getDbClient(), mock(I18n.class), mock(System2.class), permissionTemplateService,
-    new FavoriteUpdater(db.getDbClient()), projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver, true);
+    new FavoriteUpdater(db.getDbClient()), projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver);
   private final BranchSupport ossEditionBranchSupport = new BranchSupport(null);
 
   private final ReportSubmitter underTest = new ReportSubmitter(queue, userSession, componentUpdater, permissionTemplateService, db.getDbClient(), ossEditionBranchSupport,
index 5223e7123f4bd9cd6d6aa7735acbc3da431e2586..0e72ba37443dd4f3c9f656f3c6537b495c116675 100644 (file)
@@ -80,7 +80,7 @@ public class ComponentUpdaterIT {
   private final ComponentUpdater underTest = new ComponentUpdater(db.getDbClient(), i18n, system2,
     permissionTemplateService,
     new FavoriteUpdater(db.getDbClient()),
-    projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver, true);
+    projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver);
 
   @Before
   public void before() {
index df1fe14ba12aa4bf977b6c00cda5a3acacbc3789..75dd6ae7d4b65c7996a66e7fb1636e0e569428e6 100644 (file)
@@ -107,7 +107,7 @@ public class CreateActionIT {
     new CreateAction(
       db.getDbClient(), userSession,
       new ComponentUpdater(db.getDbClient(), i18n, system2, permissionTemplateService, new FavoriteUpdater(db.getDbClient()),
-        projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver, true),
+        projectIndexers, new SequenceUuidFactory(), defaultBranchNameResolver),
       projectDefaultVisibility, defaultBranchNameResolver, newCodeDefinitionResolver));
 
   @Before
index 843183bd137ac79a7d3453ff9e1849bef0aa2b2f..75118c589f1b5176d0759f00e9f87b32bc07302b 100644 (file)
@@ -65,20 +65,11 @@ public class ComponentUpdater {
   private final Indexers indexers;
   private final UuidFactory uuidFactory;
   private final DefaultBranchNameResolver defaultBranchNameResolver;
-  private final boolean useDifferentUuids;
 
   @Autowired
   public ComponentUpdater(DbClient dbClient, I18n i18n, System2 system2,
     PermissionTemplateService permissionTemplateService, FavoriteUpdater favoriteUpdater,
     Indexers indexers, UuidFactory uuidFactory, DefaultBranchNameResolver defaultBranchNameResolver) {
-    this(dbClient, i18n, system2, permissionTemplateService, favoriteUpdater, indexers, uuidFactory, defaultBranchNameResolver, false);
-  }
-
-  @VisibleForTesting
-  public ComponentUpdater(DbClient dbClient, I18n i18n, System2 system2,
-    PermissionTemplateService permissionTemplateService, FavoriteUpdater favoriteUpdater,
-    Indexers indexers, UuidFactory uuidFactory, DefaultBranchNameResolver defaultBranchNameResolver,
-    boolean useDifferentUuids) {
     this.dbClient = dbClient;
     this.i18n = i18n;
     this.system2 = system2;
@@ -87,7 +78,6 @@ public class ComponentUpdater {
     this.indexers = indexers;
     this.uuidFactory = uuidFactory;
     this.defaultBranchNameResolver = defaultBranchNameResolver;
-    this.useDifferentUuids = useDifferentUuids;
   }
 
   /**
index c71fcb9974ca4b80e6d8afded4eca9ebb4720658..379c1774e81be8a680586ca29e8649f5189a0f37 100644 (file)
@@ -154,23 +154,22 @@ public class BulkDeleteAction implements ProjectsWsAction {
       ComponentQuery query = buildDbQuery(searchRequest);
       Set<ComponentDto> componentDtos = new HashSet<>(dbClient.componentDao().selectByQuery(dbSession, query, 0, Integer.MAX_VALUE));
       List<EntityDto> entities = dbClient.entityDao().selectByKeys(dbSession, componentDtos.stream().map(ComponentDto::getKey).collect(toSet()));
+      Set<String> entityUuids = entities.stream().map(EntityDto::getUuid).collect(toSet());
+      Map<String, String> mainBranchUuidByEntityUuid = dbClient.branchDao().selectMainBranchesByProjectUuids(dbSession, entityUuids).stream()
+        .collect(Collectors.toMap(BranchDto::getProjectUuid, BranchDto::getUuid));
 
       try {
         entities.forEach(p -> componentCleanerService.deleteEntity(dbSession, p));
       } finally {
-        callDeleteListeners(dbSession, entities);
+        callDeleteListeners(dbSession, mainBranchUuidByEntityUuid, entities);
       }
     }
     response.noContent();
   }
 
-  private void callDeleteListeners(DbSession dbSession, List<EntityDto> entities) {
-    Set<String> entityUuids = entities.stream().map(EntityDto::getUuid).collect(toSet());
-    Map<String, String> mainBranchUuidByEntityUuid = dbClient.branchDao().selectMainBranchesByProjectUuids(dbSession, entityUuids).stream()
-      .collect(Collectors.toMap(BranchDto::getProjectUuid, BranchDto::getUuid));
-
-    ImmutableSet<DeletedProject> deletedProjects = entities.stream().map(entity -> new DeletedProject(Project.from(entity), mainBranchUuidByEntityUuid.get(entity.getUuid())))
-      .collect(toImmutableSet());
+  private void callDeleteListeners(DbSession dbSession, Map<String, String> mainBranchUuidByEntityUuid , List<EntityDto> entities) {
+    Set<DeletedProject> deletedProjects = entities.stream().map(entity -> new DeletedProject(Project.from(entity),
+        mainBranchUuidByEntityUuid.get(entity.getUuid()))).collect(toSet());
     projectLifeCycleListeners.onProjectsDeleted(deletedProjects);
   }