]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17352 Refactor component keys to not include branch suffix
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 28 Sep 2022 15:31:10 +0000 (10:31 -0500)
committersonartech <sonartech@sonarsource.com>
Wed, 12 Oct 2022 20:03:44 +0000 (20:03 +0000)
58 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactory.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/measure/MeasureMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentKeyUpdaterMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/measure/LiveMeasureMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
server/sonar-server-common/src/test/java/org/sonar/server/setting/ProjectConfigurationLoaderImplTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/BranchSupportDelegate.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/ce/queue/BranchReportSubmitterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/duplication/ws/ShowActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/favorite/ws/AddActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchHistoryActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/AddActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/RemoveActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddGroupActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/AddUserActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/GroupsActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveGroupActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/RemoveUserActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/permission/ws/UsersActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/project/ws/UpdateVisibilityActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/ExportActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectdump/ws/StatusActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/CreateActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectlink/ws/SearchActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/projecttag/ws/SetActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeselectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/AddProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/ws/RemoveProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/IndexActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/LinesActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/source/ws/ScmActionTest.java

index eac29025308edde940884672430a857c2ff9457e..4d65f85396515eb2053c8a3b4cc34375a5b60611 100644 (file)
@@ -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);
   }
 
index 18fe21647511c1e8dc47babadbeee17aeba9a831..0f8bf052a3d05c8605a13133e881cf34662b879e 100644 (file)
@@ -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");
index d843733d1ffa129eb21ab1e1fe4a9347565aaf47..56f6bae2fd14e9a4a82cc6c9de1441a6374ec8f8 100644 (file)
@@ -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);
index 0ace5776a854e1661a1d0122097db409f4a067ac..4a3e4fe38448f1cf749c683b2b85887fa36f5619 100644 (file)
@@ -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);
   }
index 1f00114d010da7994a5cb07a72d3372340620707..ec86e389fe3bfb15e362bbac4330f156bd3aa5fc 100644 (file)
@@ -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.");
     }
   }
index 0aad2ceb8c04cae838b2d22e2b896088ceaa0f23..6a67af03dc27d8840e475e1b4c2d0316e9401133 100644 (file)
@@ -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<ResourceDto> selectProjectResources(@Param("rootUuid") String rootUuid);
 
-  List<ResourceDto> selectDescendantProjects(@Param("rootUuid") String rootUuid);
-
   void updateComponent(ResourceDto resource);
 
   void updateProject(@Param("oldProjectKey") String oldProjectKey, @Param("newProjectKey") String newProjectKey);
index d6b8adb6a0281dac7f1455bb923d6af1f4739b8b..824b61656dc03820c485bb6e4f1c5066edf7c10d 100644 (file)
@@ -76,8 +76,8 @@ public class MeasureDao implements Dao {
     return session.getMapper(MeasureMapper.class);
   }
 
-  public List<ProjectMeasureDto> selectLastMeasureForAllProjects(DbSession session, String metricKey) {
-    return mapper(session).selectLastMeasureForAllProjects(metricKey);
+  public List<ProjectMeasureDto> selectMeasureFromLargestBranchForAllProjects(DbSession session, String metricKey) {
+    return mapper(session).selectMeasureFromLargestBranchForAllProjects(metricKey);
 
   }
 }
index 9f80836c15b54630ab0327d09568354c15218102..5b8759b2fae274a68e7c5bfac6f5389c92ec610d 100644 (file)
@@ -42,5 +42,5 @@ public interface MeasureMapper {
 
   void insert(MeasureDto measureDto);
 
-  List<ProjectMeasureDto> selectLastMeasureForAllProjects(@Param("metricKey") String metricKey);
+  List<ProjectMeasureDto> selectMeasureFromLargestBranchForAllProjects(@Param("metricKey") String metricKey);
 }
index 0029d5789d179808688c22c887770f14d3b11c9e..ecf0f8520b8bdacf93c5171e43769b3de65463fb 100644 (file)
@@ -151,6 +151,7 @@ public class PropertiesDao implements Dao {
     }
   }
 
+  // TODO distinguish branch from project
   public List<PropertyDto> selectProjectProperties(DbSession session, String projectKey) {
     return getMapper(session).selectProjectProperties(projectKey);
   }
index 6a836e97aed10688d9a5879d6f162eeb21ba11d7..8112fb214dd8853db64216137d1a5c957ed4428b 100644 (file)
@@ -12,7 +12,7 @@
     <result property="enabled" column="enabled"/>
   </resultMap>
 
-  <select id="countResourceByKey" parameterType="String" resultType="int">
+  <select id="countComponentsByKey" parameterType="String" resultType="int">
     SELECT count(1)
     FROM components
     WHERE kee = #{key,jdbcType=VARCHAR}
     and scope != 'PRJ'
   </select>
 
