From ebc870fa3d67138d8a45a152cd5d024395b9ad2f Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 28 Sep 2022 10:31:10 -0500 Subject: [PATCH] SONAR-17352 Refactor component keys to not include branch suffix --- .../analysis/ProjectConfigurationFactory.java | 13 +--- .../step/ReportPersistComponentsStepTest.java | 3 +- .../org/sonar/db/component/ComponentDao.java | 3 +- .../org/sonar/db/component/ComponentDto.java | 8 +-- .../db/component/ComponentKeyUpdaterDao.java | 39 +---------- .../component/ComponentKeyUpdaterMapper.java | 4 +- .../java/org/sonar/db/measure/MeasureDao.java | 4 +- .../org/sonar/db/measure/MeasureMapper.java | 2 +- .../org/sonar/db/property/PropertiesDao.java | 1 + .../component/ComponentKeyUpdaterMapper.xml | 10 +-- .../sonar/db/measure/LiveMeasureMapper.xml | 12 +--- .../org/sonar/db/measure/MeasureMapper.xml | 12 +--- .../component/ComponentKeyUpdaterDaoTest.java | 62 +++++++---------- .../sonar/db/component/ComponentDbTester.java | 20 ++++++ .../sonar/db/component/ComponentTesting.java | 9 +-- .../ProjectConfigurationLoaderImplTest.java | 1 + .../ce/queue/BranchSupportDelegate.java | 3 +- .../server/ce/queue/ReportSubmitter.java | 5 +- .../server/branch/ws/ListActionTest.java | 14 ---- .../ce/queue/BranchReportSubmitterTest.java | 68 +++++++++---------- .../server/component/ComponentFinderTest.java | 22 ------ .../server/component/ws/ShowActionTest.java | 13 ---- .../server/component/ws/TreeActionTest.java | 13 ---- .../server/duplication/ws/ShowActionTest.java | 13 ---- .../server/favorite/ws/AddActionTest.java | 12 ---- .../issue/ws/SearchActionComponentsTest.java | 19 ------ .../server/issue/ws/SearchActionTest.java | 3 +- .../measure/ws/ComponentActionTest.java | 18 ----- .../measure/ws/ComponentTreeActionTest.java | 17 ----- .../measure/ws/SearchHistoryActionTest.java | 23 ++----- .../server/notification/ws/AddActionTest.java | 18 +---- .../notification/ws/RemoveActionTest.java | 16 ----- .../permission/ws/AddGroupActionTest.java | 42 ++++-------- .../permission/ws/AddUserActionTest.java | 17 ----- .../permission/ws/GroupsActionTest.java | 19 ------ .../permission/ws/RemoveGroupActionTest.java | 22 +----- .../permission/ws/RemoveUserActionTest.java | 17 ----- .../server/permission/ws/UsersActionTest.java | 19 ------ .../server/project/ws/DeleteActionTest.java | 12 ---- .../project/ws/UpdateKeyActionTest.java | 12 ---- .../ws/UpdateVisibilityActionTest.java | 14 ---- .../projectdump/ws/ExportActionTest.java | 16 ----- .../projectdump/ws/StatusActionTest.java | 15 +--- .../projectlink/ws/CreateActionTest.java | 15 ---- .../projectlink/ws/SearchActionTest.java | 13 ---- .../server/projecttag/ws/SetActionTest.java | 12 ---- .../qualitygate/ws/DeselectActionTest.java | 13 ---- .../ws/GetByProjectActionTest.java | 11 --- .../ws/ProjectStatusActionTest.java | 14 ---- .../qualitygate/ws/SelectActionTest.java | 15 ---- .../ws/AddProjectActionTest.java | 17 ----- .../ws/RemoveProjectActionTest.java | 18 ----- .../server/setting/ws/ResetActionTest.java | 17 ----- .../server/setting/ws/SetActionTest.java | 13 ---- .../server/setting/ws/ValuesActionTest.java | 16 ----- .../server/source/ws/IndexActionTest.java | 14 ---- .../server/source/ws/LinesActionTest.java | 13 ---- .../sonar/server/source/ws/ScmActionTest.java | 15 ---- 58 files changed, 130 insertions(+), 771 deletions(-) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java index eac29025308..4d65f853965 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java @@ -21,15 +21,11 @@ package org.sonar.ce.task.projectanalysis.analysis; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.config.Configuration; -import org.sonar.api.config.internal.Settings; import org.sonar.api.config.internal.ConfigurationBridge; +import org.sonar.api.config.internal.Settings; import org.sonar.db.DbClient; -import org.sonar.db.component.BranchType; import org.sonar.server.setting.ChildSettings; -import static org.sonar.db.component.ComponentDto.generateBranchKey; -import static org.sonar.db.component.ComponentDto.generatePullRequestKey; - @ComputeEngineSide public class ProjectConfigurationFactory { @@ -44,11 +40,8 @@ public class ProjectConfigurationFactory { public Configuration newProjectConfiguration(String projectKey, Branch branch) { Settings projectSettings = new ChildSettings(globalSettings); addSettings(projectSettings, projectKey); - if (branch.getType() == BranchType.PULL_REQUEST) { - addSettings(projectSettings, generatePullRequestKey(projectKey, branch.getPullRequestKey())); - } else { - addSettings(projectSettings, generateBranchKey(projectKey, branch.getName())); - } + // TODO branch / PR + addSettings(projectSettings, projectKey); return new ConfigurationBridge(projectSettings); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java index 18fe2164751..0f8bf052a3d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java @@ -172,7 +172,8 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { underTest.execute(new TestComputationStepContext()); - assertThat(db.countRowsOfTable("components")).isEqualTo(3); + // 3 in this branch plus the project + assertThat(db.countRowsOfTable("components")).isEqualTo(4); ComponentDto directoryDto = dbClient.componentDao().selectByKeyAndBranch(db.getSession(), "PROJECT_KEY:src/main/java/dir", "feature/foo").get(); assertThat(directoryDto.name()).isEqualTo("dir"); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index d843733d1ff..56f6bae2fd1 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -390,8 +390,7 @@ public class ComponentDao implements Dao { mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate); } - public void setPrivateForRootComponentUuid(DbSession session, String branchUuid, boolean isPrivate, - @Nullable String qualifier, String componentKey, String componentName) { + public void setPrivateForRootComponentUuid(DbSession session, String branchUuid, boolean isPrivate, @Nullable String qualifier, String componentKey, String componentName) { ComponentNewValue componentNewValue = new ComponentNewValue(branchUuid, componentName, componentKey, isPrivate, qualifier); auditPersister.updateComponentVisibility(session, componentNewValue); mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java index 0ace5776a85..4a3e4fe3844 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java @@ -119,8 +119,8 @@ public class ComponentDto { * Example: * - project P : kee=P, uuid=U1, qualifier=TRK, project_uuid=U1, main_branch_project_uuid=NULL * - file F of project P : kee=P:F, uuid=U2, qualifier=FIL, project_uuid=U1, main_branch_project_uuid=NULL - * - branch B of project P : kee=P:BRANCH:B, uuid=U3, qualifier=TRK, project_uuid=U3, main_branch_project_uuid=U1 - * - file F in branch B of project P : kee=P:F:BRANCH:B, uuid=U4, qualifier=FIL, project_uuid=U3, main_branch_project_uuid=U1 + * - branch B of project P : kee=P, uuid=U3, qualifier=TRK, project_uuid=U3, main_branch_project_uuid=U1 + * - file F in branch B of project P : kee=P:F, uuid=U4, qualifier=FIL, project_uuid=U3, main_branch_project_uuid=U1 */ @Nullable private String mainBranchProjectUuid; @@ -433,10 +433,6 @@ public class ComponentDto { return format("%s%s%s", componentKey, BRANCH_KEY_SEPARATOR, branch); } - public static String generatePullRequestKey(String componentKey, String pullRequest) { - return format("%s%s%s", componentKey, PULL_REQUEST_SEPARATOR, pullRequest); - } - public static String removeBranchAndPullRequestFromKey(String componentKey) { return substringBeforeLast(substringBeforeLast(componentKey, ComponentDto.BRANCH_KEY_SEPARATOR), ComponentDto.PULL_REQUEST_SEPARATOR); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java index 1f00114d010..ec86e389fe3 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java @@ -22,7 +22,6 @@ package org.sonar.db.component; import com.google.common.annotations.VisibleForTesting; import java.util.Collection; import java.util.List; -import java.util.Objects; import java.util.function.BiConsumer; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; @@ -72,6 +71,7 @@ public class ComponentKeyUpdaterDao implements Dao { } public void updateApplicationBranchKey(DbSession dbSession, String appBranchUuid, String appKey, String newBranchName) { + // TODO review ComponentKeyUpdaterMapper mapper = dbSession.getMapper(ComponentKeyUpdaterMapper.class); String newAppBranchKey = generateBranchKey(appKey, newBranchName); @@ -121,43 +121,8 @@ public class ComponentKeyUpdaterDao implements Dao { } } - public static final class RekeyedResource { - private final ResourceDto resource; - private final String oldKey; - - public RekeyedResource(ResourceDto resource, String oldKey) { - this.resource = resource; - this.oldKey = oldKey; - } - - public ResourceDto getResource() { - return resource; - } - - public String getOldKey() { - return oldKey; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - RekeyedResource that = (RekeyedResource) o; - return Objects.equals(resource.getUuid(), that.resource.getUuid()); - } - - @Override - public int hashCode() { - return resource.getUuid().hashCode(); - } - } - public static void checkExistentKey(ComponentKeyUpdaterMapper mapper, String resourceKey) { - if (mapper.countResourceByKey(resourceKey) > 0) { + if (mapper.countComponentsByKey(resourceKey) > 0) { throw new IllegalArgumentException("Impossible to update key: a component with key \"" + resourceKey + "\" already exists."); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java index 0aad2ceb8c0..6a67af03dc2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java @@ -24,14 +24,12 @@ import org.apache.ibatis.annotations.Param; public interface ComponentKeyUpdaterMapper { - int countResourceByKey(String key); + int countComponentsByKey(String key); ResourceDto selectProjectByUuid(@Param("uuid") String uuid); List selectProjectResources(@Param("rootUuid") String rootUuid); - List selectDescendantProjects(@Param("rootUuid") String rootUuid); - void updateComponent(ResourceDto resource); void updateProject(@Param("oldProjectKey") String oldProjectKey, @Param("newProjectKey") String newProjectKey); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java index d6b8adb6a02..824b61656dc 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java @@ -76,8 +76,8 @@ public class MeasureDao implements Dao { return session.getMapper(MeasureMapper.class); } - public List selectLastMeasureForAllProjects(DbSession session, String metricKey) { - return mapper(session).selectLastMeasureForAllProjects(metricKey); + public List selectMeasureFromLargestBranchForAllProjects(DbSession session, String metricKey) { + return mapper(session).selectMeasureFromLargestBranchForAllProjects(metricKey); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java index 9f80836c15b..5b8759b2fae 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java @@ -42,5 +42,5 @@ public interface MeasureMapper { void insert(MeasureDto measureDto); - List selectLastMeasureForAllProjects(@Param("metricKey") String metricKey); + List selectMeasureFromLargestBranchForAllProjects(@Param("metricKey") String metricKey); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java index 0029d5789d1..ecf0f8520b8 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -151,6 +151,7 @@ public class PropertiesDao implements Dao { } } + // TODO distinguish branch from project public List selectProjectProperties(DbSession session, String projectKey) { return getMapper(session).selectProjectProperties(projectKey); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml index 6a836e97aed..8112fb214dd 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml @@ -12,7 +12,7 @@ - SELECT count(1) FROM components WHERE kee = #{key,jdbcType=VARCHAR} @@ -30,14 +30,6 @@ and scope != 'PRJ' - - update components set kee = #{key,jdbcType=VARCHAR}, deprecated_kee = #{deprecatedKey,jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml index 3516f05dcda..f0664d0a558 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml @@ -81,12 +81,7 @@ from (select counter.projectUuid as projectUuid, counter.maxncloc ncloc, - max(case - when c.main_branch_project_uuid is null - then 1 - else 0 - end) as mainBranch, - min(c.kee) as component_kee, + min(br.uuid) as branchUuid, counter.projectName, counter.projectKey from @@ -102,13 +97,12 @@ group by b.project_uuid, p.name, p.kee) counter inner join live_measures lmo on lmo.value = counter.maxncloc inner join project_branches br on br.project_uuid = counter.projectUuid and br.uuid = lmo.component_uuid - inner join components c on c.uuid = br.uuid group by counter.projectUuid, counter.maxncloc, counter.projectName, counter.projectKey) tie_breaker - inner join components c2 on c2.kee = tie_breaker.component_kee - inner join project_branches pb on c2.uuid = pb.uuid + inner join project_branches pb on tie_breaker.branchUuid = pb.uuid order by ncloc desc + - select tie_breaker.projectUuid as projectUuid, s.build_date as lastAnalysis, ncloc as loc, @@ -36,12 +36,7 @@ from (select counter.projectUuid as projectUuid, counter.maxncloc ncloc, - max(case - when c.main_branch_project_uuid is null - then 1 - else 0 - end) as mainBranch, - min(c.kee) as component_kee, + min(br.uuid) as branchUuid, counter.projectName, counter.projectKey from @@ -59,8 +54,7 @@ inner join project_branches br on br.project_uuid = counter.projectUuid and br.uuid = lmo.component_uuid inner join components c on c.uuid = br.uuid group by counter.projectUuid, counter.maxncloc, counter.projectName, counter.projectKey) tie_breaker - inner join components c2 on c2.kee = tie_breaker.component_kee - inner join project_branches pb on c2.uuid = pb.uuid + inner join project_branches pb on tie_breaker.branchUuid = pb.uuid inner join project_measures pm on pb.uuid = pm.component_uuid inner join snapshots s on s.component_uuid = pb.uuid and s.islast = ${_true} inner join metrics m on m.name = #{metricKey,jdbcType=VARCHAR} and m.uuid = pm.metric_uuid diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java index 89992ed1c3f..790e937b628 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java @@ -34,7 +34,6 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.audit.AuditPersister; import org.sonar.db.audit.model.ComponentKeyNewValue; -import org.sonar.db.component.ComponentKeyUpdaterDao.RekeyedResource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -53,14 +52,14 @@ import static org.sonar.db.component.ComponentTesting.newModuleDto; import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto; public class ComponentKeyUpdaterDaoTest { - + @Rule public DbTester db = DbTester.create(System2.INSTANCE); - private AuditPersister auditPersister = mock(AuditPersister.class); - private DbClient dbClient = db.getDbClient(); - private DbSession dbSession = db.getSession(); - private ComponentKeyUpdaterDao underTest = db.getDbClient().componentKeyUpdaterDao(); - private ComponentKeyUpdaterDao underTestWithAuditPersister = new ComponentKeyUpdaterDao(auditPersister); + private final AuditPersister auditPersister = mock(AuditPersister.class); + private final DbClient dbClient = db.getDbClient(); + private final DbSession dbSession = db.getSession(); + private final ComponentKeyUpdaterDao underTest = db.getDbClient().componentKeyUpdaterDao(); + private final ComponentKeyUpdaterDao underTestWithAuditPersister = new ComponentKeyUpdaterDao(auditPersister); @Test public void updateKey_changes_the_key_of_tree_of_components() { @@ -160,26 +159,25 @@ public class ComponentKeyUpdaterDaoTest { @Test public void updateKey_updates_branches_too() { ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); + String branchKey = RandomStringUtils.randomAlphanumeric(100); + ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchKey)); db.components().insertComponent(newFileDto(branch)); db.components().insertComponent(newFileDto(branch)); - int branchComponentCount = 3; + int prComponentCount = 3; String oldProjectKey = project.getKey(); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).hasSize(1); - - String oldBranchKey = branch.getKey(); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).hasSize(branchComponentCount); + assertThat(dbClient.componentDao().selectByBranchUuid(project.uuid(), dbSession)).hasSize(1); + assertThat(dbClient.componentDao().selectByBranchUuid(branch.uuid(), dbSession)).hasSize(prComponentCount); String newProjectKey = "newKey"; - String newBranchKey = ComponentDto.generateBranchKey(newProjectKey, branch.getBranch()); underTest.updateKey(dbSession, project.uuid(), newProjectKey); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).isEmpty(); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).isEmpty(); + assertThat(dbClient.componentDao().selectByKey(dbSession, oldProjectKey)).isEmpty(); + assertThat(dbClient.componentDao().selectByKey(dbSession, newProjectKey)).isPresent(); + assertThat(dbClient.componentDao().selectByKeyAndBranch(dbSession, newProjectKey, branchKey)).isPresent(); + assertThat(dbClient.componentDao().selectByBranchUuid(project.uuid(), dbSession)).hasSize(1); + assertThat(dbClient.componentDao().selectByBranchUuid(branch.uuid(), dbSession)).hasSize(prComponentCount); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount); db.select(dbSession, "select kee from components") .forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey))); } @@ -191,31 +189,26 @@ public class ComponentKeyUpdaterDaoTest { ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey1)); db.components().insertComponent(newFileDto(pullRequest)); db.components().insertComponent(newFileDto(pullRequest)); - int branchComponentCount = 3; + int prComponentCount = 3; String oldProjectKey = project.getKey(); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).hasSize(1); - - String oldBranchKey = pullRequest.getKey(); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).hasSize(branchComponentCount); + assertThat(dbClient.componentDao().selectByBranchUuid(project.uuid(), dbSession)).hasSize(1); + assertThat(dbClient.componentDao().selectByBranchUuid(pullRequest.uuid(), dbSession)).hasSize(prComponentCount); String newProjectKey = "newKey"; - String newBranchKey = ComponentDto.generatePullRequestKey(newProjectKey, pullRequestKey1); underTest.updateKey(dbSession, project.uuid(), newProjectKey); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).isEmpty(); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).isEmpty(); + assertThat(dbClient.componentDao().selectByKey(dbSession, oldProjectKey)).isEmpty(); + assertThat(dbClient.componentDao().selectByKey(dbSession, newProjectKey)).isPresent(); + assertThat(dbClient.componentDao().selectByKeyAndPullRequest(dbSession, newProjectKey, pullRequestKey1)).isPresent(); + + assertThat(dbClient.componentDao().selectByBranchUuid(project.uuid(), dbSession)).hasSize(1); + assertThat(dbClient.componentDao().selectByBranchUuid(pullRequest.uuid(), dbSession)).hasSize(prComponentCount); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1); - assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount); db.select(dbSession, "select kee from components") .forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey))); } - private ComponentDto prefixDbKeyWithKey(ComponentDto componentDto, String key) { - return componentDto.setKey(key + ":" + componentDto.getKey()); - } - @Test public void updateKey_throws_IAE_if_component_with_specified_key_does_not_exist() { populateSomeData(); @@ -253,11 +246,6 @@ public class ComponentKeyUpdaterDaoTest { .componentKeyUpdate(any(DbSession.class), any(ComponentKeyNewValue.class), anyString()); } - - private Predicate doNotReturnAnyRekeyedResource() { - return a -> false; - } - private void populateSomeData() { ComponentDto project1 = db.components().insertPrivateProject(t -> t.setKey("org.struts:struts").setUuid("A")); ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setKey("org.struts:struts-core").setUuid("B")); 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 be729322f02..2d7c7987556 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 @@ -72,6 +72,16 @@ public class ComponentDbTester { .orElseThrow(() -> new IllegalStateException("Project has invalid configuration")); } + public ComponentDto getComponentDto(ProjectDto project) { + return db.getDbClient().componentDao().selectByUuid(dbSession, project.getUuid()) + .orElseThrow(() -> new IllegalStateException("Can't find project")); + } + + public ComponentDto getComponentDto(BranchDto branch) { + return db.getDbClient().componentDao().selectByUuid(dbSession, branch.getUuid()) + .orElseThrow(() -> new IllegalStateException("Can't find branch")); + } + public ComponentDto insertPrivateProject(ComponentDto componentDto) { return insertComponentAndBranchAndProject(componentDto, true); } @@ -143,6 +153,16 @@ public class ComponentDbTester { return getProjectDto(componentDto); } + public final ComponentDto insertFile(ProjectDto project) { + ComponentDto projectComponent = getComponentDto(project); + return insertComponent(ComponentTesting.newFileDto(projectComponent)); + } + + public final ComponentDto insertFile(BranchDto branch) { + ComponentDto projectComponent = getComponentDto(branch); + return insertComponent(ComponentTesting.newFileDto(projectComponent)); + } + public final ComponentDto insertPrivateProject(String uuid, Consumer dtoPopulator) { return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(uuid), true, defaults(), dtoPopulator); } 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 b32970caf9a..2d17a46c7b3 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 @@ -28,9 +28,6 @@ import org.sonar.db.project.ProjectDto; import static com.google.common.base.Preconditions.checkArgument; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; -import static org.sonar.db.component.BranchType.PULL_REQUEST; -import static org.sonar.db.component.ComponentDto.BRANCH_KEY_SEPARATOR; -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; @@ -217,8 +214,6 @@ public class ComponentTesting { } public static ComponentDto newBranchComponent(ProjectDto project, BranchDto branchDto) { - 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) @@ -226,8 +221,7 @@ public class ComponentTesting { .setBranchUuid(uuid) .setModuleUuidPath(UUID_PATH_SEPARATOR + uuid + UUID_PATH_SEPARATOR) .setRootUuid(uuid) - // name of the branch is not mandatory on the main branch - .setKey(branchName != null ? project.getKey() + branchSeparator + branchName : project.getKey()) + .setKey(project.getKey()) .setMainBranchProjectUuid(project.getUuid()) .setName(project.getName()) .setLongName(project.getName()) @@ -243,7 +237,6 @@ public class ComponentTesting { public static ComponentDto newBranchComponent(ComponentDto project, BranchDto branchDto) { checkArgument(project.qualifier().equals(Qualifiers.PROJECT) || project.qualifier().equals(Qualifiers.APP)); checkArgument(project.getMainBranchProjectUuid() == null); - String branchName = branchDto.getKey(); String uuid = branchDto.getUuid(); return new ComponentDto() .setUuid(uuid) diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ProjectConfigurationLoaderImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ProjectConfigurationLoaderImplTest.java index 359a03dc299..c25f8b7ea04 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ProjectConfigurationLoaderImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ProjectConfigurationLoaderImplTest.java @@ -127,6 +127,7 @@ public class ProjectConfigurationLoaderImplTest { @Test public void return_configuration_with_global_settings_main_branch_settings_and_branch_settings() { + // TODO String globalKey = randomAlphanumeric(3); String globalValue = randomAlphanumeric(4); String mainBranchDbKey = randomAlphanumeric(5); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/BranchSupportDelegate.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/BranchSupportDelegate.java index 41a57cc1cc4..dfb2fd3b3c7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/BranchSupportDelegate.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/BranchSupportDelegate.java @@ -50,6 +50,5 @@ public interface BranchSupportDelegate { * @throws IllegalArgumentException if arguments are inconsistent (such as {@code mainComponentDto} not having the same * key as {@code componentKey.getKey()}, ...) */ - ComponentDto createBranchComponent(DbSession dbSession, ComponentKey componentKey, ComponentDto mainComponentDto, - BranchDto mainComponentBranchDto); + ComponentDto createBranchComponent(DbSession dbSession, ComponentKey componentKey, ComponentDto mainComponentDto, BranchDto mainComponentBranchDto); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java index 7e42450ec13..c9aeaa86675 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java @@ -95,8 +95,11 @@ public class ReportSubmitter { ComponentDto branchComponent; if (isMainBranch(componentKey, mainBranch)) { branchComponent = mainBranchComponent; + } else if(componentKey.getBranchName().isPresent()) { + branchComponent = dbClient.componentDao().selectByKeyAndBranch(dbSession, componentKey.getKey(), componentKey.getBranchName().get()) + .orElseGet(() -> branchSupport.createBranchComponent(dbSession, componentKey, mainBranchComponent, mainBranch)); } else { - branchComponent = dbClient.componentDao().selectByKey(dbSession, componentKey.getKey()) + branchComponent = dbClient.componentDao().selectByKeyAndPullRequest(dbSession, componentKey.getKey(), componentKey.getPullRequestKey().get()) .orElseGet(() -> branchSupport.createBranchComponent(dbSession, componentKey, mainBranchComponent, mainBranch)); } 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 aecd1c82c95..dd17b32b942 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 @@ -45,7 +45,6 @@ import org.sonarqube.ws.ProjectBranches; import org.sonarqube.ws.ProjectBranches.Branch; import org.sonarqube.ws.ProjectBranches.ListWsResponse; -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.assertj.core.api.Assertions.tuple; @@ -263,19 +262,6 @@ public class ListActionTest { tuple("feature/bar", BranchType.BRANCH)); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.logIn().addProjectPermission(USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> ws.newRequest() - .setParam("project", branch.getKey()) - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getKey())); - } - @Test public void fail_if_missing_project_parameter() { assertThatThrownBy(() -> ws.newRequest().execute()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java index 5041764425e..1d3fc13e9dc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java @@ -32,6 +32,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; import org.mockito.stubbing.Answer; import org.sonar.api.utils.System2; import org.sonar.ce.queue.CeQueue; @@ -59,7 +60,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.mock; @@ -120,13 +120,12 @@ public class BranchReportSubmitterTest { @Test public void submit_a_report_on_existing_branch() { ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); + ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1")); UserDto user = db.users().insertUser(); userSession.logIn(user).addProjectPermission(SCAN_EXECUTION, project); Map randomCharacteristics = randomNonEmptyMap(); - BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(branch); - when(branchSupportDelegate.createComponentKey(project.getKey(), randomCharacteristics)) - .thenReturn(componentKey); + BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(project.getKey(), "branch1"); + when(branchSupportDelegate.createComponentKey(project.getKey(), randomCharacteristics)).thenReturn(componentKey); InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8); String taskUuid = mockSuccessfulPrepareSubmitCall(); @@ -149,11 +148,9 @@ public class BranchReportSubmitterTest { userSession.logIn(user).addProjectPermission(SCAN_EXECUTION, existingProject); Map randomCharacteristics = randomNonEmptyMap(); ComponentDto createdBranch = createButDoNotInsertBranch(existingProject); - BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch); - when(branchSupportDelegate.createComponentKey(existingProject.getKey(), randomCharacteristics)) - .thenReturn(componentKey); - when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch))) - .thenReturn(createdBranch); + BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(existingProject.getKey(), "branch1"); + when(branchSupportDelegate.createComponentKey(existingProject.getKey(), randomCharacteristics)).thenReturn(componentKey); + when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch))).thenReturn(createdBranch); InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8); String taskUuid = mockSuccessfulPrepareSubmitCall(); @@ -163,8 +160,7 @@ public class BranchReportSubmitterTest { verifyNoInteractions(favoriteUpdater); verify(branchSupport).createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch)); verify(branchSupportDelegate).createComponentKey(existingProject.getKey(), randomCharacteristics); - verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), - eq(exitingProjectMainBranch)); + verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch)); verifyNoMoreInteractions(branchSupportDelegate); verify(componentUpdater, times(0)).commitAndIndex(any(), any()); verifyQueueSubmit(existingProject, createdBranch, user, randomCharacteristics, taskUuid); @@ -180,15 +176,12 @@ public class BranchReportSubmitterTest { Map randomCharacteristics = randomNonEmptyMap(); ComponentDto createdBranch = createButDoNotInsertBranch(nonExistingProject); - BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch); - when(branchSupportDelegate.createComponentKey(nonExistingProject.getKey(), randomCharacteristics)) - .thenReturn(componentKey); + BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(nonExistingProject.getKey()); + when(branchSupportDelegate.createComponentKey(nonExistingProject.getKey(), randomCharacteristics)).thenReturn(componentKey); when(componentUpdater.createWithoutCommit(any(), any(), eq(user.getUuid()), eq(user.getLogin()), any())) .thenAnswer((Answer) invocation -> db.components().insertPrivateProject(nonExistingProject)); - when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), any())) - .thenReturn(createdBranch); - when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), any(), eq(nonExistingProject.getKey()))) - .thenReturn(true); + when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), any())).thenReturn(createdBranch); + when(permissionTemplateService.wouldUserHaveScanPermissionWithDefaultTemplate(any(DbSession.class), any(), eq(nonExistingProject.getKey()))).thenReturn(true); String taskUuid = mockSuccessfulPrepareSubmitCall(); InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8); @@ -197,8 +190,7 @@ public class BranchReportSubmitterTest { BranchDto exitingProjectMainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), nonExistingProject.uuid()).get(); verify(branchSupport).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), eq(exitingProjectMainBranch)); verify(branchSupportDelegate).createComponentKey(nonExistingProject.getKey(), randomCharacteristics); - verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), - eq(exitingProjectMainBranch)); + verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), eq(exitingProjectMainBranch)); verifyNoMoreInteractions(branchSupportDelegate); verifyQueueSubmit(nonExistingProject, createdBranch, user, randomCharacteristics, taskUuid); verify(componentUpdater).commitAndIndex(any(DbSession.class), eq(nonExistingProject)); @@ -229,12 +221,10 @@ public class BranchReportSubmitterTest { userSession.logIn(user).addProjectPermission(SCAN_EXECUTION, nonExistingProject); Map randomCharacteristics = randomNonEmptyMap(); ComponentDto createdBranch = createButDoNotInsertBranch(nonExistingProject); - BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch); + BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(nonExistingProject.getKey()); String nonExistingProjectDbKey = nonExistingProject.getKey(); - when(branchSupportDelegate.createComponentKey(nonExistingProjectDbKey, randomCharacteristics)) - .thenReturn(componentKey); - when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), any())) - .thenReturn(createdBranch); + when(branchSupportDelegate.createComponentKey(nonExistingProjectDbKey, randomCharacteristics)).thenReturn(componentKey); + when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(nonExistingProject), any())).thenReturn(createdBranch); InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8); String name = nonExistingProject.name(); @@ -256,16 +246,26 @@ public class BranchReportSubmitterTest { } private void verifyQueueSubmit(ComponentDto project, ComponentDto branch, UserDto user, Map characteristics, String taskUuid) { - verify(queue).submit(argThat(submit -> submit.getType().equals(CeTaskTypes.REPORT) - && submit.getComponent().filter(cpt -> cpt.getUuid().equals(branch.uuid()) && cpt.getMainComponentUuid().equals(project.uuid())).isPresent() - && submit.getSubmitterUuid().equals(user.getUuid()) - && submit.getCharacteristics().equals(characteristics) - && submit.getUuid().equals(taskUuid))); + ArgumentCaptor captor = ArgumentCaptor.forClass(CeTaskSubmit.class); + + verify(queue).submit(captor.capture()); + CeTaskSubmit ceTask = captor.getValue(); + assertThat(ceTask.getUuid()).isEqualTo(taskUuid); + assertThat(ceTask.getSubmitterUuid()).isEqualTo(user.getUuid()); + assertThat(ceTask.getCharacteristics()).isEqualTo(characteristics); + assertThat(ceTask.getType()).isEqualTo(CeTaskTypes.REPORT); + assertThat(ceTask.getComponent()).isPresent(); + assertThat(ceTask.getComponent().get().getUuid()).isEqualTo(branch.uuid()); + assertThat(ceTask.getComponent().get().getMainComponentUuid()).isEqualTo(project.uuid()); } - private static BranchSupport.ComponentKey createComponentKeyOfBranch(ComponentDto branch) { - BranchSupport.ComponentKey componentKey = mockComponentKey(branch.getKey()); - when(componentKey.getBranchName()).thenReturn(Optional.of(branch).map(ComponentDto::name)); + private static BranchSupport.ComponentKey createComponentKeyOfBranch(String projectKey) { + return createComponentKeyOfBranch(projectKey, randomAlphabetic(5)); + } + + private static BranchSupport.ComponentKey createComponentKeyOfBranch(String projectKey, String branchKey) { + BranchSupport.ComponentKey componentKey = mockComponentKey(projectKey); + when(componentKey.getBranchName()).thenReturn(Optional.of(branchKey)); return componentKey; } 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 db813338c1e..c4905efc0b5 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 @@ -98,17 +98,6 @@ public class ComponentFinderTest { .hasMessage(format("Component id '%s' not found", branchUuid)); } - @Test - public void fail_to_getByUuidOrKey_when_using_branch_key() { - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - - String branchDbKey = branch.getKey(); - assertThatThrownBy(() -> underTest.getByUuidOrKey(dbSession, null, branchDbKey, ID_AND_KEY)) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - @Test public void fail_when_component_uuid_is_removed() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto()); @@ -140,17 +129,6 @@ public class ComponentFinderTest { .hasMessage("Component key 'file-key' not found"); } - @Test - public void fail_getByKey_on_branch() { - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - - String branchDbKey = branch.getKey(); - assertThatThrownBy(() -> underTest.getByKey(dbSession, branchDbKey)) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branchDbKey)); - } - @Test public void get_component_by_uuid() { db.components().insertComponent(newPrivateProjectDto("project-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 61720cbfaea..487625c0e8c 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 @@ -423,19 +423,6 @@ public class ShowActionTest { .hasMessage(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch")); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - TestRequest request = ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getKey()); - assertThatThrownBy(() -> request.executeProtobuf(ShowWsResponse.class)) - .isInstanceOf(NotFoundException.class) - .hasMessage(String.format("Component key '%s' not found", branch.getKey())); - } - private ShowWsResponse newRequest(@Nullable String key) { TestRequest request = ws.newRequest(); if (key != null) { 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 3124ef11c26..b334c89bf4b 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 @@ -375,19 +375,6 @@ public class TreeActionTest { tuple(file.getKey(), pullRequestId)); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - TestRequest request = ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getKey()); - assertThatThrownBy(() -> request.executeProtobuf(Components.ShowWsResponse.class)) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_key() { ComponentDto project = db.components().insertPrivateProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java index a48bf77e94c..f55873152e7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java @@ -234,19 +234,6 @@ public class ShowActionTest { .hasMessage("The 'key' parameter is missing"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - TestRequest request = ws.newRequest() - .setParam("key", branch.getKey()); - - assertThatThrownBy(request::execute) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - private TestRequest newBaseRequest() { return ws.newRequest(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java index a23e1c3e420..18031ce640d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java @@ -110,18 +110,6 @@ public class AddActionTest { .isInstanceOf(UnauthorizedException.class); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - UserDto user = db.users().insertUser(); - userSession.logIn(user).addProjectPermission(USER, project); - - assertThatThrownBy(() -> call(branch.getKey())) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - @Test public void fail_on_directory() { ComponentDto project = db.components().insertPrivateProject(); 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 acd829d61c5..a5228b2add3 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 @@ -694,25 +694,6 @@ public class SearchActionComponentsTest { .doesNotContain(branchIssue.getKey()); } - @Test - public void does_not_return_branch_issues_when_using_db_key() { - RuleDto rule = db.rules().insertIssueRule(); - ComponentDto project = db.components().insertPrivateProject(); - ComponentDto projectFile = db.components().insertComponent(newFileDto(project)); - IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile); - ComponentDto branch = db.components().insertProjectBranch(project); - ComponentDto branchFile = db.components().insertComponent(newFileDto(branch)); - IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile); - allowAnyoneOnProjects(project); - indexIssues(); - - SearchWsResponse result = ws.newRequest() - .setParam(PARAM_COMPONENT_KEYS, branch.getKey()) - .executeProtobuf(SearchWsResponse.class); - - assertThat(result.getIssuesList()).isEmpty(); - } - private void allowAnyoneOnProjects(ComponentDto... projects) { userSession.registerComponents(projects); Arrays.stream(projects).forEach(p -> permissionIndexer.allowOnlyAnyone(p)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index fd08abd57be..54fb534fbf8 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -99,7 +99,6 @@ import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.api.utils.DateUtils.parseDate; import static org.sonar.api.utils.DateUtils.parseDateTime; import static org.sonar.api.web.UserRole.ISSUE_ADMIN; -import static org.sonar.db.component.ComponentDto.PULL_REQUEST_SEPARATOR; import static org.sonar.db.component.ComponentTesting.newFileDto; import static org.sonar.db.issue.IssueTesting.newDto; import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection; @@ -748,7 +747,7 @@ public class SearchActionTest { ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey("pr")); SnapshotDto snapshotDto = db.components().insertSnapshot(pr); indexPermissions(); - ComponentDto file = db.components().insertComponent(newFileDto(pr, null, "FILE_ID").setKey("FILE_KEY" + PULL_REQUEST_SEPARATOR + "pr")); + ComponentDto file = db.components().insertComponent(newFileDto(pr, null, "FILE_ID").setKey("FILE_KEY")); RuleDto rule = newIssueRule(); IssueDto issue1 = newDto(rule, file, pr) .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100")) 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 9900dcf7bc2..3f65a751b79 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 @@ -42,7 +42,6 @@ import org.sonarqube.ws.Measures.Component; import org.sonarqube.ws.Measures.ComponentWsResponse; import static java.lang.Double.parseDouble; -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.assertj.core.api.Assertions.tuple; @@ -377,23 +376,6 @@ public class ComponentActionTest { .hasMessage(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch")); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.logIn().addProjectPermission(USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); - - assertThatThrownBy(() -> { - ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getKey()) - .setParam(PARAM_METRIC_KEYS, metric.getKey()) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - @Test public void json_example() { ComponentDto project = db.components().insertPrivateProject(); 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 0afae7b792c..7f4738caae0 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 @@ -1025,23 +1025,6 @@ public class ComponentTreeActionTest { .hasMessage(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch")); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.logIn().addProjectPermission(USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - insertNclocMetric(); - - assertThatThrownBy(() -> { - ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getKey()) - .setParam(PARAM_METRIC_KEYS, "ncloc") - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - private static MetricDto newMetricDto() { return MetricTesting.newMetricDto() .setWorstValue(null) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java index 3d17e12fe0c..84a1c91f8a5 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java @@ -50,7 +50,6 @@ import org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryMeasure; import org.sonarqube.ws.Measures.SearchHistoryResponse.HistoryValue; import static java.lang.Double.parseDouble; -import static java.lang.String.format; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static java.util.Optional.ofNullable; @@ -338,20 +337,6 @@ public class SearchHistoryActionTest { .containsExactlyInAnyOrder(measure.getValue()); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.logIn().addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> ws.newRequest() - .setParam(PARAM_COMPONENT, branch.getKey()) - .setParam(PARAM_METRICS, "ncloc") - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); - } - @Test public void fail_if_unknown_metric() { SearchHistoryRequest request = SearchHistoryRequest.builder() @@ -419,8 +404,8 @@ public class SearchHistoryActionTest { .setParam(PARAM_COMPONENT, "file-key") .setParam(PARAM_METRICS, "ncloc") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("Component key 'file-key' not found"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("Component key 'file-key' not found"); } @Test @@ -435,8 +420,8 @@ public class SearchHistoryActionTest { .setParam(PARAM_BRANCH, "another_branch") .setParam(PARAM_METRICS, "ncloc") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch")); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch")); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java index 36d5097c81d..05cc511c98d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java @@ -39,7 +39,6 @@ import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.TestResponse; import org.sonar.server.ws.WsActionTester; -import static java.lang.String.format; import static java.net.HttpURLConnection.HTTP_NO_CONTENT; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; @@ -75,8 +74,8 @@ public class AddActionTest { private Dispatchers dispatchers = mock(Dispatchers.class); private WsActionTester ws = new WsActionTester(new AddAction(new NotificationCenter( - new NotificationDispatcherMetadata[]{}, - new NotificationChannel[]{emailChannel, twitterChannel, defaultChannel}), + new NotificationDispatcherMetadata[] {}, + new NotificationChannel[] {emailChannel, twitterChannel, defaultChannel}), new NotificationUpdater(dbClient), dispatchers, dbClient, TestComponentFinder.from(db), userSession)); @Test @@ -313,19 +312,6 @@ public class AddActionTest { .isInstanceOf(UnauthorizedException.class); } - @Test - public void fail_when_using_branch_db_key() { - UserDto user = db.users().insertUser(); - userSession.logIn(user); - when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, branch.getKey(), null)) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); - } - @Test public void fail_when_user_does_not_have_USER_permission_on_private_project() { ComponentDto project = db.components().insertPrivateProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java index a72bfe25c13..a04c4da3a09 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java @@ -40,7 +40,6 @@ import org.sonar.server.ws.TestRequest; import org.sonar.server.ws.TestResponse; import org.sonar.server.ws.WsActionTester; -import static java.lang.String.format; import static java.net.HttpURLConnection.HTTP_NO_CONTENT; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; @@ -301,21 +300,6 @@ public class RemoveActionTest { .isInstanceOf(UnauthorizedException.class); } - @Test - public void fail_when_using_branch_db_key() { - UserDto user = db.users().insertUser(); - userSession.logIn(user); - when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - - RemoveRequest request = this.request.setProject(branch.getKey()); - assertThatThrownBy(() -> call(request)) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - private TestResponse call(RemoveRequest remove) { TestRequest request = ws.newRequest(); request.setParam(PARAM_TYPE, remove.getType()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java index 90f0663cd23..8347b209489 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java @@ -176,7 +176,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { GroupDto group = db.users().insertGroup("sonar-administrators"); loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PROJECT_ID, "not-found") @@ -222,7 +222,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { GroupDto group = db.users().insertGroup("sonar-administrators"); loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PROJECT_ID, file.uuid()) @@ -238,7 +238,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { GroupDto group = db.users().insertGroup("sonar-administrators"); loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { executeRequest(group, UserRole.ISSUE_ADMIN); }) .isInstanceOf(BadRequestException.class); @@ -251,7 +251,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project, null, "file-uuid")); loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PROJECT_ID, file.uuid()) @@ -265,7 +265,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { public void fail_when_get_request() { loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setMethod("GET") .setParam(PARAM_GROUP_NAME, "sonar-administrators") @@ -279,7 +279,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { public void fail_when_group_name_and_group_id_are_missing() { loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) .execute(); @@ -293,7 +293,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { GroupDto group = db.users().insertGroup("sonar-administrators"); loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .execute(); @@ -306,7 +306,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { GroupDto group = db.users().insertGroup(); loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .execute(); @@ -320,7 +320,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { ComponentDto project = db.components().insertPrivateProject(); loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) @@ -337,7 +337,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { GroupDto group = db.users().insertGroup("sonar-administrators"); userSession.logIn().addPermission(SCAN); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey()) @@ -352,7 +352,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { ComponentDto project = db.components().insertPrivateProject(); userSession.logIn(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey()) @@ -458,24 +458,6 @@ public class AddGroupActionTest extends BasePermissionWsTest { assertThat(db.users().selectAnyonePermissions(project)).isEmpty(); } - @Test - public void fail_when_using_branch_db_key() { - GroupDto group = db.users().insertGroup(); - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> { - newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getKey()) - .setParam(PARAM_GROUP_NAME, group.getName()) - .setParam(PARAM_PERMISSION, ISSUE_ADMIN) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_uuid() { GroupDto group = db.users().insertGroup(); @@ -483,7 +465,7 @@ public class AddGroupActionTest extends BasePermissionWsTest { userSession.logIn().addProjectPermission(UserRole.ADMIN, project); ComponentDto branch = db.components().insertProjectBranch(project); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_PROJECT_ID, branch.uuid()) .setParam(PARAM_GROUP_NAME, group.getName()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java index e0d541afbe4..589c75cd621 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java @@ -347,23 +347,6 @@ public class AddUserActionTest extends BasePermissionWsTest { assertThat(db.users().selectAnyonePermissions(project)).isEmpty(); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> { - newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getKey()) - .setParam(PARAM_USER_LOGIN, user.getLogin()) - .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_uuid() { ComponentDto project = db.components().insertPublicProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java index d3dc23d714b..d8c3a5c1303 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java @@ -329,23 +329,4 @@ public class GroupsActionTest extends BasePermissionWsTest { .isInstanceOf(NotFoundException.class) .hasMessage(format("Project id '%s' not found", branch.uuid())); } - - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - GroupDto group = db.users().insertGroup(); - db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project); - loginAsAdmin(); - - assertThatThrownBy(() -> { - newRequest() - .setParam(PARAM_PERMISSION, ISSUE_ADMIN) - .setParam(PARAM_PROJECT_KEY, branch.getKey()) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getKey())); - } - } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java index 8ffaf36bcfd..2239f0e930b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java @@ -175,7 +175,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest { + assertThatThrownBy(() -> { executeRequest(aGroup, SYSTEM_ADMIN); }) .isInstanceOf(BadRequestException.class) @@ -186,7 +186,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, aGroup.getName()) .setParam(PARAM_PROJECT_ID, "unknown-project-uuid") @@ -448,24 +448,6 @@ public class RemoveGroupActionTest extends BasePermissionWsTest { - newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getKey()) - .setParam(PARAM_GROUP_NAME, group.getName()) - .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_uuid() { GroupDto group = db.users().insertGroup(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java index edefb4dd756..29bb0d491d7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java @@ -396,23 +396,6 @@ public class RemoveUserActionTest extends BasePermissionWsTest .hasMessage("Permission codeviewer can't be removed from a public component"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> { - newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getKey()) - .setParam(PARAM_USER_LOGIN, user.getLogin()) - .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_uuid() { ComponentDto project = db.components().insertPublicProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java index c562e222e7d..0f265ed1103 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java @@ -326,25 +326,6 @@ public class UsersActionTest extends BasePermissionWsTest { .hasMessage("'q' length (2) is shorter than the minimum authorized (3)"); } - @Test - public void fail_when_using_branch_db_key() throws Exception { - UserDto user = db.users().insertUser(newUserDto()); - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - - assertThatThrownBy(() -> { - newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getKey()) - .setParam(PARAM_USER_LOGIN, user.getLogin()) - .setParam(PARAM_PERMISSION, SYSTEM_ADMIN) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project key '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_uuid() { UserDto user = db.users().insertUser(newUserDto()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java index 0d4e3e61136..992f5d13b0e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java @@ -172,18 +172,6 @@ public class DeleteActionTest { .isInstanceOf(UnauthorizedException.class); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSessionRule.logIn().addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - TestRequest request = tester.newRequest().setParam(PARAM_PROJECT, branch.getKey()); - assertThatThrownBy(() -> call(request)) - .isInstanceOf(NotFoundException.class) - .hasMessage(String.format("Project '%s' not found", branch.getKey())); - } - private String verifyDeletedKey() { ArgumentCaptor argument = ArgumentCaptor.forClass(ProjectDto.class); verify(componentCleanerService).delete(any(DbSession.class), argument.capture()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java index cc2434b9072..92ec2675f41 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java @@ -105,18 +105,6 @@ public class UpdateKeyActionTest { .isInstanceOf(NotFoundException.class); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - userSessionRule.addProjectPermission(UserRole.ADMIN, project); - - String branchDbKey = branch.getKey(); - assertThatThrownBy(() -> call(branchDbKey, ANOTHER_KEY)) - .isInstanceOf(NotFoundException.class) - .hasMessage(String.format("Project '%s' not found", branchDbKey)); - } - @Test public void api_definition() { WebService.Action definition = ws.getDef(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java index 3c7274a0f03..512361963e6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java @@ -244,7 +244,6 @@ public class UpdateVisibilityActionTest { .hasMessage("Insufficient privileges"); } - @Test public void execute_throws_ForbiddenException_if_user_has_ADMIN_permission_but_sonar_allowPermissionManagementForProjectAdmins_is_set_to_false() { when(configuration.getBoolean(CORE_ALLOW_PERMISSION_MANAGEMENT_FOR_PROJECT_ADMINS_PROPERTY)).thenReturn(of(false)); @@ -577,19 +576,6 @@ public class UpdateVisibilityActionTest { .containsOnly(UserRole.ADMIN); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = dbTester.components().insertPrivateProject(); - userSessionRule.logIn().addProjectPermission(UserRole.USER, project); - ComponentDto branch = dbTester.components().insertProjectBranch(project); - - TestRequest request = this.request.setParam(PARAM_PROJECT, branch.getKey()) - .setParam(PARAM_VISIBILITY, PUBLIC); - assertThatThrownBy(request::execute) - .isInstanceOf(NotFoundException.class) - .hasMessage(String.format("Component key '%s' not found", branch.getKey())); - } - private void unsafeGiveAllPermissionsToRootComponent(ComponentDto component, UserDto user, GroupDto group) { Arrays.stream(GlobalPermission.values()) .forEach(globalPermission -> { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java index 231955fd595..c70f5026e17 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java @@ -33,7 +33,6 @@ import org.sonar.db.user.UserDto; import org.sonar.server.ce.projectdump.ExportSubmitter; import org.sonar.server.component.ComponentFinder; import org.sonar.server.exceptions.ForbiddenException; -import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestResponse; import org.sonar.server.ws.WsActionTester; @@ -122,21 +121,6 @@ public class ExportActionTest { assertJson(response.getInput()).isSimilarTo(responseExample()); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - - assertThatThrownBy(() -> { - actionTester.newRequest() - .setMethod("POST") - .setParam("key", branch.getKey()) - .execute(); - }) - .isInstanceOf(NotFoundException.class); - } - private void logInAsProjectAdministrator(String login) { userSession.logIn(login).addProjectPermission(UserRole.ADMIN, project); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java index 6956e15b1db..3cd9078b38b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java @@ -74,7 +74,7 @@ public class StatusActionTest { private final static String projectDumpsDirectoryPathname = "data/governance/project_dumps/"; private final static String importDirectoryPathname = Paths.get(projectDumpsDirectoryPathname, "import").toString(); - private final static String exportDirectoryPathname = Paths.get(projectDumpsDirectoryPathname,"export").toString(); + private final static String exportDirectoryPathname = Paths.get(projectDumpsDirectoryPathname, "export").toString(); private ProjectDto project; @@ -277,19 +277,6 @@ public class StatusActionTest { .doesNotContain("dumpToImport"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> { - underTest.newRequest() - .setParam(KEY_PARAM, branch.getKey()) - .execute(); - }) - .isInstanceOf(NotFoundException.class); - } - @Test public void fail_when_using_branch_id() { ComponentDto project = db.components().insertPublicProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java index b222f8cb501..0c70ad57d2f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java @@ -215,21 +215,6 @@ public class CreateActionTest { } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.logIn().addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> ws.newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getKey()) - .setParam(PARAM_NAME, "Custom") - .setParam(PARAM_URL, "http://example.org") - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_db_uuid() { ComponentDto project = db.components().insertPrivateProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java index 892c5f30d8a..f8c4195d420 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java @@ -236,19 +236,6 @@ public class SearchActionTest { .isInstanceOf(IllegalArgumentException.class); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.logIn().addProjectPermission(USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> ws.newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getKey()) - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_db_uuid() { ComponentDto project = db.components().insertPrivateProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java index f252d53598c..a9666ea7d28 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java @@ -183,18 +183,6 @@ public class SetActionTest { .hasMessage("Project 'FILE_KEY' not found"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.logIn().addProjectPermission(USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - String branchDbKey = branch.getKey(); - assertThatThrownBy(() -> call(branchDbKey, "secret")) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project '%s' not found", branchDbKey)); - } - @Test public void definition() { WebService.Action definition = ws.getDef(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java index 04c2565c6fc..66bffc649be 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java @@ -160,19 +160,6 @@ public class DeselectActionTest { .isInstanceOf(ForbiddenException.class); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> ws.newRequest() - .setParam("projectKey", branch.getKey()) - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getKey())); - } - @Test public void definition() { WebService.Action def = ws.getDef(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java index 1b5e676ac90..03984cd1295 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java @@ -191,17 +191,6 @@ public class GetByProjectActionTest { .hasMessageContaining("The 'project' parameter is missing"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> ws.newRequest().setParam("project", branch.getKey()).execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getKey())); - } - private void logInAsProjectUser(ProjectDto project) { userSession.logIn().addProjectPermission(UserRole.USER, project); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java index f3a8d13fe36..d3bb4ac62f4 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java @@ -401,20 +401,6 @@ public class ProjectStatusActionTest { .hasMessageContaining("Either 'analysisId', 'projectId' or 'projectKey' must be provided"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - SnapshotDto snapshot = db.components().insertSnapshot(branch); - - assertThatThrownBy(() -> ws.newRequest() - .setParam(PARAM_PROJECT_KEY, branch.getKey()) - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_uuid() { ComponentDto project = db.components().insertPublicProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java index f29daa0519a..833dfeedaac 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java @@ -198,21 +198,6 @@ public class SelectActionTest { .isInstanceOf(ForbiddenException.class); } - @Test - public void fail_when_using_branch_db_key() { - QualityGateDto qualityGate = db.qualityGates().insertQualityGate(); - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> ws.newRequest() - .setParam("gateId", qualityGate.getUuid()) - .setParam("projectKey", branch.getKey()) - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Project '%s' not found", branch.getKey())); - } - private void assertSelected(QualityGateDto qualityGate, ComponentDto project) { Optional qGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid()); assertThat(qGateUuid) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java index 89e3fd257c2..9e077b84b8d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java @@ -208,23 +208,6 @@ public class AddProjectActionTest { .hasMessage("Quality Profile for language 'xoo' and name 'unknown' does not exist"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn(db.users().insertUser()).addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - QProfileDto profile = db.qualityProfiles().insert(); - - assertThatThrownBy(() -> { - tester.newRequest() - .setParam("project", branch.getKey()) - .setParam("profileKey", profile.getKee()) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project '%s' not found", branch.getKey())); - } - private void assertProjectIsAssociatedToProfile(ProjectDto project, QProfileDto profile) { QProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage()); assertThat(loaded.getKee()).isEqualTo(profile.getKee()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java index 8ee6be6c799..bdee1349221 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java @@ -214,24 +214,6 @@ public class RemoveProjectActionTest { .hasMessage("Quality Profile for language 'xoo' and name 'unknown' does not exist"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - QProfileDto profile = db.qualityProfiles().insert(); - - assertThatThrownBy(() -> { - ws.newRequest() - .setParam("project", branch.getKey()) - .setParam("language", profile.getLanguage()) - .setParam("qualityProfile", profile.getName()) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Project '%s' not found", branch.getKey())); - } - private void assertProjectIsAssociatedToProfile(ProjectDto project, QProfileDto profile) { QProfileDto loaded = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(db.getSession(), project, profile.getLanguage()); assertThat(loaded.getKee()).isEqualTo(profile.getKee()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java index bfd3ba794f8..07654489d7c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java @@ -366,23 +366,6 @@ public class ResetActionTest { failForPropertyWithoutDefinitionOnUnsupportedComponent(view, projectCopy); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - definitions.addComponent(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build()); - - assertThatThrownBy(() -> { - ws.newRequest() - .setParam("keys", "foo") - .setParam("component", branch.getKey()) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - @Test public void fail_when_component_not_found() { assertThatThrownBy(() -> { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java index 59e1e725091..3588b546471 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java @@ -1160,19 +1160,6 @@ public class SetActionTest { .hasMessage("Setting 'my.key' cannot be set on a Project"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPublicProject(); - userSession.logIn().addProjectPermission(UserRole.ADMIN, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> { - callForProjectSettingByKey("my.key", "My Value", branch.getKey()); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - @Test public void fail_when_component_not_found() { assertThatThrownBy(() -> { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java index 20703ac513a..e6b399e4295 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java @@ -819,22 +819,6 @@ public class ValuesActionTest { JsonAssert.assertJson(newTester().getDef().responseExampleAsString()).isSimilarTo(result); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - userSession.logIn().addProjectPermission(UserRole.USER, project); - ComponentDto branch = db.components().insertProjectBranch(project); - - assertThatThrownBy(() -> { - newTester().newRequest() - .setParam("keys", "foo") - .setParam("component", branch.getKey()) - .execute(); - }) - .isInstanceOf(NotFoundException.class) - .hasMessage(format("Component key '%s' not found", branch.getKey())); - } - @Test public void fail_when_setting_key_is_defined_in_sonar_properties() { ComponentDto project = db.components().insertPrivateProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IndexActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IndexActionTest.java index 66c679194eb..301b1a623eb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IndexActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IndexActionTest.java @@ -36,7 +36,6 @@ import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.TestResponse; import org.sonar.server.ws.WsActionTester; -import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.sonar.api.web.UserRole.CODEVIEWER; import static org.sonar.api.web.UserRole.USER; @@ -113,19 +112,6 @@ public class IndexActionTest { .isInstanceOf(NotFoundException.class); } - @Test - public void fail_when_using_branch_db_key() throws Exception { - ComponentDto project = db.components().insertPrivateProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - userSession.addProjectPermission(USER, project); - - assertThatThrownBy(() -> tester.newRequest() - .setParam("resource", branch.getKey()) - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); - } - private static DbFileSources.Data newData(String... lines) { DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder(); for (int i = 1; i <= lines.length; i++) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java index 1272acfd8cf..a4982ca69e0 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java @@ -329,19 +329,6 @@ public class LinesActionTest { .hasMessageContaining("Parameter 'uuid' cannot be used at the same time as 'branch' or 'pullRequest'"); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = db.components().insertPrivateProject(); - ComponentDto branch = db.components().insertProjectBranch(project); - userSession.addProjectPermission(UserRole.USER, project); - - assertThatThrownBy(() -> tester.newRequest() - .setParam("key", branch.getKey()) - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); - } - @Test public void fail_when_using_branch_uuid() { ComponentDto project = db.components().insertPrivateProject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java index 94f61d8448a..b74d2b340d1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java @@ -36,13 +36,11 @@ import org.sonar.db.protobuf.DbFileSources; import org.sonar.db.source.FileSourceDto; import org.sonar.server.component.TestComponentFinder; import org.sonar.server.exceptions.ForbiddenException; -import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.source.HtmlSourceDecorator; import org.sonar.server.source.SourceService; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsActionTester; -import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThatThrownBy; public class ScmActionTest { @@ -215,19 +213,6 @@ public class ScmActionTest { .isInstanceOf(ForbiddenException.class); } - @Test - public void fail_when_using_branch_db_key() { - ComponentDto project = dbTester.components().insertPrivateProject(); - ComponentDto branch = dbTester.components().insertProjectBranch(project); - userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); - - assertThatThrownBy(() -> tester.newRequest() - .setParam("key", branch.getKey()) - .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining(format("Component key '%s' not found", branch.getKey())); - } - private DbFileSources.Line newSourceLine(String author, String revision, Date date, int line) { return DbFileSources.Line.newBuilder() .setScmAuthor(author) -- 2.39.5