From: Julien Lancelot Date: Thu, 29 Mar 2018 08:58:26 +0000 (+0200) Subject: Adding UT checking it's not possible to use branch key in bulk_update_key X-Git-Tag: 7.5~1419 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=941cdf85a80bdf1049a6e3a2dfaa0690969a5e45;p=sonarqube.git Adding UT checking it's not possible to use branch key in bulk_update_key --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java index a1e6d94c628..333f6ad0ab0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java @@ -63,16 +63,6 @@ public class ComponentFinder { return getByKey(dbSession, checkParamNotEmpty(componentKey, parameterNames.getKeyParam())); } - public ComponentDto getRootComponentByUuidOrKey(DbSession dbSession, @Nullable String componentUuid, @Nullable String componentKey, ParamNames parameterNames) { - checkByUuidOrKey(componentUuid, componentKey, parameterNames); - - if (componentUuid != null) { - return checkIsProject(getByUuid(dbSession, checkParamNotEmpty(componentUuid, parameterNames.getUuidParam()), LABEL_PROJECT)); - } - - return checkIsProject(getByKey(dbSession, checkParamNotEmpty(componentKey, parameterNames.getKeyParam()), LABEL_PROJECT)); - } - private static String checkParamNotEmpty(String value, String param) { checkArgument(!value.isEmpty(), MSG_PARAMETER_MUST_NOT_BE_EMPTY, param); return value; diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java index 353e0097ed6..871980caf4a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java @@ -20,7 +20,6 @@ package org.sonar.server.project.ws; import javax.annotation.Nullable; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -75,7 +74,7 @@ public class BulkUpdateKeyActionTest { @Rule public ExpectedException expectedException = ExpectedException.none(); @Rule - public UserSessionRule userSession = UserSessionRule.standalone(); + public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot(); @Rule public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings().asConfig()), new ComponentIndexDefinition(new MapSettings().asConfig())); @@ -89,11 +88,6 @@ public class BulkUpdateKeyActionTest { private WsActionTester ws = new WsActionTester( new BulkUpdateKeyAction(dbClient, componentFinder, componentService, userSession)); - @Before - public void setUp() { - userSession.logIn().setRoot(); - } - @Test public void json_example() { OrganizationDto organizationDto = db.organizations().insert(); @@ -153,6 +147,30 @@ public class BulkUpdateKeyActionTest { verify(componentService).bulkUpdateKey(any(DbSession.class), eq(provisionedProject), eq(provisionedProject.getDbKey()), eq(newKey)); } + @Test + public void fail_to_bulk_update_key_using_branch_db_key() { + ComponentDto project = db.components().insertMainBranch(); + ComponentDto branch = db.components().insertProjectBranch(project); + userSession.addProjectPermission(UserRole.USER, project); + + expectedException.expect(NotFoundException.class); + expectedException.expectMessage(String.format("Component key '%s' not found", branch.getDbKey())); + + callByKey(branch.getDbKey(), FROM, TO); + } + + @Test + public void fail_to_bulk_update_key_using_branch_uuid() { + ComponentDto project = db.components().insertMainBranch(); + ComponentDto branch = db.components().insertProjectBranch(project); + userSession.addProjectPermission(UserRole.USER, project); + + expectedException.expect(NotFoundException.class); + expectedException.expectMessage(String.format("Component id '%s' not found", branch.uuid())); + + callByUuid(branch.uuid(), FROM, TO); + } + @Test public void fail_to_bulk_if_a_component_already_exists_with_the_same_key() { componentDb.insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("my_project"));