aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/testFixtures/java
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-09-20 11:59:16 -0500
committersonartech <sonartech@sonarsource.com>2022-10-12 20:03:43 +0000
commit566094fc629ab1e92afb0cdf191a0e2c685b5c35 (patch)
treece172266109cf1c4e81a041e460c6cc7bcd5d50e /server/sonar-db-dao/src/testFixtures/java
parentbcfb1cac55137b838da7a93385b20e0e5ed47abb (diff)
downloadsonarqube-566094fc629ab1e92afb0cdf191a0e2c685b5c35.tar.gz
sonarqube-566094fc629ab1e92afb0cdf191a0e2c685b5c35.zip
SONAR-17352 Refactor component keys to not include branch suffix
Diffstat (limited to 'server/sonar-db-dao/src/testFixtures/java')
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java10
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java45
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java2
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java2
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/source/FileSourceTester.java4
5 files changed, 23 insertions, 40 deletions
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 db56cf6c597..be729322f02 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
@@ -478,7 +478,7 @@ public class ComponentDbTester {
@SafeVarargs
public final ComponentDto insertProjectBranch(ComponentDto project, Consumer<BranchDto>... dtoPopulators) {
// MainBranchProjectUuid will be null if it's a main branch
- BranchDto branchDto = ComponentTesting.newBranchDto(firstNonNull(project.getMainBranchProjectUuid(), project.projectUuid()), BRANCH);
+ BranchDto branchDto = ComponentTesting.newBranchDto(firstNonNull(project.getMainBranchProjectUuid(), project.branchUuid()), BRANCH);
Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(branchDto));
return insertProjectBranch(project, branchDto);
}
@@ -502,7 +502,7 @@ public class ComponentDbTester {
public final ComponentDto insertProjectBranch(ComponentDto project, BranchDto branchDto) {
// MainBranchProjectUuid will be null if it's a main branch
- checkArgument(branchDto.getProjectUuid().equals(firstNonNull(project.getMainBranchProjectUuid(), project.projectUuid())));
+ checkArgument(branchDto.getProjectUuid().equals(firstNonNull(project.getMainBranchProjectUuid(), project.branchUuid())));
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto);
insertComponent(branch);
dbClient.branchDao().insert(dbSession, branchDto);
@@ -518,7 +518,7 @@ public class ComponentDbTester {
public static ProjectDto toProjectDto(ComponentDto componentDto, long createTime) {
return new ProjectDto()
.setUuid(componentDto.uuid())
- .setKey(componentDto.getDbKey())
+ .setKey(componentDto.getKey())
.setQualifier(componentDto.qualifier() != null ? componentDto.qualifier() : Qualifiers.PROJECT)
.setCreatedAt(createTime)
.setUpdatedAt(createTime)
@@ -530,8 +530,8 @@ public class ComponentDbTester {
public static PortfolioDto toPortfolioDto(ComponentDto componentDto, long createTime) {
return new PortfolioDto()
.setUuid(componentDto.uuid())
- .setKey(componentDto.getDbKey())
- .setRootUuid(componentDto.projectUuid())
+ .setKey(componentDto.getKey())
+ .setRootUuid(componentDto.branchUuid())
.setSelectionMode(NONE.name())
.setCreatedAt(createTime)
.setUpdatedAt(createTime)
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
index 741fe1ed192..b32970caf9a 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
@@ -34,8 +34,6 @@ import static org.sonar.db.component.ComponentDto.PULL_REQUEST_SEPARATOR;
import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent;
-import static org.sonar.db.component.ComponentDto.generateBranchKey;
-import static org.sonar.db.component.ComponentDto.generatePullRequestKey;
public class ComponentTesting {
@@ -51,7 +49,7 @@ public class ComponentTesting {
String filename = "NAME_" + fileUuid;
String path = directory != null ? directory.path() + "/" + filename : module.path() + "/" + filename;
return newChildComponent(fileUuid, module, directory == null ? module : directory)
- .setDbKey(generateKey("FILE_KEY_" + fileUuid, module))
+ .setKey("FILE_KEY_" + fileUuid)
.setName(filename)
.setLongName(path)
.setScope(Scopes.FILE)
@@ -68,7 +66,7 @@ public class ComponentTesting {
public static ComponentDto newDirectory(ComponentDto module, String uuid, String path) {
String key = !path.equals("/") ? module.getKey() + ":" + path : module.getKey() + ":/";
return newChildComponent(uuid, module, module)
- .setDbKey(generateKey(key, module))
+ .setKey(key)
.setName(path)
.setLongName(path)
.setPath(path)
@@ -78,7 +76,7 @@ public class ComponentTesting {
public static ComponentDto newSubPortfolio(ComponentDto portfolioOrSubPortfolio, String uuid, String key) {
return newModuleDto(uuid, portfolioOrSubPortfolio)
- .setDbKey(key)
+ .setKey(key)
.setName(key)
.setLongName(key)
.setScope(Scopes.PROJECT)
@@ -94,7 +92,7 @@ public class ComponentTesting {
public static ComponentDto newModuleDto(String uuid, ComponentDto parentModuleOrProject) {
return newChildComponent(uuid, parentModuleOrProject, parentModuleOrProject)
.setModuleUuidPath(parentModuleOrProject.moduleUuidPath() + uuid + UUID_PATH_SEPARATOR)
- .setDbKey(generateKey("MODULE_KEY_" + uuid, parentModuleOrProject))
+ .setKey("MODULE_KEY_" + uuid)
.setName("NAME_" + uuid)
.setLongName("LONG_NAME_" + uuid)
.setPath("module")
@@ -103,19 +101,6 @@ public class ComponentTesting {
.setLanguage(null);
}
- private static String generateKey(String key, ComponentDto parentModuleOrProject) {
- String branch = parentModuleOrProject.getBranch();
- if (branch != null) {
- return generateBranchKey(key, branch);
- }
- String pullRequest = parentModuleOrProject.getPullRequest();
- if (pullRequest != null) {
- return generatePullRequestKey(key, pullRequest);
- }
-
- return key;
- }
-
public static ComponentDto newModuleDto(ComponentDto subProjectOrProject) {
return newModuleDto(Uuids.createFast(), subProjectOrProject);
}
@@ -140,10 +125,10 @@ public class ComponentTesting {
return new ComponentDto()
.setUuid(uuid)
.setUuidPath(UUID_PATH_OF_ROOT)
- .setProjectUuid(uuid)
+ .setBranchUuid(uuid)
.setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR)
.setRootUuid(uuid)
- .setDbKey("KEY_" + uuid)
+ .setKey("KEY_" + uuid)
.setName("NAME_" + uuid)
.setLongName("LONG_NAME_" + uuid)
.setDescription("DESCRIPTION_" + uuid)
@@ -177,7 +162,7 @@ public class ComponentTesting {
public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) {
return newChildComponent(uuid, view, view)
- .setDbKey(view.getDbKey() + project.getDbKey())
+ .setKey(view.getKey() + project.getKey())
.setName(project.name())
.setLongName(project.longName())
.setCopyComponentUuid(project.uuid())
@@ -194,8 +179,8 @@ public class ComponentTesting {
return new ComponentDto()
.setUuid(uuid)
.setUuidPath(formatUuidPathFromParent(parent))
- .setDbKey(uuid)
- .setProjectUuid(moduleOrProject.projectUuid())
+ .setKey(uuid)
+ .setBranchUuid(moduleOrProject.branchUuid())
.setRootUuid(moduleOrProject.uuid())
.setModuleUuid(moduleOrProject.uuid())
.setModuleUuidPath(moduleOrProject.moduleUuidPath())
@@ -216,7 +201,7 @@ public class ComponentTesting {
}
public static BranchDto newBranchDto(ComponentDto project) {
- return newBranchDto(project.projectUuid(), BranchType.BRANCH);
+ return newBranchDto(project.branchUuid(), BranchType.BRANCH);
}
public static BranchDto newBranchDto(ComponentDto branchComponent, BranchType branchType) {
@@ -238,11 +223,11 @@ public class ComponentTesting {
return new ComponentDto()
.setUuid(uuid)
.setUuidPath(UUID_PATH_OF_ROOT)
- .setProjectUuid(uuid)
+ .setBranchUuid(uuid)
.setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR)
.setRootUuid(uuid)
// name of the branch is not mandatory on the main branch
- .setDbKey(branchName != null ? project.getKey() + branchSeparator + branchName : project.getKey())
+ .setKey(branchName != null ? project.getKey() + branchSeparator + branchName : project.getKey())
.setMainBranchProjectUuid(project.getUuid())
.setName(project.getName())
.setLongName(project.getName())
@@ -259,16 +244,14 @@ public class ComponentTesting {
checkArgument(project.qualifier().equals(Qualifiers.PROJECT) || project.qualifier().equals(Qualifiers.APP));
checkArgument(project.getMainBranchProjectUuid() == null);
String branchName = branchDto.getKey();
- String branchSeparator = branchDto.getBranchType() == PULL_REQUEST ? PULL_REQUEST_SEPARATOR : BRANCH_KEY_SEPARATOR;
String uuid = branchDto.getUuid();
return new ComponentDto()
.setUuid(uuid)
.setUuidPath(UUID_PATH_OF_ROOT)
- .setProjectUuid(uuid)
+ .setBranchUuid(uuid)
.setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR)
.setRootUuid(uuid)
- // name of the branch is not mandatory on the main branch
- .setDbKey(branchName != null ? project.getDbKey() + branchSeparator + branchName : project.getKey())
+ .setKey(project.getKey())
.setMainBranchProjectUuid(project.uuid())
.setName(project.name())
.setLongName(project.longName())
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java
index ae451bacac6..5de13132e63 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/SnapshotTesting.java
@@ -32,7 +32,7 @@ public class SnapshotTesting {
public static SnapshotDto newAnalysis(ComponentDto rootComponent) {
checkNotNull(rootComponent.uuid(), "Project UUID must be set");
- checkArgument(rootComponent.uuid().equals(rootComponent.projectUuid()), "Component is not a tree root");
+ checkArgument(rootComponent.uuid().equals(rootComponent.branchUuid()), "Component is not a tree root");
return newAnalysis(rootComponent.uuid());
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
index a39dee2a830..330f6cbb9e8 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureTesting.java
@@ -70,7 +70,7 @@ public class MeasureTesting {
return new LiveMeasureDto()
.setMetricUuid(metric.getUuid())
.setComponentUuid(component.uuid())
- .setProjectUuid(component.projectUuid())
+ .setProjectUuid(component.branchUuid())
.setData(String.valueOf(cursor++))
.setValue((double) cursor++)
.setVariation((double) cursor++);
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/source/FileSourceTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/source/FileSourceTester.java
index 4206dfdfce0..9175c4ab8f1 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/source/FileSourceTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/source/FileSourceTester.java
@@ -45,7 +45,7 @@ public class FileSourceTester {
public final FileSourceDto insertFileSource(ComponentDto file, Consumer<FileSourceDto>... dtoPopulators) {
FileSourceDto dto = new FileSourceDto()
.setUuid(Uuids.createFast())
- .setProjectUuid(file.projectUuid())
+ .setProjectUuid(file.branchUuid())
.setFileUuid(file.uuid())
.setSrcHash(randomAlphanumeric(50))
.setDataHash(randomAlphanumeric(50))
@@ -65,7 +65,7 @@ public class FileSourceTester {
public final FileSourceDto insertFileSource(ComponentDto file, int numLines, Consumer<FileSourceDto>... dtoPopulators) {
FileSourceDto dto = new FileSourceDto()
.setUuid(Uuids.createFast())
- .setProjectUuid(file.projectUuid())
+ .setProjectUuid(file.branchUuid())
.setFileUuid(file.uuid())
.setSrcHash(randomAlphanumeric(50))
.setDataHash(randomAlphanumeric(50))