]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19558 Fix WS action ITs
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 16 Jun 2023 21:08:19 +0000 (16:08 -0500)
committersonartech <sonartech@sonarsource.com>
Tue, 20 Jun 2023 20:02:59 +0000 (20:02 +0000)
16 files changed:
server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepIT.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityProfileEventsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/taskprocessor/ProjectDescriptor.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
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-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/TokenActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/CancelActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/PullActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/MarketplaceActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/SearchEventsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/UuidFromPair.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/developers/ws/UuidFromPairs.java

index 4850fe1d361fdd517451291a005c67016638350a..90dae4147fca60d37b1b0dd2c7dc3cc9fd30d997 100644 (file)
@@ -233,10 +233,10 @@ public class BuildComponentTreeStepIT {
   @Test
   public void return_existing_uuids() {
     setAnalysisMetadataHolder();
-    ComponentDto project = dbTester.components().insertPrivateProject("ABCD", p -> p.setKey(REPORT_PROJECT_KEY)).getMainBranchComponent();
-    ComponentDto directory = newDirectory(project, "CDEF", REPORT_DIR_PATH_1);
+    ComponentDto mainBranch = dbTester.components().insertPrivateProject("ABCD", p -> p.setKey(REPORT_PROJECT_KEY)).getMainBranchComponent();
+    ComponentDto directory = newDirectory(mainBranch, "CDEF", REPORT_DIR_PATH_1);
     insertComponent(directory.setKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1));
-    insertComponent(newFileDto(project, directory, "DEFG")
+    insertComponent(newFileDto(mainBranch, directory, "DEFG")
       .setKey(REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1)
       .setPath(REPORT_FILE_PATH_1));
 
@@ -246,7 +246,7 @@ public class BuildComponentTreeStepIT {
 
     underTest.execute(new TestComputationStepContext());
 
-    verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), "ABCD");
+    verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), mainBranch.uuid());
     verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, REPORT_DIR_PATH_1, "CDEF");
     verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, "DEFG");
   }
