]> source.dussan.org Git - sonarqube.git/commitdiff
Adding UT checking it's not possible to use branch key in bulk_update_key
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 29 Mar 2018 08:58:26 +0000 (10:58 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Wed, 4 Apr 2018 12:40:51 +0000 (14:40 +0200)
server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkUpdateKeyActionTest.java

index a1e6d94c6289a6742911bf5546646f8173ccb6fd..333f6ad0ab0d35a0dfb33efd10962af66f4f4525 100644 (file)
@@ -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;
index 353e0097ed6186b9f393db8fbe6cfac91c2fe3c3..871980caf4afeecec2d6db1f0834fd52dc7f4c89 100644 (file)
@@ -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"));