From 9957e4aacaab10021c16d971a2b1de227a611c4b Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 9 May 2023 03:10:47 -0500 Subject: [PATCH] [NO JIRA] Use different uuids for project and main branch in ITs --- .../java/org/sonar/db/DbTester.java | 26 ++++++++--- .../sonar/db/component/ComponentDbTester.java | 31 ++----------- .../org/sonar/db/component/ProjectData.java | 46 +++++++++++++++++++ 3 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectData.java diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java index dafd9db00d8..55b9cd9378c 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java @@ -89,14 +89,14 @@ public class DbTester extends AbstractDbTester { private final AlmPatsDbTester almPatsDbtester; private final AuditDbTester auditDbTester; - private DbTester(System2 system2, @Nullable String schemaPath, AuditPersister auditPersister, MyBatisConfExtension... confExtensions) { + private DbTester(System2 system2, boolean useDifferentProjectUuids, @Nullable String schemaPath, AuditPersister auditPersister, MyBatisConfExtension... confExtensions) { super(TestDbImpl.create(schemaPath, confExtensions)); this.system2 = system2; this.auditPersister = auditPersister; initDbClient(); this.userTester = new UserDbTester(this); - this.componentTester = new ComponentDbTester(this); + this.componentTester = new ComponentDbTester(this, useDifferentProjectUuids); this.componentLinkTester = new ProjectLinkDbTester(this); this.favoriteTester = new FavoriteDbTester(this); this.eventTester = new EventDbTester(this); @@ -120,23 +120,35 @@ public class DbTester extends AbstractDbTester { } public static DbTester create() { - return new DbTester(System2.INSTANCE, null, new NoOpAuditPersister()); + return create(false); + } + + public static DbTester create(boolean useDifferentProjectUuids) { + return new DbTester(System2.INSTANCE, useDifferentProjectUuids, null, new NoOpAuditPersister()); } public static DbTester create(AuditPersister auditPersister) { - return new DbTester(System2.INSTANCE, null, auditPersister); + return new DbTester(System2.INSTANCE, false, null, auditPersister); } public static DbTester create(System2 system2, AuditPersister auditPersister) { - return new DbTester(system2, null, auditPersister); + return new DbTester(system2, false, null, auditPersister); } public static DbTester create(System2 system2) { - return new DbTester(system2, null, new NoOpAuditPersister()); + return new DbTester(system2, false, null, new NoOpAuditPersister()); + } + + public static DbTester create(System2 system2, boolean useDifferentProjectUuids) { + return new DbTester(system2, useDifferentProjectUuids, null, new NoOpAuditPersister()); } public static DbTester createWithExtensionMappers(System2 system2, Class firstMapperClass, Class... otherMapperClasses) { - return new DbTester(system2, null, new NoOpAuditPersister(), new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses)); + return createWithExtensionMappers(system2, false, firstMapperClass, otherMapperClasses); + } + + public static DbTester createWithExtensionMappers(System2 system2, boolean useDifferentProjectUuids, Class firstMapperClass, Class... otherMapperClasses) { + return new DbTester(system2, useDifferentProjectUuids, null, new NoOpAuditPersister(), new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses)); } private void initDbClient() { diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java index 3ebee457ea1..667b703230e 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java @@ -20,6 +20,7 @@ package org.sonar.db.component; import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; import javax.annotation.Nullable; import org.sonar.api.resources.Qualifiers; @@ -302,8 +303,9 @@ public class ComponentDbTester { addPortfolioProject(portfolio.uuid(), projectUuids); } - public void addPortfolioProject(ComponentDto portfolio, ComponentDto... projects) { - addPortfolioProject(portfolio, Arrays.stream(projects).map(ComponentDto::uuid).toArray(String[]::new)); + public void addPortfolioProject(ComponentDto portfolio, ComponentDto... mainBranches) { + List branchDtos = dbClient.branchDao().selectByUuids(db.getSession(), Arrays.stream(mainBranches).map(ComponentDto::uuid).toList()); + addPortfolioProject(portfolio, branchDtos.stream().map(BranchDto::getProjectUuid).toArray(String[]::new)); } public void addPortfolioProject(PortfolioDto portfolioDto, ProjectDto... projects) { @@ -541,29 +543,4 @@ public class ComponentDbTester { return t -> { }; } - - public class ProjectData { - private final BranchDto mainBranchDto; - private final ComponentDto mainBranchComponent; - private final ProjectDto projectDto; - - - public ProjectData(ProjectDto projectDto, BranchDto mainBranchDto, ComponentDto mainBranchComponent) { - this.mainBranchDto = mainBranchDto; - this.mainBranchComponent = mainBranchComponent; - this.projectDto = projectDto; - } - - public ComponentDto getMainBranchComponent() { - return mainBranchComponent; - } - - public ProjectDto getProjectDto() { - return projectDto; - } - - public BranchDto getMainBranchDto() { - return mainBranchDto; - } - } } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectData.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectData.java new file mode 100644 index 00000000000..21b55e1c66c --- /dev/null +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectData.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.component; + +import org.sonar.db.project.ProjectDto; + +public class ProjectData { + private final BranchDto mainBranchDto; + private final ComponentDto mainBranchComponent; + private final ProjectDto projectDto; + + public ProjectData(ProjectDto projectDto, BranchDto mainBranchDto, ComponentDto mainBranchComponent) { + this.mainBranchDto = mainBranchDto; + this.mainBranchComponent = mainBranchComponent; + this.projectDto = projectDto; + } + + public ComponentDto getMainBranchComponent() { + return mainBranchComponent; + } + + public ProjectDto getProjectDto() { + return projectDto; + } + + public BranchDto getMainBranchDto() { + return mainBranchDto; + } +} -- 2.39.5