index 8d9f13c2baedd1f7558a044602960112f6fe22db..d80ab7addc55d19436013a486c56fabaa46485ec 100644 (file)
@@ -72,18 +72,18 @@ public class QualityProfileEventsStep implements ComputationStep {
 
   @Override
   public void execute(ComputationStep.Context context) {
-    executeForProject(treeRootHolder.getRoot());
+    executeForBranch(treeRootHolder.getRoot());
   }
 
-  private void executeForProject(Component projectComponent) {
-    Optional<Measure> baseMeasure = measureRepository.getBaseMeasure(projectComponent, metricRepository.getByKey(CoreMetrics.QUALITY_PROFILES_KEY));
+  private void executeForBranch(Component branchComponent) {
+    Optional<Measure> baseMeasure = measureRepository.getBaseMeasure(branchComponent, metricRepository.getByKey(CoreMetrics.QUALITY_PROFILES_KEY));
     if (!baseMeasure.isPresent()) {
       // first analysis -> do not generate events
       return;
     }
 
     // Load profiles used in current analysis for which at least one file of the corresponding language exists
-    Optional<Measure> rawMeasure = measureRepository.getRawMeasure(projectComponent, metricRepository.getByKey(CoreMetrics.QUALITY_PROFILES_KEY));
+    Optional<Measure> rawMeasure = measureRepository.getRawMeasure(branchComponent, metricRepository.getByKey(CoreMetrics.QUALITY_PROFILES_KEY));
     if (!rawMeasure.isPresent()) {
       // No qualify profile computed on the project
       return;
index d1f1bb12fd2e97d6b5bcd7483e19f8cc32670edb..282bc315bc89af75d5b50fbc1a8f7bff0122aa92 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Objects;
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
 
 import static java.util.Objects.requireNonNull;
 
@@ -41,8 +42,8 @@ public class ProjectDescriptor {
   /**
    * Build a {@link ProjectDescriptor} without checking qualifier of ComponentDto.
    */
-  public static ProjectDescriptor of(ComponentDto project) {
-    return new ProjectDescriptor(project.uuid(), project.getKey(), project.name());
+  public static ProjectDescriptor of(ProjectDto project) {
+    return new ProjectDescriptor(project.getUuid(), project.getKey(), project.getName());
   }
 
   public final String getUuid() {
index 1d8b0ef5b6af1882174b29228fcd126049e64547..9859d2370fa404f9df6fd0ed87bbf90e0aa41700 100644 (file)
@@ -97,18 +97,17 @@ public class SnapshotDao implements Dao {
   /**
    * Returned finished analysis from a list of projects and dates.
    * "Finished" analysis means that the status in the CE_ACTIVITY table is SUCCESS => the goal is to be sure that the CE task is completely finished.
-   *
    * Note that branches analysis of projects are also returned.
    */
   public List<SnapshotDto> selectFinishedByProjectUuidsAndFromDates(DbSession dbSession, List<String> projectUuids, List<Long> fromDates) {
     checkArgument(projectUuids.size() == fromDates.size(), "The number of components (%s) and from dates (%s) must be the same.",
       String.valueOf(projectUuids.size()),
       String.valueOf(fromDates.size()));
-    List<ComponentUuidFromDatePair> componentUuidFromDatePairs = IntStream.range(0, projectUuids.size())
-      .mapToObj(i -> new ComponentUuidFromDatePair(projectUuids.get(i), fromDates.get(i)))
+    List<ProjectUuidFromDatePair> projectUuidFromDatePairs = IntStream.range(0, projectUuids.size())
+      .mapToObj(i -> new ProjectUuidFromDatePair(projectUuids.get(i), fromDates.get(i)))
       .collect(MoreCollectors.toList(projectUuids.size()));
 
-    return executeLargeInputs(componentUuidFromDatePairs, partition -> mapper(dbSession).selectFinishedByProjectUuidsAndFromDates(partition), i -> i / 2);
+    return executeLargeInputs(projectUuidFromDatePairs, partition -> mapper(dbSession).selectFinishedByProjectUuidsAndFromDates(partition), i -> i / 2);
   }
 
   public void switchIsLastFlagAndSetProcessedStatus(DbSession dbSession, String componentUuid, String analysisUuid) {
@@ -148,22 +147,22 @@ public class SnapshotDao implements Dao {
     return session.getMapper(SnapshotMapper.class);
   }
 
-  static class ComponentUuidFromDatePair implements Comparable<ComponentUuidFromDatePair> {
-    private final String componentUuid;
+  static class ProjectUuidFromDatePair implements Comparable<ProjectUuidFromDatePair> {
+    private final String projectUuid;
     private final long from;
 
-    ComponentUuidFromDatePair(String componentUuid, long from) {
-      this.componentUuid = requireNonNull(componentUuid);
+    ProjectUuidFromDatePair(String projectUuid, long from) {
+      this.projectUuid = requireNonNull(projectUuid);
       this.from = from;
     }
 
     @Override
-    public int compareTo(ComponentUuidFromDatePair other) {
+    public int compareTo(ProjectUuidFromDatePair other) {
       if (this == other) {
         return 0;
       }
 
-      int c = componentUuid.compareTo(other.componentUuid);
+      int c = projectUuid.compareTo(other.projectUuid);
       if (c == 0) {
         c = Long.compare(from, other.from);
       }
@@ -180,14 +179,13 @@ public class SnapshotDao implements Dao {
         return false;
       }
 
-      ComponentUuidFromDatePair other = (ComponentUuidFromDatePair) o;
-      return componentUuid.equals(other.componentUuid)
-        && from == other.from;
+      ProjectUuidFromDatePair other = (ProjectUuidFromDatePair) o;
+      return projectUuid.equals(other.projectUuid) && from == other.from;
     }
 
     @Override
     public int hashCode() {
-      return Objects.hash(componentUuid, from);
+      return Objects.hash(projectUuid, from);
     }
   }
 }
index a28063c7b78a3dee751c0aaa8df3a591a9c29ce8..acf6105d11a0f078e6f799750d6e971d7102d080 100644 (file)
@@ -24,7 +24,7 @@ import java.util.List;
 import javax.annotation.CheckForNull;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.session.RowBounds;
-import org.sonar.db.component.SnapshotDao.ComponentUuidFromDatePair;
+import org.sonar.db.component.SnapshotDao.ProjectUuidFromDatePair;
 
 public interface SnapshotMapper {
 
@@ -52,7 +52,7 @@ public interface SnapshotMapper {
 
   void update(SnapshotDto analysis);
 
-  List<SnapshotDto> selectFinishedByProjectUuidsAndFromDates(@Param("projectUuidFromDatePairs") List<ComponentUuidFromDatePair> pairs);
+  List<SnapshotDto> selectFinishedByProjectUuidsAndFromDates(@Param("projectUuidFromDatePairs") List<ProjectUuidFromDatePair> pairs);
 
   @CheckForNull
   Long selectLastAnalysisDateByProject(String projectUuid);
index 7d2adfa6b13f6d853d5a40522e34a59ae03b78b0..da7a40f453d4b66b018029170fd13be2eac8f718 100644 (file)
       inner join project_branches pb on pb.uuid=p.uuid
     where
       <foreach collection="projectUuidFromDatePairs" open="(" close=")" item="projectUuidFromDatePair" separator=" or ">
-        (pb.project_uuid=#{projectUuidFromDatePair.componentUuid, jdbcType=VARCHAR} and s.created_at >= #{projectUuidFromDatePair.from, jdbcType=BIGINT})
+        (pb.project_uuid=#{projectUuidFromDatePair.projectUuid, jdbcType=VARCHAR} and s.created_at >= #{projectUuidFromDatePair.from, jdbcType=BIGINT})
       </foreach>
       and s.status = 'P'
     order by
index 4a8d78515a69e6d1fa76a5853ffed540caed47d6..cf752455f0a6589175969f266aeec922d2981abc 100644 (file)
@@ -169,7 +169,11 @@ public class ComponentDbTester {
   }
 
   public final ProjectData insertPrivateProject(String uuid, Consumer<ComponentDto> dtoPopulator) {
-    return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(uuid), true, defaults(), dtoPopulator);
+    if (useDifferentUuids) {
+      return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true, defaults(), dtoPopulator, p -> p.setUuid(uuid));
+    } else {
+      return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(uuid), true, defaults(), dtoPopulator);
+    }
   }
 
   public final ProjectData insertPrivateProjectWithCustomBranch(String branchKey) {
index 5d301036a6fde93849176b10a763aa8159c4151e..cf638ea7a4d4328557b319e0db802ecc81d8666a 100644 (file)
@@ -37,12 +37,12 @@ import static org.sonar.db.portfolio.PortfolioDto.SelectionMode.NONE;
 
 public class ComponentTesting {
 
-  public static ComponentDto newFileDto(ComponentDto project) {
-    return newFileDto(project, (ComponentDto) null);
+  public static ComponentDto newFileDto(ComponentDto branch) {
+    return newFileDto(branch, (ComponentDto) null);
   }
 
-  public static ComponentDto newFileDto(ComponentDto project, @Nullable ComponentDto directory) {
-    return newFileDto(project, directory, Uuids.createFast());
+  public static ComponentDto newFileDto(ComponentDto branch, @Nullable ComponentDto directory) {
+    return newFileDto(branch, directory, Uuids.createFast());
   }
 
   public static ComponentDto newFileDto(ComponentDto branch, String mainBranchUuid) {
@@ -72,28 +72,28 @@ public class ComponentTesting {
       .setLanguage("xoo");
   }
 
-  public static ComponentDto newDirectory(ComponentDto project, String path) {
-    return newDirectory(project, Uuids.createFast(), path);
+  public static ComponentDto newDirectory(ComponentDto branch, String path) {
+    return newDirectory(branch, Uuids.createFast(), path);
   }
 
-  public static ComponentDto newDirectoryOnBranch(ComponentDto project, String path, String mainBranchUuid) {
-    return newDirectory(project, Uuids.createFast(), path, mainBranchUuid);
+  public static ComponentDto newDirectoryOnBranch(ComponentDto branch, String path, String mainBranchUuid) {
+    return newDirectory(branch, Uuids.createFast(), path, mainBranchUuid);
   }
 
-  private static ComponentDto newDirectory(ComponentDto project, String uuid, String path, String mainBranchUuid) {
-    String key = !path.equals("/") ? project.getKey() + ":" + path : project.getKey() + ":/";
-    return newChildComponent(uuid, project, project)
+  private static ComponentDto newDirectory(ComponentDto branch, String uuid, String path, String mainBranchUuid) {
+    String key = !path.equals("/") ? branch.getKey() + ":" + path : branch.getKey() + ":/";
+    return newChildComponent(uuid, branch, branch)
       .setKey(key)
       .setName(path)
       .setLongName(path)
-      .setBranchUuid(project.branchUuid())
+      .setBranchUuid(branch.branchUuid())
       .setPath(path)
       .setScope(Scopes.DIRECTORY)
       .setQualifier(Qualifiers.DIRECTORY);
   }
 
-  public static ComponentDto newDirectory(ComponentDto project, String uuid, String path) {
-    return newDirectory(project, uuid, path, null);
+  public static ComponentDto newDirectory(ComponentDto branch, String uuid, String path) {
+    return newDirectory(branch, uuid, path, null);
   }
 
   public static ComponentDto newSubPortfolio(ComponentDto portfolioOrSubPortfolio, String uuid, String key) {
index ae4da9f4a9f6c7c8b50ccb345278dc969d724af3..96fdfcb5df9a838bad6b688b3af95c6d6484ad3c 100644 (file)
@@ -90,11 +90,11 @@ public class IssueDbTester {
    * @throws AssertionError if rule is a Security Hotspot
    */
   @SafeVarargs
-  public final IssueDto insertIssue(RuleDto rule, ComponentDto project, ComponentDto file, Consumer<IssueDto>... populators) {
+  public final IssueDto insertIssue(RuleDto rule, ComponentDto branch, ComponentDto file, Consumer<IssueDto>... populators) {
     assertThat(rule.getType())
       .describedAs("rule must not be a Security Hotspot type")
       .isNotEqualTo(SECURITY_HOTSPOT.getDbConstant());
-    IssueDto issue = newIssue(rule, project, file)
+    IssueDto issue = newIssue(rule, branch, file)
       .setType(RULE_TYPES_EXCEPT_HOTSPOTS[new Random().nextInt(RULE_TYPES_EXCEPT_HOTSPOTS.length)]);
     stream(populators).forEach(p -> p.accept(issue));
     return insertIssue(issue);
index 4256242dba1a337a0c09df40d86d3dbda3354de4..74e4fcfdb1efa5a641bb2485ca740aeed9690f86 100644 (file)
@@ -26,6 +26,7 @@ import org.mockito.Mockito;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.TokenType;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.tester.UserSessionRule;
@@ -72,7 +73,7 @@ public class TokenActionIT {
 
   @Test
   public void should_generate_token() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     userSession.logIn().addProjectPermission(UserRole.USER, project);
     when(tokenGenerator.generate(TokenType.PROJECT_BADGE_TOKEN)).thenReturn("generated_token");
 
@@ -83,7 +84,7 @@ public class TokenActionIT {
 
   @Test
   public void handle_whenApplicationKeyPassed_shouldReturnToken() {
-    ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
+    ProjectDto application = db.components().insertPrivateApplication().getProjectDto();
     userSession.logIn().addProjectPermission(UserRole.USER, application);
     when(tokenGenerator.generate(TokenType.PROJECT_BADGE_TOKEN)).thenReturn("generated_token");
 
@@ -92,10 +93,9 @@ public class TokenActionIT {
     response.assertJson("{\"token\":\"generated_token\"}");
   }
 
-
   @Test
   public void should_reuse_generated_token() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     userSession.logIn().addProjectPermission(UserRole.USER, project);
     when(tokenGenerator.generate(TokenType.PROJECT_BADGE_TOKEN)).thenReturn("generated_token");
 
index 381323b96f120b0dfa2ba542822aac6baacf1883..d148bc5dfa366309f729753dedc7b86792c7c505 100644 (file)
@@ -35,6 +35,8 @@ import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.platform.NodeInformation;
 import org.sonar.server.tester.UserSessionRule;
@@ -98,9 +100,12 @@ public class CancelActionIT {
 
   @Test
   public void cancel_pending_task_when_project_administer() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.ADMIN, project);
-    CeQueueDto queue = createTaskSubmit(project);
+    ProjectData project = db.components().insertPrivateProject();
+    ProjectDto projectDto = project.getProjectDto();
+    ComponentDto mainBranchComponent = project.getMainBranchComponent();
+    userSession.addProjectPermission(UserRole.ADMIN, projectDto);
+    userSession.addProjectBranchMapping(projectDto.getUuid(), mainBranchComponent);
+    CeQueueDto queue = createTaskSubmit(mainBranchComponent);
 
     tester.newRequest()
       .setParam("id", queue.getUuid())
index e845bfe0a6d1b035ab82d249203e9edef53d1a5f..a03151cac616031ec24ce8b37d58110131f0806a 100644 (file)
@@ -33,11 +33,14 @@ import org.sonar.api.issue.Issue;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.issue.IssueDbTester;
 import org.sonar.db.issue.IssueDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.protobuf.DbCommons;
 import org.sonar.db.protobuf.DbIssues;
 import org.sonar.db.rule.RuleDto;
@@ -89,16 +92,21 @@ public class PullActionIT {
     pullActionProtobufObjectGenerator);
   private final WsActionTester tester = new WsActionTester(underTest);
 
+  private ProjectDto project;
   private ComponentDto correctProject, incorrectProject;
   private ComponentDto correctFile, incorrectFile;
 
   @Before
   public void before() {
     when(system2.now()).thenReturn(NOW);
-    correctProject = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPrivateProject();
+    correctProject = projectData.getMainBranchComponent();
+    project = projectData.getProjectDto();
+
     correctFile = db.components().insertComponent(newFileDto(correctProject));
 
-    incorrectProject = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData incorrectProjectData = db.components().insertPrivateProject();
+    incorrectProject = incorrectProjectData.getMainBranchComponent();
     incorrectFile = db.components().insertComponent(newFileDto(incorrectProject));
   }
 
@@ -220,10 +228,12 @@ public class PullActionIT {
 
   @Test
   public void wsExecution_whenHotspotOnAnotherBranchThanMain_shouldReturnOneIssue() throws IOException {
-    ComponentDto developBranch = componentDbTester.insertPrivateProjectWithCustomBranch("develop").getMainBranchComponent();
+    ProjectData projectData = componentDbTester.insertPrivateProjectWithCustomBranch("develop");
+    ProjectDto project = projectData.getProjectDto();
+    ComponentDto developBranch = projectData.getMainBranchComponent();
     ComponentDto developFile = db.components().insertComponent(newFileDto(developBranch));
     List<String> hotspotKeys = generateHotspots(developBranch, developFile, 1);
-    loginWithBrowsePermission(developBranch.uuid(), developFile.uuid());
+    loginWithBrowsePermission(project, developFile.uuid());
 
     TestRequest request = tester.newRequest()
       .setParam("projectKey", developBranch.getKey())
@@ -268,7 +278,7 @@ public class PullActionIT {
 
   @Test
   public void wsExecution_whenDifferentHotspotsInTheTable_shouldReturnOnlyThatBelongToSelectedProject() throws IOException {
-    loginWithBrowsePermission(correctProject.uuid(), correctFile.uuid());
+    loginWithBrowsePermission(project, correctFile.uuid());
     List<String> correctIssueKeys = generateHotspots(correctProject, correctFile, 10);
     List<String> incorrectIssueKeys = generateHotspots(incorrectProject, incorrectFile, 5);
 
@@ -288,7 +298,7 @@ public class PullActionIT {
 
   @Test
   public void wsExecution_whenNoIssuesBelongToTheProject_shouldReturnZeroIssues() throws IOException {
-    loginWithBrowsePermission(correctProject.uuid(), correctFile.uuid());
+    loginWithBrowsePermission(project, correctFile.uuid());
     generateHotspots(incorrectProject, incorrectFile, 5);
 
     TestRequest request = tester.newRequest()
@@ -303,7 +313,7 @@ public class PullActionIT {
 
   @Test
   public void wsExecution_whenLanguagesParam_shouldReturnOneIssue() throws IOException {
-    loginWithBrowsePermission(correctProject.uuid(), correctFile.uuid());
+    loginWithBrowsePermission(project, correctFile.uuid());
     RuleDto javaRule = db.rules().insert(r -> r.setLanguage("java"));
 
     IssueDto javaIssue = issueDbTester.insertHotspot(p -> p.setSeverity("MINOR")
@@ -331,7 +341,7 @@ public class PullActionIT {
 
   @Test
   public void wsExecution_whenChangedSinceParam_shouldReturnMatchingIssue() throws IOException {
-    loginWithBrowsePermission(correctProject.uuid(), correctFile.uuid());
+    loginWithBrowsePermission(project, correctFile.uuid());
     RuleDto javaRule = db.rules().insert(r -> r.setLanguage("java"));
 
     IssueDto issueBefore = issueDbTester.insertHotspot(p -> p.setSeverity("MINOR")
@@ -371,7 +381,7 @@ public class PullActionIT {
 
   @Test
   public void wsExecution_whenWrongLanguageSet_shouldReturnZeroIssues() throws IOException {
-    loginWithBrowsePermission(correctProject.uuid(), correctFile.uuid());
+    loginWithBrowsePermission(project, correctFile.uuid());
     RuleDto javascriptRule = db.rules().insert(r -> r.setLanguage("javascript"));
 
     issueDbTester.insertHotspot(p -> p.setSeverity("MINOR")
@@ -418,12 +428,16 @@ public class PullActionIT {
   }
 
   private void loginWithBrowsePermission(IssueDto issueDto) {
-    loginWithBrowsePermission(issueDto.getProjectUuid(), issueDto.getComponentUuid());
+    BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get();
+    ProjectDto projectDto = db.getDbClient().projectDao().selectByUuid(db.getSession(), branchDto.getProjectUuid()).get();
+    loginWithBrowsePermission(projectDto, issueDto.getComponentUuid());
   }
 
-  private void loginWithBrowsePermission(String projectUuid, String componentUuid) {
+  private void loginWithBrowsePermission(ProjectDto project, String componentUuid) {
     UserDto user = db.users().insertUser("john");
-    userSession.logIn(user).addProjectPermission(USER, getComponentOrFail(projectUuid, "project not found"), getComponentOrFail(componentUuid, "component not found"));
+    userSession.logIn(user)
+      .addProjectPermission(USER, project)
+      .addProjectPermission(USER, getComponentOrFail(componentUuid, "component not found"));
   }
 
   private ComponentDto getComponentOrFail(String componentUuid, String failMessage) {
index aeeb6fedb9e34d66aa85b015a021f972ba66e7fe..244c45af47945ed9b53306b096028fe38ea92dcd 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
 import org.sonar.server.tester.UserSessionRule;
@@ -116,8 +117,8 @@ public class MarketplaceActionIT {
   }
 
   private void setNcloc(double ncloc) {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    db.getDbClient().projectDao().updateNcloc(db.getSession(), project.uuid(), (long) ncloc);
+    ProjectDto project = db.components().insertPublicProject().getProjectDto();
+    db.getDbClient().projectDao().updateNcloc(db.getSession(), project.getUuid(), (long) ncloc);
     db.commit();
   }
 }
index 1f965dc99860e7df8d7838b04a784771c61605d6..598c7616760067e73139833b7f885bb0ec5b069c 100644 (file)
@@ -24,7 +24,6 @@ import java.net.URLEncoder;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Predicate;
@@ -63,8 +62,8 @@ import static org.sonar.core.util.stream.MoreCollectors.toList;
 import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
 import static org.sonar.db.component.BranchType.BRANCH;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
-import static org.sonar.server.developers.ws.UuidFromPairs.componentUuids;
 import static org.sonar.server.developers.ws.UuidFromPairs.fromDates;
+import static org.sonar.server.developers.ws.UuidFromPairs.projectUuids;
 import static org.sonar.server.exceptions.BadRequestException.checkRequest;
 import static org.sonar.server.ws.WsUtils.writeProtobuf;
 
@@ -136,7 +135,7 @@ public class SearchEventsAction implements DevelopersWsAction {
       List<ProjectDto> authorizedProjects = searchProjects(dbSession, projectKeys);
       Map<String, ProjectDto> projectsByUuid = authorizedProjects.stream().collect(uniqueIndex(ProjectDto::getUuid));
       List<UuidFromPair> uuidFromPairs = buildUuidFromPairs(fromDates, projectKeys, authorizedProjects);
-      List<SnapshotDto> analyses = dbClient.snapshotDao().selectFinishedByProjectUuidsAndFromDates(dbSession, componentUuids(uuidFromPairs), fromDates(uuidFromPairs));
+      List<SnapshotDto> analyses = dbClient.snapshotDao().selectFinishedByProjectUuidsAndFromDates(dbSession, projectUuids(uuidFromPairs), fromDates(uuidFromPairs));
 
       if (analyses.isEmpty()) {
         return Stream.empty();
@@ -184,9 +183,9 @@ public class SearchEventsAction implements DevelopersWsAction {
   private Stream<Event> computeNewIssuesEvents(Map<String, ProjectDto> projectsByUuid, Map<String, BranchDto> branchesByUuids,
     List<UuidFromPair> uuidFromPairs) {
     Map<String, Long> fromsByProjectUuid = uuidFromPairs.stream().collect(Collectors.toMap(
-      UuidFromPair::getComponentUuid,
+      UuidFromPair::getProjectUuid,
       UuidFromPair::getFrom));
-    List<ProjectStatistics> projectStatistics = issueIndex.searchProjectStatistics(componentUuids(uuidFromPairs), fromDates(uuidFromPairs), userSession.getUuid());
+    List<ProjectStatistics> projectStatistics = issueIndex.searchProjectStatistics(projectUuids(uuidFromPairs), fromDates(uuidFromPairs), userSession.getUuid());
     return projectStatistics
       .stream()
       .map(e -> {
index 0a025c70dfe400b8e2bef38f101ec85740d329d8..2575545fb980b8147f11bd5198763f22f80c15c4 100644 (file)
 package org.sonar.server.developers.ws;
 
 class UuidFromPair {
-  private final String componentUuid;
+  private final String projectUuid;
   private final long from;
 
-  public UuidFromPair(String componentUuid, long from) {
-    this.componentUuid = componentUuid;
+  public UuidFromPair(String projectUuid, long from) {
+    this.projectUuid = projectUuid;
     this.from = from;
   }
 
-  public String getComponentUuid() {
-    return componentUuid;
+  public String getProjectUuid() {
+    return projectUuid;
   }
 
   public long getFrom() {
index 93383b711fc772a114798d44ff4afaaed443d686..f074c8b0ea9a7745eb20d0844480e4ad59bdb4b4 100644 (file)
@@ -27,8 +27,8 @@ public class UuidFromPairs {
     // prevent instantiation
   }
 
-  public static List<String> componentUuids(List<UuidFromPair> pairs) {
-    return pairs.stream().map(UuidFromPair::getComponentUuid).collect(MoreCollectors.toList(pairs.size()));
+  public static List<String> projectUuids(List<UuidFromPair> pairs) {
+    return pairs.stream().map(UuidFromPair::getProjectUuid).collect(MoreCollectors.toList(pairs.size()));
   }
 
   public static List<Long> fromDates(List<UuidFromPair> pairs) {