aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-webapi
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-webserver-webapi')
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java16
-rw-r--r--server/sonar-webserver-webapi/src/main/resources/org/sonar/server/branch/ws/list-example.json2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectActionTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/SetAutomaticDeletionProtectionActionTest.java5
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java4
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java3
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java15
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java14
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SetBaselineActionTest.java5
19 files changed, 66 insertions, 36 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
index 45da74e4fe3..8aeea98aa5a 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
@@ -98,6 +98,20 @@ public class ComponentUpdater {
return componentDto;
}
+ /**
+ * - Create component
+ * - Apply default permission template
+ * - Add component to favorite if the component has the 'Project Creators' permission
+ * - Index component in es indexes
+ */
+ public ComponentDto createApplicationOrPortfolio(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid,
+ @Nullable String userLogin) {
+ ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userUuid, userLogin,
+ BranchDto.DEFAULT_APPLICATION_MAIN_BRANCH_NAME, c -> {});
+ commitAndIndex(dbSession, componentDto);
+ return componentDto;
+ }
+
public void commitAndIndex(DbSession dbSession, ComponentDto componentDto) {
projectIndexers.commitAndIndexComponents(dbSession, singletonList(componentDto), Cause.PROJECT_CREATION);
}
@@ -218,7 +232,7 @@ public class ComponentUpdater {
String branchKey = Optional.ofNullable(mainBranch)
.or(() -> Optional.ofNullable(propertiesDao.selectGlobalProperty(session, CorePropertyDefinitions.SONAR_PROJECTCREATION_MAINBRANCHNAME))
.map(PropertyDto::getValue))
- .orElse(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
+ .orElse(BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME);
BranchDto branch = new BranchDto()
.setBranchType(BranchType.BRANCH)
diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/branch/ws/list-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/branch/ws/list-example.json
index e37bdebc9f1..a035d056925 100644
--- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/branch/ws/list-example.json
+++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/branch/ws/list-example.json
@@ -11,7 +11,7 @@
"excludedFromPurge": false
},
{
- "name": "master",
+ "name": "main",
"isMain": true,
"type": "BRANCH",
"status": {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java
index 99671c08985..3b020a99fb3 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java
@@ -63,6 +63,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
import static org.sonar.db.permission.GlobalPermission.SCAN;
@@ -173,7 +174,7 @@ public class ImportAzureProjectActionTest {
.findFirst();
assertThat(mainBranch).isPresent();
- assertThat(mainBranch.get().getKey()).hasToString("master");
+ assertThat(mainBranch.get().getKey()).hasToString(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
}
@Test
@@ -183,7 +184,7 @@ public class ImportAzureProjectActionTest {
.setParam("projectName", "project-name")
.setParam("repositoryName", "repo-name");
- assertThatThrownBy(() -> request.execute())
+ assertThatThrownBy(request::execute)
.isInstanceOf(UnauthorizedException.class);
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java
index eb0e1a08fcf..a1c5c348ecc 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java
@@ -70,6 +70,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
import static org.sonar.db.permission.GlobalPermission.SCAN;
@@ -270,7 +271,7 @@ public class ImportBitbucketServerProjectActionTest {
Collection<BranchDto> branchDtos = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get());
List<BranchDto> collect = branchDtos.stream().filter(BranchDto::isMain).collect(Collectors.toList());
String mainBranchName = collect.iterator().next().getKey();
- assertThat(mainBranchName).isEqualTo("master");
+ assertThat(mainBranchName).isEqualTo(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
}
@Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectActionTest.java
index aa4820ecc31..4f4204eb81c 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectActionTest.java
@@ -56,6 +56,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
import static org.sonar.server.tester.UserSessionRule.standalone;
@@ -188,7 +189,7 @@ public class ImportGitLabProjectActionTest {
Assertions.assertThat(db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get()))
.extracting(BranchDto::getKey, BranchDto::isMain)
- .containsExactlyInAnyOrder(tuple("master", true));
+ .containsExactlyInAnyOrder(tuple(DEFAULT_PROJECT_MAIN_BRANCH_NAME, true));
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java
index 1ef0af77e4d..80ac0430697 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java
@@ -57,6 +57,7 @@ import static org.sonar.api.utils.DateUtils.dateToLong;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.BranchType.BRANCH;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
import static org.sonar.test.JsonAssert.assertJson;
@@ -161,7 +162,7 @@ public class ListActionTest {
assertThat(response.getBranchesList())
.extracting(Branch::getName, Branch::getIsMain, Branch::getType)
- .containsExactlyInAnyOrder(tuple("master", true, BranchType.BRANCH));
+ .containsExactlyInAnyOrder(tuple(DEFAULT_PROJECT_MAIN_BRANCH_NAME, true, BranchType.BRANCH));
}
@Test
@@ -194,7 +195,7 @@ public class ListActionTest {
assertThat(response.getBranchesList())
.extracting(Branch::getName, Branch::getType)
.containsExactlyInAnyOrder(
- tuple("master", BranchType.BRANCH),
+ tuple(DEFAULT_PROJECT_MAIN_BRANCH_NAME, BranchType.BRANCH),
tuple("feature/foo", BranchType.BRANCH),
tuple("feature/bar", BranchType.BRANCH));
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/SetAutomaticDeletionProtectionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/SetAutomaticDeletionProtectionActionTest.java
index 626d75bda8b..16174e39934 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/SetAutomaticDeletionProtectionActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/SetAutomaticDeletionProtectionActionTest.java
@@ -40,6 +40,7 @@ import org.sonar.server.ws.WsActionTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.api.resources.Qualifiers.PROJECT;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
public class SetAutomaticDeletionProtectionActionTest {
@@ -124,7 +125,7 @@ public class SetAutomaticDeletionProtectionActionTest {
assertThatThrownBy(() -> tester.newRequest()
.setParam("project", project.getKey())
- .setParam("branch", "master")
+ .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.setParam("value", "false")
.execute())
.isInstanceOf(IllegalArgumentException.class)
@@ -146,7 +147,7 @@ public class SetAutomaticDeletionProtectionActionTest {
assertThat(db.countRowsOfTable("project_branches")).isEqualTo(2);
Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid());
- assertThat(mainBranch.get().getKey()).isEqualTo("master");
+ assertThat(mainBranch.get().getKey()).isEqualTo(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
assertThat(mainBranch.get().isExcludeFromPurge()).isTrue();
Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid());
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java
index 0a5376d0d4a..551f413890a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java
@@ -30,6 +30,7 @@ import org.sonar.server.exceptions.NotFoundException;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newFileDto;
@@ -217,7 +218,7 @@ public class ComponentFinderTest {
public void get_by_key_and_branch_accept_main_branch() {
ComponentDto project = db.components().insertPublicProject();
- assertThat(underTest.getByKeyAndBranch(dbSession, project.getKey(), "master").uuid()).isEqualTo(project.uuid());
+ assertThat(underTest.getByKeyAndBranch(dbSession, project.getKey(), DEFAULT_PROJECT_MAIN_BRANCH_NAME).uuid()).isEqualTo(project.uuid());
}
@Test
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java
index c958148c03f..09263f5340a 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java
@@ -99,7 +99,7 @@ public class ComponentUpdaterTest {
Optional<BranchDto> branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), returned.uuid());
assertThat(branch).isPresent();
- assertThat(branch.get().getKey()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
+ assertThat(branch.get().getKey()).isEqualTo(BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME);
assertThat(branch.get().getMergeBranchUuid()).isNull();
assertThat(branch.get().getBranchType()).isEqualTo(BranchType.BRANCH);
assertThat(branch.get().getUuid()).isEqualTo(returned.uuid());
@@ -200,7 +200,7 @@ public class ComponentUpdaterTest {
assertThat(projectIndexers.hasBeenCalled(loaded.uuid(), ProjectIndexer.Cause.PROJECT_CREATION)).isTrue();
Optional<BranchDto> branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), returned.uuid());
assertThat(branch).isPresent();
- assertThat(branch.get().getKey()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
+ assertThat(branch.get().getKey()).isEqualTo(BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME);
assertThat(branch.get().getMergeBranchUuid()).isNull();
assertThat(branch.get().getBranchType()).isEqualTo(BranchType.BRANCH);
assertThat(branch.get().getUuid()).isEqualTo(returned.uuid());
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
index 1793a77a430..edea80d3e3d 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
@@ -48,6 +48,7 @@ import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.BranchType.BRANCH;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newDirectory;
@@ -288,11 +289,10 @@ public class ShowActionTest {
public void dont_show_branch_if_main_branch() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
- String branchKey = "master";
ShowWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, project.getKey())
- .setParam(PARAM_BRANCH, branchKey)
+ .setParam(PARAM_BRANCH, DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.executeProtobuf(ShowWsResponse.class);
assertThat(response.getComponent())
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
index c0564c6ed34..6152d29a743 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
@@ -61,6 +61,7 @@ import static org.sonar.api.resources.Qualifiers.APP;
import static org.sonar.api.resources.Qualifiers.FILE;
import static org.sonar.api.resources.Qualifiers.PROJECT;
import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newChildComponent;
import static org.sonar.db.component.ComponentTesting.newDirectory;
@@ -384,7 +385,7 @@ public class TreeActionTest {
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
- .setParam(PARAM_BRANCH, "master")
+ .setParam(PARAM_BRANCH, DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.executeProtobuf(TreeWsResponse.class);
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getBranch)
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java
index 2c2769ae308..b735139beb4 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java
@@ -57,6 +57,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.ComponentTesting.newFileDto;
public class PullActionTest {
@@ -64,7 +65,7 @@ public class PullActionTest {
private static final long NOW = 10_000_000_000L;
private static final long PAST = 1_000_000_000L;
- private static final String DEFAULT_BRANCH = "master";
+ private static final String DEFAULT_BRANCH = DEFAULT_PROJECT_MAIN_BRANCH_NAME;
@Rule
public DbTester dbTester = DbTester.create();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java
index 29b0d0f7a2b..637b5c40910 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java
@@ -58,13 +58,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.ComponentTesting.newFileDto;
public class PullTaintActionTest {
private static final long NOW = 10_000_000_000L;
private static final long PAST = 1_000_000_000L;
- private static final String DEFAULT_BRANCH = "master";
+ private static final String DEFAULT_BRANCH = DEFAULT_PROJECT_MAIN_BRANCH_NAME;
@Rule
public DbTester dbTester = DbTester.create();
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java
index b77b308559e..f22493335fd 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java
@@ -66,6 +66,7 @@ import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.api.web.UserRole.USER;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.BranchType.BRANCH;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newDirectory;
@@ -668,7 +669,7 @@ public class SearchActionComponentsTest {
SearchWsResponse result = ws.newRequest()
.setParam(PARAM_COMPONENT_KEYS, project.getKey())
- .setParam(PARAM_BRANCH, "master")
+ .setParam(PARAM_BRANCH, DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.executeProtobuf(SearchWsResponse.class);
assertThat(result.getIssuesList())
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
index e3e8ecba3e7..08cae5ea7ea 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
@@ -47,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
@@ -147,7 +148,7 @@ public class ComponentActionTest {
ComponentWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
- .setParam(PARAM_BRANCH, "master")
+ .setParam(PARAM_BRANCH, DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.setParam(PARAM_METRIC_KEYS, "complexity")
.executeProtobuf(ComponentWsResponse.class);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
index 2de3079465f..241edc67f81 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
@@ -32,6 +32,7 @@ import org.sonar.core.util.stream.MoreCollectors;
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.ComponentTesting;
import org.sonar.db.component.ResourceTypesRule;
@@ -564,7 +565,7 @@ public class ComponentTreeActionTest {
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
- .setParam(PARAM_BRANCH, "master")
+ .setParam(PARAM_BRANCH, BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.setParam(PARAM_METRIC_KEYS, complexity.getKey())
.executeProtobuf(ComponentTreeWsResponse.class);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java
index 8cee6bd9bde..fab0c1bd5a6 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java
@@ -50,6 +50,7 @@ import org.sonarqube.ws.NewCodePeriods.ShowWSResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
public class ListActionTest {
@@ -115,7 +116,7 @@ public class ListActionTest {
assertThat(response).isNotNull();
assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains("master", "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
+ .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
//check if global default is set
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
@@ -138,7 +139,7 @@ public class ListActionTest {
assertThat(response).isNotNull();
assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains("master", "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
+ .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
//check if global default is set
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
@@ -173,7 +174,7 @@ public class ListActionTest {
assertThat(response).isNotNull();
assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains("master", "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
+ .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
//check if project setting is set
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
@@ -191,7 +192,7 @@ public class ListActionTest {
assertThat(response).isNotNull();
assertThat(response.getNewCodePeriodsCount()).isOne();
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .containsOnly("master");
+ .containsOnly(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
//check if global setting is set
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
@@ -227,7 +228,7 @@ public class ListActionTest {
assertThat(response).isNotNull();
assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains("master", "OWN_SETTINGS", "GLOBAL_SETTINGS");
+ .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "GLOBAL_SETTINGS");
Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream()
.filter(s -> !s.getInherited())
@@ -282,7 +283,7 @@ public class ListActionTest {
assertThat(response).isNotNull();
assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .contains("master", "OWN_SETTINGS", "PROJECT_SETTINGS");
+ .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "PROJECT_SETTINGS");
Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream()
.filter(s -> !s.getInherited())
@@ -343,7 +344,7 @@ public class ListActionTest {
assertThat(response).isNotNull();
assertThat(response.getNewCodePeriodsCount()).isEqualTo(2);
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
- .containsOnly("master", "PROJECT_BRANCH");
+ .containsOnly(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "PROJECT_BRANCH");
ShowWSResponse result = response.getNewCodePeriodsList().get(0);
assertThat(result.getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java
index 8e1019fc690..e0335b2a030 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java
@@ -54,6 +54,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
@RunWith(DataProviderRunner.class)
public class SetActionTest {
@@ -130,7 +131,7 @@ public class SetActionTest {
assertThatThrownBy(() -> ws.newRequest()
.setParam("project", project.getKey())
- .setParam("branch", "master")
+ .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.setParam("type", "number_of_days")
.execute())
.isInstanceOf(IllegalArgumentException.class)
@@ -145,7 +146,7 @@ public class SetActionTest {
assertThatThrownBy(() -> ws.newRequest()
.setParam("project", project.getKey())
.setParam("type", "specific_analysis")
- .setParam("branch", "master")
+ .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.execute())
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("New Code Period type 'SPECIFIC_ANALYSIS' requires a value");
@@ -159,7 +160,7 @@ public class SetActionTest {
assertThatThrownBy(() -> ws.newRequest()
.setParam("project", project.getKey())
.setParam("type", "number_of_days")
- .setParam("branch", "master")
+ .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.setParam("value", "unknown")
.execute())
.isInstanceOf(IllegalArgumentException.class)
@@ -174,7 +175,7 @@ public class SetActionTest {
assertThatThrownBy(() -> ws.newRequest()
.setParam("project", project.getKey())
.setParam("type", "specific_analysis")
- .setParam("branch", "master")
+ .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.setParam("value", "unknown")
.execute())
.isInstanceOf(NotFoundException.class)
@@ -194,11 +195,12 @@ public class SetActionTest {
assertThatThrownBy(() -> ws.newRequest()
.setParam("project", project.getKey())
.setParam("type", "specific_analysis")
- .setParam("branch", "master")
+ .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.setParam("value", analysisBranch.getUuid())
.execute())
.isInstanceOf(IllegalArgumentException.class)
- .hasMessageContaining("Analysis '" + analysisBranch.getUuid() + "' does not belong to branch 'master' of project '" + project.getKey() + "'");
+ .hasMessageContaining("Analysis '" + analysisBranch.getUuid() + "' does not belong to branch '" + DEFAULT_PROJECT_MAIN_BRANCH_NAME +
+ "' of project '" + project.getKey() + "'");
}
// validation of project/branch
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SetBaselineActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SetBaselineActionTest.java
index 22629b3c0b9..664235f34e9 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SetBaselineActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SetBaselineActionTest.java
@@ -52,6 +52,7 @@ import org.sonar.server.ws.WsActionTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.SPECIFIC_ANALYSIS;
import static org.sonar.server.projectanalysis.ws.ProjectAnalysesWsParameters.PARAM_ANALYSIS;
import static org.sonar.server.projectanalysis.ws.ProjectAnalysesWsParameters.PARAM_BRANCH;
@@ -116,7 +117,7 @@ public class SetBaselineActionTest {
ComponentDto project = tester.insertPrivateProject();
SnapshotDto analysis = db.components().insertSnapshot(project);
- assertThatThrownBy(() -> call(project.getKey(), "master", analysis.getUuid()))
+ assertThatThrownBy(() -> call(project.getKey(), DEFAULT_PROJECT_MAIN_BRANCH_NAME, analysis.getUuid()))
.isInstanceOf(ForbiddenException.class)
.hasMessage("Insufficient privileges");
}
@@ -178,7 +179,7 @@ public class SetBaselineActionTest {
SnapshotDto analysis = db.components().insertSnapshot(project);
logInAsProjectAdministrator(project);
- ComponentDto otherProject = tester.insertPrivateProjectWithCustomBranch("main");
+ ComponentDto otherProject = tester.insertPrivateProjectWithCustomBranch("develop");
BranchDto branchOfOtherProject = branchDao.selectByUuid(dbSession, otherProject.uuid()).get();
assertThatThrownBy(() -> call(project.getKey(), branchOfOtherProject.getKey(), analysis.getUuid()))