]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Use different uuids for project and main branch in ITs
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 9 May 2023 08:10:47 +0000 (03:10 -0500)
committersonartech <sonartech@sonarsource.com>
Tue, 9 May 2023 20:10:37 +0000 (20:10 +0000)
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ProjectData.java [new file with mode: 0644]

index dafd9db00d800d084ecd119a35da85d9c1c9cf9f..55b9cd9378cb4cd2b9f23fe20089c32b092f4bee 100644 (file)
@@ -89,14 +89,14 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
   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<TestDbImpl> {
   }
 
   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() {
index 3ebee457ea1ebb7f44f4e8ec62e52373a14f85f4..667b703230e856c59858c0975604832611350eba 100644 (file)
@@ -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<BranchDto> 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 (file)
index 0000000..21b55e1
--- /dev/null
@@ -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;
+  }
+}