-  <select id="selectDescendantProjects" parameterType="String" resultMap="resourceResultMap">
-    select * from components
-    where
-    scope='PRJ'
-    and root_uuid = #{rootUuid,jdbcType=VARCHAR}
-    and uuid != #{rootUuid,jdbcType=VARCHAR}
-  </select>
-
   <update id="updateComponent" parameterType="Resource">
     update components
     set kee = #{key,jdbcType=VARCHAR}, deprecated_kee = #{deprecatedKey,jdbcType=VARCHAR}
index 3516f05dcda2f0e1ff1f24217b3f759fc841c29c..f0664d0a558c54150e578f12131dd70912646cff 100644 (file)
       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
                 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>
 
+
   <select id="countProjectsHavingMeasure" parameterType="map" resultType="long">
     select count(1)
       from live_measures lm
index 8d3c6d8d290ea4c47f49bcc2317ed78321f10aa3..20cce60af4d14ce5b3438519b8d54af300248ec1 100644 (file)
@@ -28,7 +28,7 @@
   </select>
 
 
-  <select id="selectLastMeasureForAllProjects" parameterType="map" resultType="ProjectMeasure">
+  <select id="selectMeasureFromLargestBranchForAllProjects" parameterType="map" resultType="ProjectMeasure">
     select tie_breaker.projectUuid as projectUuid,
     s.build_date as lastAnalysis,
     ncloc as loc,
       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
index 89992ed1c3faacf984fee2cc6602c605f769395f..790e937b628cee2264b58f110b47695ccb68e358 100644 (file)
@@ -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<RekeyedResource> 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"));
index be729322f027d69e2ec200268b4146d71d545d8b..2d7c7987556bd01d26995f2a4da9c971d9c088a0 100644 (file)
@@ -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<ComponentDto> dtoPopulator) {
     return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(uuid), true, defaults(), dtoPopulator);
   }
index b32970caf9a22af046ce214fccd668608effdd44..2d17a46c7b337e1cae8ca4d1d30b3b34549b8336 100644 (file)
@@ -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)
index 359a03dc2995b16ea0dc60ea9efe90b96740676d..c25f8b7ea0401dd4382f419e90c09de411844412 100644 (file)
@@ -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);
index 41a57cc1cc46a6446b961c11873296f88ce6846c..dfb2fd3b3c7ecf7d0be3c9655fcf176214364532 100644 (file)
@@ -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);
 }
index 7e42450ec13c3b04e3ac2669956a76f85e0e8672..c9aeaa8667566117dec66292ede3ad7c123c51ec 100644 (file)
@@ -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));
       }
 
index aecd1c82c95e36763c09f2578e54c7a0519020b4..dd17b32b9425d43dcb6f9c8ea6f1e55c152caee6 100644 (file)
@@ -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())
index 5041764425ef1796b4d26e8bfcbbfa9136c34d4f..1d3fc13e9dc5d525374d5304558ffa1fe9e51bd8 100644 (file)
@@ -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;
   }
 
index db813338c1e71b23833b546248cbcec393a8f069..c4905efc0b5062e0a9c8b5b1e15bc974c58244bb 100644 (file)
@@ -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"));
index 61720cbfaeaffe55b90c9b30ad76d170ff393dee..487625c0e8c196dc3f7f83393e1eabe1b0cdf8a2 100644 (file)
@@ -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) {
index 3124ef11c26b6eb8566a252338551a50a05693ff..b334c89bf4bc9db5c0c8c5d517107c8a1e707ebc 100644 (file)
@@ -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();
index a48bf77e94c4435262eb4cd9d06bf6613977c7af..f55873152e7b0be02ad274cba9dd35afcb66ddf6 100644 (file)
@@ -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();
   }
index a23e1c3e420c0684eb9be599cebd0b490b6a00e3..18031ce640d298017f1b2cf259d990d620d3c9b3 100644 (file)
@@ -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();
index acd829d61c5ab2566a848df641b4e45895058bfa..a5228b2add3fadf4a5edd3926a4e30f5c8579b73 100644 (file)
@@ -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));
index fd08abd57be8c0bf817f2a9b73afe3e31dcec2db..54fb534fbf83744dc23a73150c706bfd40e16c7c 100644 (file)
@@ -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"))
index 9900dcf7bc2bb94d26eeb43bea88c05e729809d6..3f65a751b790c98e3142d06b63533981d825970b 100644 (file)
@@ -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();
index 0afae7b792cc5042b4df56134bffa9881fc586bf..7f4738caae0a5b28e2843064af03f100578acace 100644 (file)
@@ -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)
index 3d17e12fe0c96af715dfdba3c56ea4a1eb5df98b..84a1c91f8a582046b77af9cc022d2a3b31f1d1a5 100644 (file)
@@ -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
index 36d5097c81dc4349079a864713c3d1360548732d..05cc511c98d6b97db017cf22845df17bf2ade665 100644 (file)
@@ -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();
index a72bfe25c133ca04f5afae7807e3a7dbb2075821..a04c4da3a09205614bd12aa413aceaab9a1f7f6e 100644 (file)
@@ -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());
index 90f0663cd23948cd3516ba7342ce6ab387aaaa15..8347b2094890e0dc579f17dfbb1f2f51efbd8b86 100644 (file)
@@ -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())
@@ -458,24 +458,6 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> {
     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<AddGroupAction> {
     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())
index e0d541afbe405e71c6cbfcdc113a89961b654a99..589c75cd621cb35fca5b0c1ecf7d9ead70f1d7dd 100644 (file)
@@ -347,23 +347,6 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> {
     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();
index d3dc23d714b8ba649ace1d06b49d6cdd7b8e9cef..d8c3a5c1303c4898a563a94d9ec5afa3d0282032 100644 (file)
@@ -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()));
-  }
-
 }
