aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/testFixtures/java/org/sonar
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-db-dao/src/testFixtures/java/org/sonar')
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java7
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java1
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/dependency/ProjectDependenciesDbTester.java64
3 files changed, 71 insertions, 1 deletions
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 041cf9ffc84..9e6a46fecd5 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
@@ -42,6 +42,7 @@ import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ProjectLinkDbTester;
+import org.sonar.db.dependency.ProjectDependenciesDbTester;
import org.sonar.db.event.EventDbTester;
import org.sonar.db.favorite.FavoriteDbTester;
import org.sonar.db.issue.IssueDbTester;
@@ -94,6 +95,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> implements BeforeEach
private final AlmPatsDbTester almPatsDbtester;
private final AuditDbTester auditDbTester;
private final AnticipatedTransitionDbTester anticipatedTransitionDbTester;
+ private final ProjectDependenciesDbTester projectDependenciesDbTester;
private DbTester(UuidFactory uuidFactory, System2 system2, @Nullable String schemaPath, AuditPersister auditPersister, MyBatisConfExtension... confExtensions) {
super(TestDbImpl.create(schemaPath, confExtensions));
@@ -125,6 +127,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> implements BeforeEach
this.almPatsDbtester = new AlmPatsDbTester(this);
this.auditDbTester = new AuditDbTester(this);
this.anticipatedTransitionDbTester = new AnticipatedTransitionDbTester(this);
+ this.projectDependenciesDbTester = new ProjectDependenciesDbTester(this);
}
public static DbTester create() {
@@ -268,6 +271,10 @@ public class DbTester extends AbstractDbTester<TestDbImpl> implements BeforeEach
return anticipatedTransitionDbTester;
}
+ public ProjectDependenciesDbTester projectDependencies() {
+ return projectDependenciesDbTester;
+ }
+
@Override
public void afterEach(ExtensionContext context) throws Exception {
after();
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 c4fd31374e0..7990f52e503 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
@@ -27,7 +27,6 @@ import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.entity.EntityDto;
import org.sonar.db.portfolio.PortfolioDto;
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/dependency/ProjectDependenciesDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/dependency/ProjectDependenciesDbTester.java
new file mode 100644
index 00000000000..edd64b6013e
--- /dev/null
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/dependency/ProjectDependenciesDbTester.java
@@ -0,0 +1,64 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 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.dependency;
+
+import java.util.function.Consumer;
+import javax.annotation.Nullable;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbTester;
+import org.sonar.db.component.ComponentDto;
+
+import static org.apache.commons.lang3.StringUtils.EMPTY;
+
+public class ProjectDependenciesDbTester {
+ private final DbTester db;
+ private final DbClient dbClient;
+
+ public ProjectDependenciesDbTester(DbTester db) {
+ this.db = db;
+ this.dbClient = db.getDbClient();
+ }
+
+ public ProjectDependencyDto insertProjectDependency(String branchUuid) {
+ return insertProjectDependency(branchUuid, EMPTY, null);
+ }
+
+ public ProjectDependencyDto insertProjectDependency(String branchUuid, String suffix) {
+ return insertProjectDependency(branchUuid, suffix, null);
+ }
+
+ public ProjectDependencyDto insertProjectDependency(String branchUuid, String suffix, @Nullable Consumer<ComponentDto> dtoPopulator) {
+ ComponentDto componentDto = new ComponentDto().setUuid("uuid" + suffix)
+ .setKey("key" + suffix)
+ .setUuidPath("uuidPath" + suffix)
+ .setName("name" + suffix)
+ .setLongName("long_name" + suffix)
+ .setBranchUuid(branchUuid);
+
+ if (dtoPopulator != null) {
+ dtoPopulator.accept(componentDto);
+ }
+
+ db.components().insertComponent(componentDto);
+ var projectDependencyDto = new ProjectDependencyDto(componentDto.uuid(), "version" + suffix, "includePaths" + suffix, "packageManager" + suffix, 1L, 2L);
+ dbClient.projectDependenciesDao().insert(db.getSession(), projectDependencyDto);
+ return projectDependencyDto;
+ }
+}