diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2022-09-28 10:31:10 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-12 20:03:44 +0000 |
commit | ebc870fa3d67138d8a45a152cd5d024395b9ad2f (patch) | |
tree | 1c1370d7dc20561e5b90fbe73325c806f74f82b7 /server/sonar-webserver-webapi | |
parent | d9a12fc4c11a83195e121041390181aab142960a (diff) | |
download | sonarqube-ebc870fa3d67138d8a45a152cd5d024395b9ad2f.tar.gz sonarqube-ebc870fa3d67138d8a45a152cd5d024395b9ad2f.zip |
SONAR-17352 Refactor component keys to not include branch suffix
Diffstat (limited to 'server/sonar-webserver-webapi')
42 files changed, 61 insertions, 637 deletions
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; @@ -264,19 +263,6 @@ public class ListActionTest { } @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()) .isInstanceOf(IllegalArgumentException.class) 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<String, String> 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<String, String> 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<String, String> 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<ComponentDto>) 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<String, String> 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<String, String> 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<CeTaskSubmit> 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 @@ -99,17 +99,6 @@ public class ComponentFinderTest { } @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()); db.components().insertComponent(newFileDto(project, null, "file-uuid").setEnabled(false)); @@ -141,17 +130,6 @@ public class ComponentFinderTest { } @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 @@ -376,19 +376,6 @@ public class TreeActionTest { } @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(); userSession.addProjectPermission(UserRole.USER, project); 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 @@ -111,18 +111,6 @@ public class AddActionTest { } @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(); ComponentDto directory = db.components().insertComponent(newDirectory(project, "dir")); 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; @@ -378,23 +377,6 @@ public class ComponentActionTest { } @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(); userSession.addProjectPermission(USER, project); 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; @@ -339,20 +338,6 @@ public class SearchHistoryActionTest { } @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() .setComponent(project.getKey()) @@ -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 @@ -314,19 +313,6 @@ public class AddActionTest { } @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(); userSession.logIn().setNonSystemAdministrator(); 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<AddGroupAction> { 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<AddGroupAction> { 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<AddGroupAction> { 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<AddGroupAction> { 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<AddGroupAction> { 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<AddGroupAction> { 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<AddGroupAction> { 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<AddGroupAction> { 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<AddGroupAction> { 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<AddGroupAction> { 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<AddGroupAction> { ComponentDto project = db.components().insertPrivateProject(); userSession.logIn(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, group.getName()) .setParam(PARAM_PERMISSION, PROVISION_PROJECTS.getKey()) @@ -459,31 +459,13 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { } @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(); ComponentDto project = db.components().insertPublicProject(); 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 @@ -348,23 +348,6 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> { } @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(); userSession.logIn().addProjectPermission(UserRole.ADMIN, project); 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<GroupsAction> { .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<RemoveGroupActio db.users().insertPermissionOnGroup(aGroup, PROVISION_PROJECTS); loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { executeRequest(aGroup, SYSTEM_ADMIN); }) .isInstanceOf(BadRequestException.class) @@ -186,7 +186,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio public void fail_when_project_does_not_exist() { loginAsAdmin(); - assertThatThrownBy(() -> { + assertThatThrownBy(() -> { newRequest() .setParam(PARAM_GROUP_NAME, aGroup.getName()) .setParam(PARAM_PROJECT_ID, "unknown-project-uuid") @@ -449,24 +449,6 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio } @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, 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(); ComponentDto project = db.components().insertPublicProject(); 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 @@ -397,23 +397,6 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> } @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(); userSession.logIn().addProjectPermission(UserRole.ADMIN, project); 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 @@ -327,25 +327,6 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> { } @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()); ComponentDto project = db.components().insertPublicProject(); 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<ProjectDto> 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 @@ -106,18 +106,6 @@ public class UpdateKeyActionTest { } @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; @@ -278,19 +278,6 @@ public class StatusActionTest { } @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(); ComponentDto branch = db.components().insertProjectBranch(project); 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 @@ -216,21 +216,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(); userSession.logIn().addProjectPermission(UserRole.USER, project); 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 @@ -237,19 +237,6 @@ public class SearchActionTest { } @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(); userSession.logIn().addProjectPermission(USER, project); 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 @@ -184,18 +184,6 @@ public class SetActionTest { } @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 @@ -161,19 +161,6 @@ public class DeselectActionTest { } @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 @@ -402,20 +402,6 @@ public class ProjectStatusActionTest { } @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(); userSession.logIn().addProjectPermission(UserRole.ADMIN, project); 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<String> 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 @@ -367,23 +367,6 @@ public class ResetActionTest { } @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(() -> { ws.newRequest() 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 @@ -1161,19 +1161,6 @@ public class SetActionTest { } @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(() -> { ws.newRequest() 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 @@ -820,22 +820,6 @@ public class ValuesActionTest { } @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(); userSession.logIn().addProjectPermission(UserRole.USER, project); 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 @@ -330,19 +330,6 @@ public class LinesActionTest { } @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(); ComponentDto branch = db.components().insertProjectBranch(project); 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) |