index 8ffaf36bcfd66dd47e7b9130d1e04ec4ba24b666..2239f0e930b71c456183dceb3a921faab96d324c 100644 (file)
@@ -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")
@@ -448,24 +448,6 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio
       .hasMessage("Permission codeviewer can't be removed from a public component");
   }
 
-  @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();
index edefb4dd7566c0a7ba54ff9b031f859b7619c844..29bb0d491d7b55effac1c5ffe859e4b62088f8d0 100644 (file)
@@ -396,23 +396,6 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction>
       .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();
index c562e222e7d446b393ca2a85c39a060196d2e9fb..0f265ed1103ec5e84b2e6708ea44c6e503de649f 100644 (file)
@@ -326,25 +326,6 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> {
       .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());
index 0d4e3e61136c3fb4159255f02ee04bddb3641d70..992f5d13b0e5e5a1754a6fba0ba57f076b4bf17f 100644 (file)
@@ -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());
index cc2434b907271eb5c6e5b8172b5cf075a733e33b..92ec2675f4158c263a188baa0e67ecb8b22ee99c 100644 (file)
@@ -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();
index 3c7274a0f03eeae0bd02e64a5252ef434fb05d04..512361963e6c0a4b44f75b4be24437094eead467 100644 (file)
@@ -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 -> {
index 231955fd5958cd7eae65dfed6cd608281d11a1b3..c70f5026e176e89ab15c5b571cc0b26db78c36b9 100644 (file)
@@ -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);
   }
index 6956e15b1dbea7e1bedb1af3a2fba572d580a713..3cd9078b38b03ec8f2f05b398b651c54c7c8fd2d 100644 (file)
@@ -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();
index b222f8cb501aae0261b3f3bc40cc2204cf50e4d4..0c70ad57d2fa4e3e49d4733c489c4e7c5b1721dd 100644 (file)
@@ -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();
index 892c5f30d8aca2dfb1a8e8c7bc698dc26d7f31d5..f8c4195d420873e03328abdf6186f1a0b4faa882 100644 (file)
@@ -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();
index f252d53598cfc0601b734d111d8ba0c004f57941..a9666ea7d286ee47abc2049d77622145cffff96a 100644 (file)
@@ -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();
index 04c2565c6fc91cd76ee31842e7568d0ee5ff91ab..66bffc649bea37289f6df81745af6b0653855111 100644 (file)
@@ -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();
index 1b5e676ac9010b586efd8d49dc931f45f0a81615..03984cd1295bd3b79ee1e1922a955d0f807aa16c 100644 (file)
@@ -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);
   }
index f3a8d13fe3627acc45b123f1d6d530d4543d9ce4..d3bb4ac62f4214aa73d5c8897ef07caf86abc8b7 100644 (file)
@@ -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();
index f29daa0519aef5532d7766adf2c80e04f8244fbb..833dfeedaacdd9d84fb6a2314d637a4e7f182096 100644 (file)
@@ -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)
index 89e3fd257c278c3305d48de0ce4d12da316666ad..9e077b84b8d9e5924179413d76dee54b7cdd857e 100644 (file)
@@ -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());
index 8ee6be6c799f6708ef37c49cba497c46fd3dced8..bdee1349221f46373aa887b0ed10d947797cae1e 100644 (file)
@@ -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());
index bfd3ba794f816966cb046d50e99327402bde4750..07654489d7cf35cc03b6093ee64ee7a54141445d 100644 (file)
@@ -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(() -> {
index 59e1e7250911be64aba9815bee41ce74d88a99bb..3588b5464717c13372cc8774653d65c47b36167f 100644 (file)
@@ -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(() -> {
index 20703ac513a6b43dc5a1e106f66d849c3512ef0c..e6b399e429509bd12e10cc0db34bbe9c68aacbba 100644 (file)
@@ -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();
index 66c679194eb08593cbff6a453be6aa4db1976526..301b1a623ebb0db990bc75ba95874b245f9015c8 100644 (file)
@@ -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++) {
index 1272acfd8cf535e89084510bc4b91731a1174171..a4982ca69e0614b11919ac977d39ffabbc96ff24 100644 (file)
@@ -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();
index 94f61d8448a3f6068b9d2fe3aca23ddc87fd65e0..b74d2b340d1f823bec2579ed380a854a940cbd0b 100644 (file)
@@ -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)