aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>2023-05-11 10:33:45 +0200
committersonartech <sonartech@sonarsource.com>2023-05-11 20:03:13 +0000
commit9bae806d9195bbd5c63063dd64dcb855d8fb364e (patch)
tree0abd1c8c10d4be02790320174bc72621bcc3ecdc
parentcc1d563b233d7099b2430e247e44c25b53fa8a74 (diff)
downloadsonarqube-9bae806d9195bbd5c63063dd64dcb855d8fb364e.tar.gz
sonarqube-9bae806d9195bbd5c63063dd64dcb855d8fb364e.zip
SONAR-18856 Fix Delete/List branch endpoint to support project uuid
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java2
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java10
-rw-r--r--server/sonar-webserver-es/src/testFixtures/java/org/sonar/server/permission/index/PermissionIndexerTester.java5
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java12
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java46
5 files changed, 48 insertions, 27 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
index 88f6520476c..d777f526599 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueTesting.java
@@ -53,7 +53,7 @@ public class IssueTesting {
}
public static IssueDto newIssue(RuleDto rule, String projectUuid, String projectKey, ComponentDto file) {
- checkArgument(file.branchUuid().equals(projectUuid), "The file doesn't belong to the project");
+ //checkArgument(file.branchUuid().equals(projectUuid), "The file doesn't belong to the project");
return new IssueDto()
.setKee("uuid_" + randomAlphabetic(5))
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
index 1c17b15a5e3..f7a23fdd5e1 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/measure/MeasureDbTester.java
@@ -24,6 +24,7 @@ import java.util.function.Consumer;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
@@ -60,6 +61,15 @@ public class MeasureDbTester {
}
@SafeVarargs
+ public final LiveMeasureDto insertLiveMeasure(BranchDto branchDto, MetricDto metric, Consumer<LiveMeasureDto>... consumers) {
+ LiveMeasureDto dto = newLiveMeasure(branchDto, metric);
+ Arrays.stream(consumers).forEach(c -> c.accept(dto));
+ dbClient.liveMeasureDao().insert(dbSession, dto);
+ dbSession.commit();
+ return dto;
+ }
+
+ @SafeVarargs
public final MetricDto insertMetric(Consumer<MetricDto>... consumers) {
MetricDto metricDto = newMetricDto();
Arrays.stream(consumers).forEach(c -> c.accept(metricDto));
diff --git a/server/sonar-webserver-es/src/testFixtures/java/org/sonar/server/permission/index/PermissionIndexerTester.java b/server/sonar-webserver-es/src/testFixtures/java/org/sonar/server/permission/index/PermissionIndexerTester.java
index fa02817876f..59d6417564f 100644
--- a/server/sonar-webserver-es/src/testFixtures/java/org/sonar/server/permission/index/PermissionIndexerTester.java
+++ b/server/sonar-webserver-es/src/testFixtures/java/org/sonar/server/permission/index/PermissionIndexerTester.java
@@ -22,6 +22,7 @@ package org.sonar.server.permission.index;
import java.util.List;
import java.util.stream.Stream;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.es.EsTester;
@@ -41,6 +42,10 @@ public class PermissionIndexerTester {
return allow(stream(projects).map(project -> new IndexPermissions(project.uuid(), project.qualifier()).allowAnyone()).toList());
}
+ public PermissionIndexerTester allowOnlyAnyone(ProjectDto... projects) {
+ return allow(stream(projects).map(project -> new IndexPermissions(project.getUuid(), project.getQualifier()).allowAnyone()).toList());
+ }
+
public PermissionIndexerTester allowOnlyUser(ComponentDto project, UserDto user) {
IndexPermissions dto = new IndexPermissions(project.uuid(), project.qualifier())
.addUserUuid(user.getUuid());
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java
index 7f1e99a2d51..d6878af3c68 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/DeleteActionIT.java
@@ -28,7 +28,7 @@ import org.sonar.api.web.UserRole;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.TestComponentFinder;
@@ -49,7 +49,7 @@ import static org.mockito.Mockito.verify;
public class DeleteActionIT {
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private ComponentCleanerService componentCleanerService = mock(ComponentCleanerService.class);
private ComponentFinder componentFinder = TestComponentFinder.from(db);
@@ -62,8 +62,8 @@ public class DeleteActionIT {
@Test
public void delete_branch() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1"));
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
+ db.components().insertProjectBranch(project, b -> b.setKey("branch1"));
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
tester.newRequest()
@@ -102,7 +102,7 @@ public class DeleteActionIT {
@Test
public void fail_if_branch_does_not_exist() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
assertThatThrownBy(() -> tester.newRequest()
@@ -127,7 +127,7 @@ public class DeleteActionIT {
@Test
public void fail_if_branch_is_main() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
db.executeUpdateSql("UPDATE project_branches set KEE = 'main'");
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java
index d33740f6351..cb83c6620c2 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/branch/ws/ListActionIT.java
@@ -26,10 +26,13 @@ import org.sonar.api.resources.ResourceTypes;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.metric.MetricDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.es.EsTester;
@@ -65,7 +68,7 @@ import static org.sonar.test.JsonAssert.assertJson;
public class ListActionIT {
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public EsTester es = EsTester.create();
@Rule
@@ -97,19 +100,20 @@ public class ListActionIT {
@Test
public void test_example() {
- ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("sonarqube")).getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject(p -> p.setKey("sonarqube"));
+ ProjectDto project = projectData.getProjectDto();
db.getDbClient().snapshotDao().insert(db.getSession(),
- newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
- db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR"));
+ newAnalysis(projectData.getMainBranchDto()).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
+ db.measures().insertLiveMeasure(projectData.getMainBranchComponent(), qualityGateStatus, m -> m.setData("ERROR"));
- ComponentDto branch = db.components()
+ BranchDto branch = db.components()
.insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(BRANCH));
db.getDbClient().snapshotDao().insert(db.getSession(),
newAnalysis(branch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime()));
db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK"));
RuleDto rule = db.rules().insert();
- db.issues().insert(rule, branch, branch, i -> i.setType(BUG).setResolution(null));
+ db.issues().insert(rule, project, db.components().getComponentDto(branch), i -> i.setType(BUG).setResolution(null));
indexIssues();
@@ -126,19 +130,20 @@ public class ListActionIT {
@Test
public void test_with_SCAN_EXCUTION_permission() {
- ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("sonarqube")).getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject(p -> p.setKey("sonarqube"));
+ ProjectDto project = projectData.getProjectDto();
db.getDbClient().snapshotDao().insert(db.getSession(),
- newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
- db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR"));
+ newAnalysis(projectData.getMainBranchDto()).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime()));
+ db.measures().insertLiveMeasure(projectData.getMainBranchDto(), qualityGateStatus, m -> m.setData("ERROR"));
- ComponentDto branch = db.components()
+ BranchDto branch = db.components()
.insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(BRANCH));
db.getDbClient().snapshotDao().insert(db.getSession(),
newAnalysis(branch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime()));
db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK"));
RuleDto rule = db.rules().insert();
- db.issues().insert(rule, branch, branch, i -> i.setType(BUG).setResolution(null));
+ db.issues().insert(rule, project, db.components().getComponentDto(branch), i -> i.setType(BUG).setResolution(null));
indexIssues();
userSession.logIn().addProjectPermission(SCAN.getKey(), project);
@@ -153,7 +158,7 @@ public class ListActionIT {
@Test
public void main_branch() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
userSession.logIn().addProjectPermission(USER, project);
ListWsResponse response = ws.newRequest()
@@ -167,8 +172,9 @@ public class ListActionIT {
@Test
public void main_branch_with_specified_name() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- db.getDbClient().branchDao().updateBranchName(db.getSession(), project.uuid(), "head");
+ ProjectData projectData = db.components().insertPrivateProject();
+ ProjectDto project = projectData.getProjectDto();
+ db.getDbClient().branchDao().updateBranchName(db.getSession(), projectData.getMainBranchDto().getUuid(), "head");
db.commit();
userSession.logIn().addProjectPermission(USER, project);
@@ -183,7 +189,7 @@ public class ListActionIT {
@Test
public void test_project_with_branches() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
db.components().insertProjectBranch(project, b -> b.setKey("feature/bar"));
db.components().insertProjectBranch(project, b -> b.setKey("feature/foo"));
userSession.logIn().addProjectPermission(USER, project);
@@ -202,9 +208,9 @@ public class ListActionIT {
@Test
public void status_on_branch() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
userSession.logIn().addProjectPermission(USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK"));
ListWsResponse response = ws.newRequest()
@@ -220,9 +226,9 @@ public class ListActionIT {
public void response_contains_date_of_last_analysis() {
Long lastAnalysisBranch = dateToLong(parseDateTime("2017-04-01T00:00:00+0100"));
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPrivateProject().getProjectDto();
userSession.logIn().addProjectPermission(USER, project);
- ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
+ BranchDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
db.getDbClient().snapshotDao().insert(db.getSession(),
newAnalysis(branch2).setCreatedAt(lastAnalysisBranch));
db.commit();
@@ -247,7 +253,7 @@ public class ListActionIT {
@Test
public void application_branches() {
- ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
+ ProjectDto application = db.components().insertPrivateApplication().getProjectDto();
db.components().insertProjectBranch(application, b -> b.setKey("feature/bar"));
db.components().insertProjectBranch(application, b -> b.setKey("feature/foo"));
userSession.logIn().addProjectPermission(USER, application);