Browse Source

SONAR-19850 Fix tests after enabling different uuids for project and branch

tags/10.2.0.77647
lukasz-jarocki-sonarsource 11 months ago
parent
commit
f83091c81a
13 changed files with 34 additions and 37 deletions
  1. 9
    9
      server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterIT.java
  2. 3
    1
      server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectExportTaskProcessor.java
  3. 7
    1
      server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java
  4. 1
    1
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionIT.java
  5. 1
    1
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionIT.java
  6. 1
    1
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionIT.java
  7. 1
    1
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionIT.java
  8. 1
    1
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectActionIT.java
  9. 1
    1
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java
  10. 1
    1
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentUpdaterIT.java
  11. 1
    1
      server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/CreateActionIT.java
  12. 0
    10
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
  13. 7
    8
      server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/BulkDeleteAction.java

+ 9
- 9
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/component/ProjectPersisterIT.java View 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);

}
}

+ 3
- 1
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectExportTaskProcessor.java View 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,

+ 7
- 1
server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java View 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

+ 1
- 1
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionIT.java View 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);

+ 1
- 1
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionIT.java View 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);

+ 1
- 1
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionIT.java View 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);

+ 1
- 1
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionIT.java View 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);

+ 1
- 1
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectActionIT.java View 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);

+ 1
- 1
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.java View 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,

+ 1
- 1
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ComponentUpdaterIT.java View 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() {

+ 1
- 1
server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/CreateActionIT.java View 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

+ 0
- 10
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java View 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;
}

/**

+ 7
- 8
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/BulkDeleteAction.java View 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);
}


Loading…
Cancel
Save