]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19445 Remove usage of registerComponents in UserSessionRule
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Thu, 8 Jun 2023 12:35:39 +0000 (14:35 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 19 Jun 2023 20:03:14 +0000 (20:03 +0000)
25 files changed:
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-webserver-auth/src/test/java/org/sonar/server/user/ThreadLocalUserSessionTest.java
server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/AbstractMockUserSession.java
server/sonar-webserver-auth/src/testFixtures/java/org/sonar/server/tester/UserSessionRule.java
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/MeasureActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/badge/ws/QualityGateActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/ws/TaskActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/ShowActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AddCommentActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/AssignActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ChangeStatusActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/DeleteCommentActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/EditCommentActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/SearchActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/hotspot/ws/ShowActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionComponentsIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTagsActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentTreeActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/SearchActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectlink/ws/CreateActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/LinesActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ui/ws/ComponentActionIT.java

index 020853338604948190f4084ce453ef833784b920..1dc899a954273dd65d0a4ba79551a5e949ea541a 100644 (file)
@@ -479,11 +479,17 @@ public class ComponentDbTester {
   }
 
   public SnapshotDto insertSnapshot(ProjectData project, Consumer<SnapshotDto> consumer) {
-    return insertSnapshot(project.getProjectDto(), consumer);
+    return insertSnapshot(project.getMainBranchDto(), consumer);
   }
 
+  /**
+   * Add a snapshot to the main branch of a project
+   * Should use insertSnapshot(org.sonar.db.component.BranchDto, java.util.function.Consumer<org.sonar.db.component.SnapshotDto>) instead
+   */
+  @Deprecated
   public SnapshotDto insertSnapshot(ProjectDto project, Consumer<SnapshotDto> consumer) {
-    SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(project.getUuid());
+    BranchDto mainBranchDto = db.getDbClient().branchDao().selectMainBranchByProjectUuid(dbSession, project.getUuid()).orElseThrow();
+    SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(mainBranchDto.getUuid());
     consumer.accept(snapshotDto);
     return insertSnapshot(snapshotDto);
   }
index a440726ddb4c3dbc52b25ebebc15f93bfd2837e3..927d448abf1aba73d06ad3ef9e25a8c3add45eec 100644 (file)
@@ -264,6 +264,14 @@ public class ComponentTesting {
       .setQualifier(Qualifiers.PROJECT);
   }
 
+  public static ProjectDto newApplicationDto() {
+    return new ProjectDto()
+      .setKey("appKey")
+      .setUuid("uuid")
+      .setName("appName")
+      .setQualifier(Qualifiers.APP);
+  }
+
   public static ComponentDto newBranchComponent(ProjectDto project, BranchDto branchDto) {
     String uuid = branchDto.getUuid();
     return new ComponentDto()
index 74e3544caad50ec8473b63ccf00e192f294e36bc..db58d6bdeefd76d9223b5dec4fbe74aa1cab12dd 100644 (file)
@@ -124,15 +124,12 @@ public class ThreadLocalUserSessionTest {
       .setGroups(group);
 
     ProjectDto subProjectDto = new ProjectDto().setQualifier(Qualifiers.PROJECT).setUuid("subproject-uuid");
-    ComponentDto applicationAsComponentDto = new ComponentDto().setQualifier(Qualifiers.APP).setUuid("application-component-uuid").setBranchUuid("application-project-uuid");
     ProjectDto applicationAsProjectDto = new ProjectDto().setQualifier(Qualifiers.APP).setUuid("application-project-uuid");
 
     expected.registerProjects(subProjectDto);
     expected.registerApplication(applicationAsProjectDto, subProjectDto);
-    expected.registerComponents(applicationAsComponentDto);
     threadLocalUserSession.set(expected);
 
-    assertThat(threadLocalUserSession.checkChildProjectsPermission(USER, applicationAsComponentDto)).isEqualTo(threadLocalUserSession);
     assertThat(threadLocalUserSession.checkChildProjectsPermission(USER, applicationAsProjectDto)).isEqualTo(threadLocalUserSession);
   }
 }
index 48c4ff0f4ff142dcce46388d3498398c6670c367..fec1d77b4b684c19f2dca25f2694cdb2c1232410 100644 (file)
@@ -102,18 +102,6 @@ public abstract class AbstractMockUserSession<T extends AbstractMockUserSession>
     return clazz.cast(this);
   }
 
-  public T registerApplication(ComponentDto application, ComponentDto... appProjects) {
-    registerComponents(application);
-    registerComponents(appProjects);
-
-    var appProjectsUuid = Arrays.stream(appProjects)
-      .map(ComponentDto::uuid)
-      .collect(Collectors.toSet());
-    this.applicationProjects.put(application.uuid(), appProjectsUuid);
-
-    return clazz.cast(this);
-  }
-
   public T registerApplication(ProjectDto application, ProjectDto... appProjects) {
     registerProjects(application);
     registerProjects(appProjects);
index 3d4f35ac0f39fd4be19f940353488b2159ed4146..a0cac5d1f75225d2cfddaf96951997ebf22121b1 100644 (file)
@@ -175,8 +175,8 @@ public class UserSessionRule implements TestRule, UserSession {
     setCurrentUserSession(userSession);
   }
 
-  public UserSessionRule registerComponents(ComponentDto... componentDtos) {
-    ensureAbstractMockUserSession().registerComponents(componentDtos);
+  public UserSessionRule registerPortfolios(ComponentDto... portfolios) {
+    ensureAbstractMockUserSession().registerComponents(portfolios);
     return this;
   }
 
@@ -195,11 +195,6 @@ public class UserSessionRule implements TestRule, UserSession {
     return this;
   }
 
-  public UserSessionRule registerApplication(ComponentDto application, ComponentDto... appProjects) {
-    ensureAbstractMockUserSession().registerApplication(application, appProjects);
-    return this;
-  }
-
   public UserSessionRule addProjectPermission(String projectPermission, ComponentDto... components) {
     ensureAbstractMockUserSession().addProjectPermission(projectPermission, components);
     return this;
@@ -210,7 +205,7 @@ public class UserSessionRule implements TestRule, UserSession {
     return this;
   }
 
-  public UserSession registerBranches(BranchDto... branchDtos) {
+  public UserSessionRule registerBranches(BranchDto... branchDtos) {
     ensureAbstractMockUserSession().registerBranches(branchDtos);
     return this;
   }
index ececa35a00c79487869040112de573619824f558..d74539ba182b60db53cb2b491e8d05d84041fed6 100644 (file)
@@ -33,8 +33,10 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.api.testfixtures.log.LogTester;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.metric.MetricDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.rule.RuleDbTester;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.user.UserDto;
@@ -300,7 +302,7 @@ public class IssueQueryFactoryTest {
     ComponentDto view = db.components().insertPublicPortfolio();
     SearchRequest request = new SearchRequest()
       .setComponentUuids(singletonList(view.uuid()));
-    userSession.registerComponents(view);
+    userSession.registerPortfolios(view);
 
     IssueQuery query = underTest.create(request);
 
@@ -310,12 +312,16 @@ public class IssueQueryFactoryTest {
 
   @Test
   public void application_search_project_issues() {
-    ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPublicProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPublicProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
+    ProjectData applicationData = db.components().insertPublicApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
     db.components().insertComponents(newProjectCopy("PC1", project1, application));
     db.components().insertComponents(newProjectCopy("PC2", project2, application));
-    userSession.registerApplication(application, project1, project2);
+    userSession.registerApplication(applicationData.getProjectDto())
+      .registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto());
 
     IssueQuery result = underTest.create(new SearchRequest().setComponentUuids(singletonList(application.uuid())));
 
@@ -339,22 +345,28 @@ public class IssueQueryFactoryTest {
   public void application_search_project_issues_in_new_code_with_and_without_analysis_after_sonarqube_94() {
     Date now = new Date();
     when(clock.millis()).thenReturn(now.getTime());
-    ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPublicProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
     SnapshotDto analysis1 = db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
-    ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPublicProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     db.components().insertSnapshot(project2, s -> s.setPeriodDate(null));
-    ComponentDto project3 = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto project4 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData3 = db.components().insertPublicProject();
+    ComponentDto project3 = projectData3.getMainBranchComponent();
+    ProjectData projectData4 = db.components().insertPublicProject();
+    ComponentDto project4 = projectData4.getMainBranchComponent();
     SnapshotDto analysis2 = db.components().insertSnapshot(project4,
       s -> s.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
-    ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+    ProjectData applicationData = db.components().insertPublicApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
     MetricDto analysisMetric = db.measures().insertMetric(m -> m.setKey(ANALYSIS_FROM_SONARQUBE_9_4_KEY));
     db.measures().insertLiveMeasure(project4, analysisMetric, measure -> measure.setData("true"));
     db.components().insertComponents(newProjectCopy("PC1", project1, application));
     db.components().insertComponents(newProjectCopy("PC2", project2, application));
     db.components().insertComponents(newProjectCopy("PC3", project3, application));
     db.components().insertComponents(newProjectCopy("PC4", project4, application));
-    userSession.registerApplication(application, project1, project2, project3, project4);
+    userSession.registerApplication(applicationData.getProjectDto());
+    userSession.registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto(), projectData3.getProjectDto(), projectData4.getProjectDto());
 
     IssueQuery result = underTest.create(new SearchRequest()
       .setComponentUuids(singletonList(application.uuid()))
@@ -523,15 +535,19 @@ public class IssueQueryFactoryTest {
 
   @Test
   public void search_by_application_key() {
-    ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData applicationData = db.components().insertPrivateApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPrivateProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPrivateProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     db.components().insertComponents(newProjectCopy(project1, application));
     db.components().insertComponents(newProjectCopy(project2, application));
-    userSession.registerApplication(application, project1, project2)
-      .addProjectPermission(USER, application)
-      .addProjectPermission(USER, project1)
-      .addProjectPermission(USER, project2);
+    userSession.registerApplication(applicationData.getProjectDto())
+      .registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto())
+      .addProjectPermission(USER, applicationData.getProjectDto())
+      .addProjectPermission(USER, projectData1.getProjectDto())
+      .addProjectPermission(USER, projectData2.getProjectDto());
 
     assertThat(underTest.create(new SearchRequest()
         .setComponents(singletonList(application.getKey())))
index d9c38fba6aabbd2c1e99fecbeb15694ea3f68db5..c68e8c572534d4ced0a6f5a400d0379fd3312b71 100644 (file)
@@ -42,6 +42,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.metric.MetricDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.UserDto;
@@ -83,7 +84,7 @@ public class MeasureActionIT {
   @Rule
   public UserSessionRule userSession = UserSessionRule.standalone();
   @Rule
-  public DbTester db = DbTester.create();
+  public DbTester db = DbTester.create(true);
 
   private final MapSettings mapSettings = new MapSettings();
   private final Configuration config = mapSettings.asConfig();
@@ -101,8 +102,10 @@ public class MeasureActionIT {
 
   @Test
   public void int_measure() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createIntMetricAndMeasure(project, BUGS_KEY, 10_000);
 
     TestResponse response = ws.newRequest()
@@ -118,8 +121,10 @@ public class MeasureActionIT {
 
   @Test
   public void percent_measure() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY).setValueType(PERCENT.name()));
     db.measures().insertLiveMeasure(project, metric, m -> m.setValue(12.345d));
 
@@ -136,8 +141,10 @@ public class MeasureActionIT {
 
   @Test
   public void duration_measure() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(TECHNICAL_DEBT_KEY).setValueType(WORK_DUR.name()));
     db.measures().insertLiveMeasure(project, metric, m -> m.setValue(10_000d));
 
@@ -166,8 +173,10 @@ public class MeasureActionIT {
   @Test
   @UseDataProvider("ratings")
   public void rating_measure(Rating rating, Color color) {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(SQALE_RATING_KEY).setValueType(RATING.name()));
     db.measures().insertLiveMeasure(project, metric, m -> m.setValue((double) rating.getIndex()).setData(rating.name()));
 
@@ -193,8 +202,10 @@ public class MeasureActionIT {
   @Test
   @UseDataProvider("qualityGates")
   public void quality_gate(Level status, String expectedValue, Color expectedColor) {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setData(status.name()));
 
@@ -211,8 +222,10 @@ public class MeasureActionIT {
 
   @Test
   public void security_hotspots() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createIntMetricAndMeasure(project, SECURITY_HOTSPOTS_KEY, 42);
 
     TestResponse response = ws.newRequest()
@@ -229,8 +242,10 @@ public class MeasureActionIT {
 
   @Test
   public void display_deprecated_warning_quality_gate() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setData(WARN.name()));
 
@@ -244,8 +259,10 @@ public class MeasureActionIT {
 
   @Test
   public void measure_on_non_main_branch() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setPrivate(false)).getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setPrivate(false));
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createIntMetricAndMeasure(project, BUGS_KEY, 5_000);
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
@@ -273,8 +290,10 @@ public class MeasureActionIT {
 
   @Test
   public void measure_on_application() {
-    ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
-    userSession.registerComponents(application);
+    ProjectData projectData = db.components().insertPublicApplication();
+    ComponentDto application = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createIntMetricAndMeasure(application, BUGS_KEY, 10_000);
 
     TestResponse response = ws.newRequest()
@@ -302,9 +321,10 @@ public class MeasureActionIT {
 
   @Test
   public void return_error_if_branch_does_not_exist() throws ParseException {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY));
 
     TestResponse response = ws.newRequest()
@@ -318,8 +338,10 @@ public class MeasureActionIT {
 
   @Test
   public void return_error_if_measure_not_found() throws ParseException {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY));
 
     TestResponse response = ws.newRequest()
@@ -332,9 +354,10 @@ public class MeasureActionIT {
 
   @Test
   public void return_error_on_directory() throws ParseException {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(project, "path"));
-    userSession.registerComponents(project);
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY).setValueType(INT.name()));
 
     TestResponse response = ws.newRequest()
@@ -383,22 +406,19 @@ public class MeasureActionIT {
   @UseDataProvider("publicProject_forceAuth_accessGranted")
   public void badge_accessible_on_private_project_with_token(boolean publicProject, boolean forceAuth,
     boolean validToken, boolean accessGranted) throws ParseException {
-    ComponentDto projectAsComponent = publicProject ? db.components().insertPublicProject().getMainBranchComponent() : db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.registerComponents(projectAsComponent);
-    MetricDto metric = createIntMetricAndMeasure(projectAsComponent, BUGS_KEY, 10_000);
-
-    ProjectDto project = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), projectAsComponent.getKey())
-      .orElseThrow(() -> new IllegalStateException("project not found"));
+    ProjectData project = publicProject ? db.components().insertPublicProject() : db.components().insertPrivateProject();
+    userSession.registerProjects(project.getProjectDto());
+    MetricDto metric = createIntMetricAndMeasure(project.getMainBranchComponent(), BUGS_KEY, 10_000);
 
     String token = db.getDbClient().projectBadgeTokenDao()
-      .insert(db.getSession(), UuidFactoryFast.getInstance().create(), project, "user-uuid", "user-login")
+      .insert(db.getSession(), UuidFactoryFast.getInstance().create(), project.getProjectDto(), "user-uuid", "user-login")
       .getToken();
     db.commit();
 
     mapSettings.setProperty(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY, forceAuth);
 
     TestResponse response = ws.newRequest()
-      .setParam("project", projectAsComponent.getKey())
+      .setParam("project", project.getProjectDto().getKey())
       .setParam("metric", metric.getKey())
       .setParam("token", validToken ? token : "invalid-token")
       .execute();
@@ -412,8 +432,9 @@ public class MeasureActionIT {
 
   @Test
   public void return_error_on_provisioned_project() throws ParseException {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectDto project = db.components().insertPublicProject().getProjectDto();
+
+    userSession.registerProjects(project);
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY).setValueType(INT.name()));
 
     TestResponse response = ws.newRequest()
@@ -426,8 +447,10 @@ public class MeasureActionIT {
 
   @Test
   public void fail_on_invalid_quality_gate() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setData("UNKNOWN"));
 
@@ -444,8 +467,10 @@ public class MeasureActionIT {
 
   @Test
   public void fail_when_measure_value_is_null() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY).setValueType(INT.name()));
     db.measures().insertLiveMeasure(project, metric, m -> m.setValue(null));
 
@@ -463,8 +488,10 @@ public class MeasureActionIT {
 
   @Test
   public void fail_when_metric_not_found() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
 
     TestRequest request = ws.newRequest()
       .setParam("project", project.getKey())
index c76bb9b483aaef79786e0d5f49dd2192a21896be..0995757dd93edd502bc4182fa0ca119d52bc1629 100644 (file)
@@ -41,6 +41,7 @@ import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.measure.LiveMeasureDto;
 import org.sonar.db.metric.MetricDto;
 import org.sonar.db.project.ProjectDto;
@@ -85,8 +86,10 @@ public class QualityGateActionIT {
 
   @Test
   public void quality_gate_passed() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
 
@@ -99,8 +102,10 @@ public class QualityGateActionIT {
 
   @Test
   public void quality_gate_failed() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setData(ERROR.name()));
 
@@ -135,12 +140,12 @@ public class QualityGateActionIT {
   @UseDataProvider("publicProject_forceAuth_validToken_accessGranted")
   public void badge_accessible_on_private_project_with_token(boolean publicProject, boolean forceAuth,
                                                                boolean validToken, boolean accessGranted) throws ParseException {
-    ComponentDto projectAsComponent = publicProject ? db.components().insertPublicProject().getMainBranchComponent() : db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.registerComponents(projectAsComponent);
+    ProjectData projectData = publicProject ? db.components().insertPublicProject() : db.components().insertPrivateProject();
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
 
-    db.measures().insertLiveMeasure(projectAsComponent, metric, m -> m.setData(OK.name()));
-    ProjectDto project = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), projectAsComponent.getKey())
+    db.measures().insertLiveMeasure(projectData, metric, m -> m.setData(OK.name()));
+    ProjectDto project = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), projectData.getProjectDto().getKey())
       .orElseThrow(() -> new IllegalStateException("project not found"));
 
     String token = db.getDbClient().projectBadgeTokenDao()
@@ -151,7 +156,7 @@ public class QualityGateActionIT {
     mapSettings.setProperty(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY, forceAuth);
 
     TestResponse response = ws.newRequest()
-      .setParam("project", projectAsComponent.getKey())
+      .setParam("project", projectData.getProjectDto().getKey())
       .setParam("token", validToken ? token : "invalid-token")
       .execute();
 
@@ -165,8 +170,10 @@ public class QualityGateActionIT {
 
   @Test
   public void etag_should_be_different_if_quality_gate_is_different() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     LiveMeasureDto liveMeasure = db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
 
@@ -192,8 +199,10 @@ public class QualityGateActionIT {
 
   @Test
   public void when_IfNoneMatch_match_etag_http_304_must_be_send() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
 
@@ -213,8 +222,10 @@ public class QualityGateActionIT {
 
   @Test
   public void quality_gate_on_branch() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setPrivate(false)).getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setPrivate(false));
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
     String branchName = randomAlphanumeric(248);
@@ -231,8 +242,10 @@ public class QualityGateActionIT {
 
   @Test
   public void quality_gate_on_application() {
-    ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
-    userSession.registerComponents(application);
+    ProjectData projectData = db.components().insertPublicApplication();
+    ComponentDto application = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(application, metric, m -> m.setData(ERROR.name()));
 
@@ -245,9 +258,10 @@ public class QualityGateActionIT {
 
   @Test
   public void return_error_on_directory() throws ParseException {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(project, "path"));
-    userSession.registerComponents(project);
+    userSession.registerProjects(projectData.getProjectDto());
 
     TestResponse response = ws.newRequest()
       .setParam("project", directory.getKey())
@@ -271,8 +285,10 @@ public class QualityGateActionIT {
 
   @Test
   public void return_error_on_provisioned_project() throws ParseException {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
 
     TestResponse response = ws.newRequest()
       .setParam("project", project.getKey())
@@ -292,8 +308,10 @@ public class QualityGateActionIT {
 
   @Test
   public void return_error_on_not_existing_branch() throws ParseException {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setPrivate(false)).getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setPrivate(false));
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
 
     TestResponse response = ws.newRequest()
@@ -306,8 +324,10 @@ public class QualityGateActionIT {
 
   @Test
   public void return_error_if_measure_not_found() throws ParseException {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
 
     TestResponse response = ws.newRequest()
       .setParam("project", project.getKey())
@@ -318,8 +338,10 @@ public class QualityGateActionIT {
 
   @Test
   public void return_error_if_measure_value_is_null() throws ParseException {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setData((String) null));
 
@@ -333,8 +355,10 @@ public class QualityGateActionIT {
 
   @Test
   public void fail_on_invalid_quality_gate() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
     MetricDto metric = createQualityGateMetric();
     db.measures().insertLiveMeasure(project, metric, m -> m.setData("UNKNOWN"));
 
index 33960fbc82fff9263957ee7bfddacb3f52d51850..425e40f5ceb48bbca40911dccc685a0c40786110 100644 (file)
@@ -39,7 +39,9 @@ import org.sonar.db.ce.CeTaskMessageDto;
 import org.sonar.db.ce.CeTaskMessageType;
 import org.sonar.db.ce.CeTaskTypes;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.permission.GlobalPermission;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -74,13 +76,16 @@ public class TaskActionIT {
   private final WsActionTester ws = new WsActionTester(underTest);
 
   private ComponentDto privateProject;
-  private ComponentDto publicProject;
+  private ComponentDto publicProjectMainBranch;
+  private ProjectDto publicProject;
 
   @Before
   public void setUp() {
     privateProject = db.components().insertPrivateProject().getMainBranchComponent();
     userSession.logIn().addProjectPermission(ADMIN, privateProject);
-    publicProject = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData publicProjectData = db.components().insertPublicProject();
+    publicProject = publicProjectData.getProjectDto();
+    publicProjectMainBranch = publicProjectData.getMainBranchComponent();
   }
 
   @Test
@@ -307,8 +312,8 @@ public class TaskActionIT {
   @Test
   public void getting_project_queue_task_of_public_project_fails_with_ForbiddenException() {
     UserDto user = db.users().insertUser();
-    userSession.logIn().registerComponents(publicProject);
-    CeQueueDto task = createAndPersistQueueTask(publicProject, user);
+    userSession.logIn().registerProjects(publicProject);
+    CeQueueDto task = createAndPersistQueueTask(publicProjectMainBranch, user);
 
     String uuid = task.getUuid();
     assertThatThrownBy(() -> call(uuid))
@@ -393,8 +398,8 @@ public class TaskActionIT {
 
   @Test
   public void getting_archived_task_of_public_project_fails_with_ForbiddenException() {
-    userSession.logIn().registerComponents(publicProject);
-    CeActivityDto task = createAndPersistArchivedTask(publicProject);
+    userSession.logIn().registerProjects(publicProject);
+    CeActivityDto task = createAndPersistArchivedTask(publicProjectMainBranch);
 
     String uuid = task.getUuid();
     assertThatThrownBy(() -> call(uuid))
@@ -446,9 +451,9 @@ public class TaskActionIT {
 
   @Test
   public void get_warnings_on_public_project_archived_task_if_not_admin_fails_with_ForbiddenException() {
-    userSession.logIn().registerComponents(publicProject);
+    userSession.logIn().registerProjects(publicProject);
 
-    CeActivityDto persistArchivedTask = createAndPersistArchivedTask(publicProject);
+    CeActivityDto persistArchivedTask = createAndPersistArchivedTask(publicProjectMainBranch);
     assertThatThrownBy(() -> insertWarningsCallEndpointAndAssertWarnings(persistArchivedTask))
       .isInstanceOf(ForbiddenException.class);
   }
index e8f6908b44651ff93902be139e7b87360d2c71b4..cd6db266a8ccb92921d9963bc50f3525e34bfec2 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.api.utils.System2;
 import org.sonar.api.web.UserRole;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -213,8 +214,10 @@ public class ShowActionIT {
 
   @Test
   public void should_return_visibility_for_public_project() {
-    ComponentDto publicProject = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(publicProject);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto publicProject = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
 
     ShowWsResponse result = newRequest(publicProject.getKey());
     assertThat(result.getComponent().hasVisibility()).isTrue();
@@ -318,33 +321,37 @@ public class ShowActionIT {
     ComponentDto subview = db.components().insertSubView(portfolio1);
 
     String pullRequestKey1 = randomAlphanumeric(100);
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPrivateProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
     ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey1)
       .setNeedIssueSync(true));
     ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch1, "dir", project1.uuid()));
     ComponentDto file = db.components().insertComponent(newFileDto(project1.uuid(), branch1, directory));
-    userSession.addProjectBranchMapping(project1.uuid(), branch1);
+    userSession.addProjectBranchMapping(projectData1.projectUuid(), branch1);
 
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPrivateProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     String branchName2 = randomAlphanumeric(248);
     ComponentDto branch2 = db.components().insertProjectBranch(project2, b -> b.setBranchType(BRANCH).setNeedIssueSync(true).setKey(branchName2));
     String branchName3 = randomAlphanumeric(248);
     ComponentDto branch3 = db.components().insertProjectBranch(project2, b -> b.setBranchType(BRANCH).setNeedIssueSync(false).setKey(branchName3));
-    userSession.addProjectBranchMapping(project2.uuid(), branch2);
-    userSession.addProjectBranchMapping(project2.uuid(), branch3);
+    userSession.addProjectBranchMapping(projectData2.projectUuid(), branch2);
+    userSession.addProjectBranchMapping(projectData2.projectUuid(), branch3);
 
-    ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData3 = db.components().insertPrivateProject();
+    ComponentDto project3 = projectData3.getMainBranchComponent();
     String pullRequestKey4 = randomAlphanumeric(100);
     ComponentDto branch4 = db.components().insertProjectBranch(project3, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey4).setNeedIssueSync(false));
     ComponentDto directoryOfBranch4 = db.components().insertComponent(newDirectoryOnBranch(branch4, "dir", project3.uuid()));
     ComponentDto fileOfBranch4 = db.components().insertComponent(newFileDto(project3.uuid(), branch4, directoryOfBranch4));
     String branchName5 = randomAlphanumeric(248);
     ComponentDto branch5 = db.components().insertProjectBranch(project3, b -> b.setBranchType(BRANCH).setNeedIssueSync(false).setKey(branchName5));
-    userSession.addProjectBranchMapping(project3.uuid(), branch4);
-    userSession.addProjectBranchMapping(project3.uuid(), branch5);
+    userSession.addProjectBranchMapping(projectData3.projectUuid(), branch4);
+    userSession.addProjectBranchMapping(projectData3.projectUuid(), branch5);
 
-    userSession.addProjectPermission(UserRole.USER, project1, project2, project3);
-    userSession.registerComponents(portfolio1, portfolio2, subview, project1, project2, project3);
+    userSession.addProjectPermission(UserRole.USER, projectData1.getProjectDto(), projectData2.getProjectDto(), projectData3.getProjectDto());
+    userSession.registerPortfolios(portfolio1, portfolio2, subview);
+    userSession.registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto(), projectData3.getProjectDto());
 
     // for portfolios, sub-views need issue sync flag is set to true if any project need sync
     assertNeedIssueSyncEqual(null, null, portfolio1, true);
index 91169002ce29a7e57fb851927541787f0c8b1680..bae92500f1c3e4a8593ce5fb5b2428939d3d57d2 100644 (file)
@@ -43,7 +43,9 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.ResourceTypesRule;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -119,7 +121,7 @@ public class TreeActionIT {
 
   @Test
   public void json_example() throws IOException {
-    ComponentDto project = initJsonExampleComponents();
+    ProjectDto project = initJsonExampleComponents();
     logInWithBrowsePermission(project);
 
     String response = ws.newRequest()
@@ -134,19 +136,20 @@ public class TreeActionIT {
 
   @Test
   public void return_children() {
-    ComponentDto project = newPrivateProjectDto("project-uuid");
-    db.components().insertProjectAndSnapshot(project);
-    ComponentDto dir = newDirectory(project, "dir");
+    ProjectData projectData = db.components().insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+    ComponentDto projectMainBranch = projectData.getMainBranchComponent();
+    db.components().insertSnapshot(projectMainBranch);
+    ComponentDto dir = newDirectory(projectMainBranch, "dir");
     db.components().insertComponent(dir);
-    db.components().insertComponent(newFileDto(project, 1));
+    db.components().insertComponent(newFileDto(projectMainBranch, 1));
     for (int i = 2; i <= 9; i++) {
       db.components().insertComponent(newFileDto(dir, i));
     }
     ComponentDto directory = newDirectory(dir, "directory-path-1");
     db.components().insertComponent(directory);
-    db.components().insertComponent(newFileDto(project, directory, 10));
+    db.components().insertComponent(newFileDto(projectMainBranch, directory, 10));
     db.commit();
-    logInWithBrowsePermission(project);
+    logInWithBrowsePermission(projectData.getProjectDto());
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_STRATEGY, "children")
@@ -164,11 +167,13 @@ public class TreeActionIT {
 
   @Test
   public void return_descendants() {
-    ComponentDto project = newPrivateProjectDto("project-uuid");
-    db.components().insertProjectAndSnapshot(project);
-    ComponentDto module = newDirectory(project, "path");
+    ProjectData projectData = db.components()
+      .insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+    ComponentDto projectMainBranch = projectData.getMainBranchComponent();
+    db.components().insertSnapshot(projectMainBranch);
+    ComponentDto module = newDirectory(projectMainBranch, "path");
     db.components().insertComponent(module);
-    db.components().insertComponent(newFileDto(project, 10));
+    db.components().insertComponent(newFileDto(projectMainBranch, 10));
     for (int i = 2; i <= 9; i++) {
       db.components().insertComponent(newFileDto(module, i));
     }
@@ -176,7 +181,7 @@ public class TreeActionIT {
     db.components().insertComponent(directory);
     db.components().insertComponent(newFileDto(module, directory, 1));
     db.commit();
-    logInWithBrowsePermission(project);
+    logInWithBrowsePermission(projectData.getProjectDto());
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_STRATEGY, "all")
@@ -194,36 +199,40 @@ public class TreeActionIT {
 
   @Test
   public void filter_descendants_by_qualifier() {
-    ComponentDto project = newPrivateProjectDto("project-uuid");
-    db.components().insertProjectAndSnapshot(project);
-    db.components().insertComponent(newFileDto(project, 1));
-    db.components().insertComponent(newFileDto(project, 2));
+    ProjectData projectData = db.components()
+      .insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+    ComponentDto projectMainBranch = projectData.getMainBranchComponent();
+    db.components().insertSnapshot(projectMainBranch);
+    db.components().insertComponent(newFileDto(projectMainBranch, 1));
+    db.components().insertComponent(newFileDto(projectMainBranch, 2));
     db.commit();
-    logInWithBrowsePermission(project);
+    logInWithBrowsePermission(projectData.getProjectDto());
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_STRATEGY, "all")
       .setParam(PARAM_QUALIFIERS, FILE)
-      .setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(TreeWsResponse.class);
+      .setParam(PARAM_COMPONENT, projectMainBranch.getKey()).executeProtobuf(TreeWsResponse.class);
 
     assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-1", "file-key-2");
   }
 
   @Test
   public void return_leaves() {
-    ComponentDto project = newPrivateProjectDto("project-uuid");
-    db.components().insertProjectAndSnapshot(project);
-    db.components().insertComponent(newFileDto(project, 1));
-    db.components().insertComponent(newFileDto(project, 2));
-    ComponentDto directory = newDirectory(project, "directory-path-1");
+    ProjectData projectData = db.components()
+      .insertPrivateProject(p->p.setUuid("mainBranch-uuid").setBranchUuid("mainBranch-uuid"));
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
+    db.components().insertSnapshot(mainBranch);
+    db.components().insertComponent(newFileDto(mainBranch, 1));
+    db.components().insertComponent(newFileDto(mainBranch, 2));
+    ComponentDto directory = newDirectory(mainBranch, "directory-path-1");
     db.components().insertComponent(directory);
-    db.components().insertComponent(newFileDto(project, directory, 3));
+    db.components().insertComponent(newFileDto(mainBranch, directory, 3));
     db.commit();
-    logInWithBrowsePermission(project);
+    logInWithBrowsePermission(projectData.getProjectDto());
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_STRATEGY, "leaves")
-      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(PARAM_COMPONENT, mainBranch.getKey())
       .setParam(PARAM_QUALIFIERS, FILE).executeProtobuf(TreeWsResponse.class);
 
     assertThat(response.getComponentsCount()).isEqualTo(3);
@@ -233,33 +242,36 @@ public class TreeActionIT {
 
   @Test
   public void sort_descendants_by_qualifier() {
-    ComponentDto project = newPrivateProjectDto("project-uuid");
-    db.components().insertProjectAndSnapshot(project);
-    db.components().insertComponent(newFileDto(project, 1));
-    db.components().insertComponent(newFileDto(project, 2));
-    db.components().insertComponent(newDirectory(project, "path/directory/", "directory-uuid-1"));
+    ProjectData projectData = db.components()
+      .insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid").setKey("project-key"));
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
+    db.components().insertSnapshot(mainBranch);
+    db.components().insertComponent(newFileDto(mainBranch, 1));
+    db.components().insertComponent(newFileDto(mainBranch, 2));
+    db.components().insertComponent(newDirectory(mainBranch, "path/directory/", "directory-uuid-1"));
     db.commit();
-    logInWithBrowsePermission(project);
+    logInWithBrowsePermission(projectData.getProjectDto());
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_STRATEGY, "all")
       .setParam(Param.SORT, "qualifier, name")
-      .setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(TreeWsResponse.class);
+      .setParam(PARAM_COMPONENT, mainBranch.getKey()).executeProtobuf(TreeWsResponse.class);
 
-    assertThat(response.getComponentsList()).extracting("key").containsExactly("KEY_project-uuid:directory-uuid-1", "file-key-1", "file-key-2");
+    assertThat(response.getComponentsList()).extracting("key").containsExactly("project-key:directory-uuid-1", "file-key-1", "file-key-2");
   }
 
   @Test
   public void project_reference_from_portfolio() {
     ComponentDto view = ComponentTesting.newPortfolio("view-uuid");
     db.components().insertPortfolioAndSnapshot(view);
-    ComponentDto project = newPrivateProjectDto("project-uuid-1").setName("project-name").setKey("project-key-1");
-    db.components().insertProjectAndSnapshot(project);
-    db.components().insertComponent(newProjectCopy("project-uuid-1-copy", project, view));
+    ProjectData project = db.components().insertPrivateProject(p->p.setUuid("project-uuid-1").setBranchUuid("project-uuid-1").setName("project-name").setKey("project-key-1"));
+    db.components().insertSnapshot(project.getMainBranchComponent());
+    db.components().insertComponent(newProjectCopy("project-uuid-1-copy", project.getMainBranchComponent(), view));
     db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"));
     db.commit();
     userSession.logIn()
-      .registerComponents(view, project);
+      .registerPortfolios(view)
+      .registerProjects(project.getProjectDto());
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_STRATEGY, "children")
@@ -275,13 +287,15 @@ public class TreeActionIT {
   public void project_branch_reference_from_portfolio() {
     ComponentDto view = ComponentTesting.newPortfolio("view-uuid");
     db.components().insertPortfolioAndSnapshot(view);
-    ComponentDto project = newPrivateProjectDto("project-uuid-1").setName("project-name").setKey("project-key-1");
-    db.components().insertProjectAndSnapshot(project);
-    db.components().insertComponent(newProjectBranchCopy("project-uuid-1-copy", project, view, "branch1"));
+    ProjectData projectData = db.components().insertPrivateProject(p->p.setUuid("project-uuid-1").setBranchUuid("project-uuid-1").setName("project-name").setKey("project-key-1"));
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
+    db.components().insertSnapshot(mainBranch);
+    db.components().insertComponent(newProjectBranchCopy("project-uuid-1-copy", mainBranch, view, "branch1"));
     db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"));
     db.commit();
     userSession.logIn()
-      .registerComponents(view, project);
+      .registerPortfolios(view)
+      .registerProjects(projectData.getProjectDto());
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_STRATEGY, "children")
@@ -298,16 +312,17 @@ public class TreeActionIT {
     String appBranchName = "app-branch";
     String projectBranchName = "project-branch";
 
-    ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app-key")).getMainBranchComponent();
-    ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey(appBranchName));
+    ProjectData applicationData = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app-key"));
+    ProjectDto application = applicationData.getProjectDto();
+    ComponentDto applicationBranch = db.components().insertProjectBranch(applicationData.getMainBranchComponent(), a -> a.setKey(appBranchName));
 
     ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key")).getMainBranchComponent();
     ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey(projectBranchName));
     ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch)
-      .setKey(applicationBranch.getKey() + project.getKey()).setMainBranchProjectUuid(application.uuid()));
+      .setKey(applicationBranch.getKey() + project.getKey()).setMainBranchProjectUuid(application.getUuid()));
 
     logInWithBrowsePermission(application);
-    userSession.addProjectBranchMapping(application.uuid(), applicationBranch);
+    userSession.addProjectBranchMapping(application.getUuid(), applicationBranch);
 
     TreeWsResponse result = ws.newRequest()
       .setParam(MeasuresWsParameters.PARAM_COMPONENT, applicationBranch.getKey())
@@ -324,7 +339,7 @@ public class TreeActionIT {
 
   @Test
   public void response_is_empty_on_provisioned_projects() {
-    ComponentDto project = db.components().insertPrivateProject("project-uuid").getMainBranchComponent();
+    ProjectDto project = db.components().insertPrivateProject("project-uuid").getProjectDto();
     logInWithBrowsePermission(project);
 
     TreeWsResponse response = ws.newRequest()
@@ -339,13 +354,15 @@ public class TreeActionIT {
 
   @Test
   public void return_projects_composing_a_view() {
-    ComponentDto project = newPrivateProjectDto("project-uuid");
-    db.components().insertProjectAndSnapshot(project);
+    ProjectData projectData = db.components().insertPrivateProject(p -> p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+    ComponentDto project = projectData.getMainBranchComponent();
+    db.components().insertSnapshot(project);
     ComponentDto view = ComponentTesting.newPortfolio("view-uuid");
     db.components().insertPortfolioAndSnapshot(view);
     ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view));
     userSession.logIn()
-      .registerComponents(project, view);
+      .registerProjects(projectData.getProjectDto())
+      .registerPortfolios(view);
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, view.getKey())
@@ -491,9 +508,10 @@ public class TreeActionIT {
 
   @Test
   public void fail_when_base_component_is_removed() {
-    ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
-    db.components().insertComponent(ComponentTesting.newFileDto(project).setKey("file-key").setEnabled(false));
-    logInWithBrowsePermission(project);
+
+    ProjectData projectData = db.components().insertPrivateProject(p->p.setKey("file-key").setEnabled(false));
+    db.components().insertSnapshot(projectData.getMainBranchComponent());
+    logInWithBrowsePermission(projectData.getProjectDto());
 
     TestRequest request = ws.newRequest()
       .setParam(PARAM_COMPONENT, "file-key");
@@ -535,14 +553,14 @@ public class TreeActionIT {
     return newFileDto(moduleOrProject, null, i);
   }
 
-  private ComponentDto initJsonExampleComponents() throws IOException {
-    ComponentDto project = db.components().insertPrivateProject(c -> c.setUuid("MY_PROJECT_ID")
+  private ProjectDto initJsonExampleComponents() throws IOException {
+    ProjectData projectData = db.components().insertPrivateProject(c -> c.setUuid("MY_PROJECT_ID")
         .setDescription("MY_PROJECT_DESCRIPTION")
         .setKey("MY_PROJECT_KEY")
         .setName("Project Name")
         .setBranchUuid("MY_PROJECT_ID"),
-      p -> p.setTagsString("abc,def")).getMainBranchComponent();
-    db.components().insertSnapshot(project);
+      p -> p.setTagsString("abc,def"));
+    db.components().insertSnapshot(projectData.getMainBranchComponent());
 
     Date now = new Date();
     JsonParser jsonParser = new JsonParser();
@@ -552,7 +570,7 @@ public class TreeActionIT {
       JsonElement componentAsJsonElement = components.get(i);
       JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject();
       String uuid = format("child-component-uuid-%d", i);
-      db.components().insertComponent(newChildComponent(uuid, project, project)
+      db.components().insertComponent(newChildComponent(uuid, projectData.getMainBranchComponent(), projectData.getMainBranchComponent())
         .setKey(getJsonField(componentAsJsonObject, "key"))
         .setName(getJsonField(componentAsJsonObject, "name"))
         .setLanguage(getJsonField(componentAsJsonObject, "language"))
@@ -563,7 +581,7 @@ public class TreeActionIT {
         .setCreatedAt(now));
     }
     db.commit();
-    return project;
+    return projectData.getProjectDto();
   }
 
   @CheckForNull
@@ -572,20 +590,20 @@ public class TreeActionIT {
     return jsonElement == null ? null : jsonElement.getAsString();
   }
 
-  private void logInWithBrowsePermission(ComponentDto project) {
+  private void logInWithBrowsePermission(ProjectDto project) {
     userSession.logIn().addProjectPermission(UserRole.USER, project);
   }
 
   @Test
   public void doHandle_whenPassingUnsupportedQualifier_ShouldThrowIllegalArgumentException() {
-    ComponentDto project = newPrivateProjectDto("project-uuid");
-    db.components().insertProjectAndSnapshot(project);
+    ProjectData project = db.components().insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+    db.components().insertSnapshot(project.getMainBranchComponent());
     db.commit();
-    logInWithBrowsePermission(project);
+    logInWithBrowsePermission(project.getProjectDto());
 
     TestRequest testRequest = ws.newRequest()
       .setParam(PARAM_QUALIFIERS, "BRC")
-      .setParam(PARAM_COMPONENT, project.getKey());
+      .setParam(PARAM_COMPONENT, project.getProjectDto().getKey());
 
     assertThatThrownBy(testRequest::execute).isInstanceOf(IllegalArgumentException.class)
       .hasMessage("Value of parameter 'qualifiers' (BRC) must be one of: [UTS, FIL, DIR, TRK]");
index 94a7792e4a4d4b4a9b077ea65ad91656c031315a..b28fc33bb0dc36712dfc5b17e5d8f6673564b20a 100644 (file)
@@ -40,6 +40,7 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -176,8 +177,10 @@ public class AddCommentActionIT {
 
   @Test
   public void fails_with_ForbiddenException_if_project_is_private_and_not_allowed() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = dbTester.rules().insertHotspotRule();
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@@ -191,8 +194,10 @@ public class AddCommentActionIT {
 
   @Test
   public void succeeds_on_public_project() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = dbTester.rules().insertHotspotRule();
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@@ -203,8 +208,11 @@ public class AddCommentActionIT {
 
   @Test
   public void succeeds_on_private_project_with_permission() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project).addProjectPermission(UserRole.USER, project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.USER, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = dbTester.rules().insertHotspotRule();
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@@ -218,8 +226,10 @@ public class AddCommentActionIT {
   public void persists_comment_if_hotspot_status_changes_and_transition_done(String currentStatus, @Nullable String currentResolution) {
     long now = RANDOM.nextInt(232_323);
     when(system2.now()).thenReturn(now);
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = dbTester.rules().insertHotspotRule();
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(currentStatus).setResolution(currentResolution));
index b30bbd2e0b2934ada61a94b98adfa4aa25d3e2a7..81a4677452c7f00548f59c7ec422a220b2a0d56a 100644 (file)
@@ -48,6 +48,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.rule.RuleTesting;
@@ -134,12 +135,13 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenAssignedForPublicProject() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
     UserDto userDto = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(userDto).registerComponents(project);
+    userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
 
     UserDto assignee = insertUser(randomAlphanumeric(15));
     when(issueFieldsSetter.assign(eq(hotspot.toDefaultIssue()), userMatcher(assignee), any(IssueChangeContext.class))).thenReturn(true);
@@ -151,14 +153,15 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenUnassignedForPublicProject() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     UserDto assignee = insertUser(randomAlphanumeric(15));
 
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setAssigneeUuid(assignee.getUuid()));
 
     UserDto userDto = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(userDto).registerComponents(project);
+    userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
     when(issueFieldsSetter.assign(eq(hotspot.toDefaultIssue()), isNull(), any(IssueChangeContext.class))).thenReturn(true);
 
     executeRequest(hotspot, null, null);
@@ -168,12 +171,13 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenMyselfAssignedForPublicProject() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
     UserDto me = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(me).registerComponents(project);
+    userSessionRule.logIn(me).registerProjects(projectData.getProjectDto());
 
     when(issueFieldsSetter.assign(eq(hotspot.toDefaultIssue()), userMatcher(me), any(IssueChangeContext.class))).thenReturn(true);
 
@@ -184,10 +188,11 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenMyselfUnassignedForPublicProject() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     UserDto me = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(me).registerComponents(project);
+    userSessionRule.logIn(me).registerProjects(projectData.getProjectDto());
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setAssigneeUuid(me.getUuid()));
 
     when(issueFieldsSetter.assign(eq(hotspot.toDefaultIssue()), isNull(), any(IssueChangeContext.class))).thenReturn(true);
@@ -301,13 +306,13 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenAssignHotspotWithComment() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
     UserDto userDto = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(userDto).registerComponents(project);
+    userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
 
     UserDto assignee = insertUser(randomAlphanumeric(15));
 
@@ -321,12 +326,13 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenAssignTwiceSameUserHotspotDoesNotReload_shouldFail() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
     UserDto userDto = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(userDto).registerComponents(project);
+    userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
 
     UserDto assignee = insertUser(randomAlphanumeric(15));
 
@@ -340,12 +346,13 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenBranchTypeIsBranch_shouldDistributeEvents() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
     UserDto userDto = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(userDto).registerComponents(project);
+    userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
 
     UserDto assignee = insertUser(randomAlphanumeric(15));
     when(branchDto.getBranchType()).thenReturn(BranchType.BRANCH);
@@ -357,12 +364,13 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenBranchIsPullRequest_shouldNotDistributeEvents() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
     UserDto userDto = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(userDto).registerComponents(project);
+    userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
 
     UserDto assignee = insertUser(randomAlphanumeric(15));
     when(branchDto.getBranchType()).thenReturn(BranchType.PULL_REQUEST);
@@ -375,12 +383,13 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenAssigningToNonExistingUser_shouldFail() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
     UserDto userDto = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(userDto).registerComponents(project);
+    userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
 
     String notExistingUserLogin = randomAlphanumeric(10);
 
@@ -392,8 +401,8 @@ public class AssignActionIT {
   @Test
   @UseDataProvider("allIssueStatusesAndResolutionsThatThrowOnAssign")
   public void wsExecution_whenAssigningToUserIfForbidden_shouldFail(String status, String resolution) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> {
       h.setStatus(status);
@@ -401,7 +410,7 @@ public class AssignActionIT {
     });
 
     UserDto userDto = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(userDto).registerComponents(project);
+    userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
 
     String login = userSessionRule.getLogin();
     assertThatThrownBy(() -> executeRequest(hotspot, login, null))
@@ -422,7 +431,8 @@ public class AssignActionIT {
   @Test
   @UseDataProvider("allIssueStatusesAndResolutionsThatDoNotThrowOnAssign")
   public void wsExecution_whenAssigningToUserIfAllowed_shouldNotFail(String status, String resolution) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> {
       h.setStatus(status);
@@ -430,7 +440,7 @@ public class AssignActionIT {
     });
 
     UserDto userDto = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn(userDto).registerComponents(project);
+    userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
 
     String login = userSessionRule.getLogin();
     assertThatNoException().isThrownBy(() -> executeRequest(hotspot, login, null));
@@ -478,10 +488,10 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenHotspotDoesNotExist_shouldFail() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     UserDto me = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn().registerComponents(project);
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto());
 
     String notExistingHotspotKey = randomAlphanumeric(10);
     String login = me.getLogin();
@@ -493,7 +503,8 @@ public class AssignActionIT {
   @Test
   @UseDataProvider("allRuleTypesWithStatusesExceptHotspot")
   public void wsExecution_whenAssigningToNonexistantIssue_shouldFail(RuleType ruleType, String status) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(ruleType);
     IssueDto issue = dbTester.issues().insertIssue(rule, project, file, i -> i
@@ -501,7 +512,7 @@ public class AssignActionIT {
       .setType(ruleType));
 
     UserDto me = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn().registerComponents(project);
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto());
 
     String login = me.getLogin();
     assertThatThrownBy(() -> executeRequest(issue, login, null))
@@ -527,12 +538,13 @@ public class AssignActionIT {
 
   @Test
   public void wsExecution_whenHotspotIsClosed_shouldFailWithNotFoundException() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto issue = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_CLOSED));
     UserDto me = insertUser(randomAlphanumeric(10));
-    userSessionRule.logIn().registerComponents(project);
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto());
 
     String login = me.getLogin();
     assertThatThrownBy(() -> executeRequest(issue, login, null))
index 480401f1f7f2da7dd265cfe6cb8d37528d7472e1..1d1def56ee8ef28e02f3e60f6feaa69cef0c4a41 100644 (file)
@@ -48,6 +48,7 @@ import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.issue.IssueTesting;
 import org.sonar.db.project.ProjectDto;
@@ -309,9 +310,11 @@ public class ChangeStatusActionIT {
   @Test
   @UseDataProvider("anyPublicProjectPermissionButHotspotAdmin")
   public void fails_with_ForbiddenException_if_project_is_public_and_user_has_no_HotspotAdmin_permission_on_it(String permission) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(permission, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(permission, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
@@ -339,9 +342,11 @@ public class ChangeStatusActionIT {
   @Test
   @UseDataProvider("anyPrivateProjectPermissionButHotspotAdmin")
   public void fails_with_ForbiddenException_if_project_is_private_and_has_no_IssueAdmin_permission_on_it(String permission) {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(permission, project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(permission, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
@@ -371,9 +376,11 @@ public class ChangeStatusActionIT {
   @Test
   @UseDataProvider("validStatusAndResolutions")
   public void succeeds_on_public_project_with_HotspotAdmin_permission(String status, @Nullable String resolution) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
@@ -383,9 +390,11 @@ public class ChangeStatusActionIT {
   @Test
   @UseDataProvider("validStatusAndResolutions")
   public void succeeds_on_private_project_with_HotspotAdmin_permission(String status, @Nullable String resolution) {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
 
@@ -395,9 +404,11 @@ public class ChangeStatusActionIT {
   @Test
   @UseDataProvider("validStatusAndResolutions")
   public void no_effect_and_success_if_hotspot_already_has_specified_status_and_resolution(String status, @Nullable String resolution) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(status).setResolution(resolution));
 
@@ -411,9 +422,11 @@ public class ChangeStatusActionIT {
   public void success_to_change_hostpot_to_review_into_reviewed_status(String resolution, String expectedTransitionKey, boolean transitionDone) {
     long now = RANDOM.nextInt(232_323);
     when(system2.now()).thenReturn(now);
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(STATUS_TO_REVIEW).setResolution(null));
     when(transitionService.doTransition(any(), any(), any())).thenReturn(transitionDone);
@@ -443,9 +456,11 @@ public class ChangeStatusActionIT {
 
   @Test
   public void wsExecution_whenOnMainBranch_shouldDistributeEvents() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     when(branchDto.getBranchType()).thenReturn(BranchType.BRANCH);
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
@@ -468,8 +483,9 @@ public class ChangeStatusActionIT {
     IssueDto hotspot = dbTester.issues().insertHotspot(branchComponentDto, file);
     when(transitionService.doTransition(any(), any(), any())).thenReturn(true);
 
-    userSessionRule.logIn().registerComponents(projectComponentDto)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectComponentDto, branchComponentDto);
+    userSessionRule.logIn().registerProjects(project)
+      .registerBranches(branch)
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
     newRequest(hotspot, STATUS_REVIEWED, RESOLUTION_FIXED, NO_COMMENT).execute();
 
     verify(hotspotChangeEventService).distributeHotspotChangedEvent(eq(branchDto.getProjectUuid()), any(HotspotChangedEvent.class));
@@ -477,9 +493,11 @@ public class ChangeStatusActionIT {
 
   @Test
   public void wsExecution_whenBranchTypeIsPullRequest_shouldNotDistributeEvents() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     when(branchDto.getBranchType()).thenReturn(BranchType.PULL_REQUEST);
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
@@ -507,9 +525,11 @@ public class ChangeStatusActionIT {
   public void success_to_change_reviewed_hotspot_back_to_to_review(String resolution, boolean transitionDone) {
     long now = RANDOM.nextInt(232_323);
     when(system2.now()).thenReturn(now);
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
 
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(STATUS_REVIEWED).setResolution(resolution));
@@ -556,9 +576,11 @@ public class ChangeStatusActionIT {
     String newStatus, @Nullable String newResolution, boolean transitionDone) {
     long now = RANDOM.nextInt(232_323);
     when(system2.now()).thenReturn(now);
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
 
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(currentStatus).setResolution(currentResolution));
@@ -613,9 +635,11 @@ public class ChangeStatusActionIT {
   public void do_not_persist_comment_if_no_status_change(String status, @Nullable String resolution) {
     long now = RANDOM.nextInt(232_323);
     when(system2.now()).thenReturn(now);
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(status).setResolution(resolution));
     String comment = randomAlphabetic(12);
index 8d6165bb7c831237d8eadefeaace9f017cfbabed..769104cb79febcf8dd05d5886bb46d4ebb2e29c5 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.user.UserDto;
@@ -91,8 +92,8 @@ public class DeleteCommentActionIT {
   public void delete_comment_from_hotspot_public_project() {
     UserDto userAddingComment = dbTester.users().insertUser();
 
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     IssueDto hotspot = dbTester.issues().insertHotspot(h -> h.setProject(project));
     IssueChangeDto comment = dbTester.issues().insertComment(hotspot, userAddingComment, "Some comment");
 
@@ -100,7 +101,7 @@ public class DeleteCommentActionIT {
       .isNotEmpty();
 
     userSessionRule.logIn(userAddingComment);
-    userSessionRule.registerComponents(project);
+    userSessionRule.registerProjects(projectData.getProjectDto());
 
     TestRequest request = newRequest(comment.getKey());
 
@@ -157,13 +158,11 @@ public class DeleteCommentActionIT {
     UserDto userTryingToDelete = dbTester.users().insertUser();
     UserDto userWithHotspotComment = dbTester.users().insertUser();
 
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     IssueDto hotspot = dbTester.issues().insertHotspot(h -> h.setProject(project));
     IssueChangeDto comment = dbTester.issues().insertComment(hotspot, userWithHotspotComment, "Some comment");
-
-    userSessionRule.logIn(userTryingToDelete)
-      .registerComponents(project);
+    userSessionRule.logIn(userTryingToDelete).registerProjects(projectData.getProjectDto());
 
     TestRequest request = newRequest(comment.getKey());
 
index 897596f58de2bb2e6364ce77e6dbe1cbbc2a5b54..d942876c457bcb9b87768020f163195043b84c56 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.api.web.UserRole;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.user.UserDto;
@@ -100,13 +101,13 @@ public class EditCommentActionIT {
   public void edit_comment_from_hotspot_public_project() {
     UserDto userEditingComment = dbTester.users().insertUser();
 
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     IssueDto hotspot = dbTester.issues().insertHotspot(h -> h.setProject(project));
     IssueChangeDto comment = dbTester.issues().insertComment(hotspot, userEditingComment, "Some comment");
 
     userSessionRule.logIn(userEditingComment);
-    userSessionRule.registerComponents(project);
+    userSessionRule.registerProjects(projectData.getProjectDto());
 
     TestRequest request = newRequest(comment.getKey(), "new comment");
 
@@ -164,13 +165,11 @@ public class EditCommentActionIT {
     UserDto userTryingToEdit = dbTester.users().insertUser();
     UserDto userWithHotspotComment = dbTester.users().insertUser();
 
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     IssueDto hotspot = dbTester.issues().insertHotspot(h -> h.setProject(project));
     IssueChangeDto comment = dbTester.issues().insertComment(hotspot, userWithHotspotComment, "Some comment");
-
-    userSessionRule.logIn(userTryingToEdit)
-      .registerComponents(project);
+    userSessionRule.logIn(userTryingToEdit).registerProjects(projectData.getProjectDto());
 
     TestRequest request = newRequest(comment.getKey(), "new comment");
 
index eec9682545a7731d739c340d2429ca07e28f4f32..4db590cb6dc6f02c2b5b17ad095a157c1e9e3aab 100644 (file)
@@ -360,8 +360,10 @@ public class SearchActionIT {
 
   @Test
   public void fails_with_ForbiddenException_if_project_is_private_and_not_allowed() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     TestRequest request = newRequest(project);
 
     assertThatThrownBy(request::execute)
@@ -371,8 +373,10 @@ public class SearchActionIT {
 
   @Test
   public void fails_with_ForbiddenException_if_application_is_private_and_not_allowed() {
-    ComponentDto application = dbTester.components().insertPrivateApplication().getMainBranchComponent();
-    userSessionRule.registerComponents(application);
+    ProjectData projectData = dbTester.components().insertPrivateApplication();
+    ComponentDto application = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     TestRequest request = newRequest(application);
 
     assertThatThrownBy(request::execute)
@@ -382,8 +386,10 @@ public class SearchActionIT {
 
   @Test
   public void succeeds_on_public_project() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
 
     SearchWsResponse response = newRequest(project)
       .executeProtobuf(SearchWsResponse.class);
@@ -394,8 +400,9 @@ public class SearchActionIT {
 
   @Test
   public void succeeds_on_public_application() {
-    ComponentDto application = dbTester.components().insertPublicApplication().getMainBranchComponent();
-    userSessionRule.registerApplication(application);
+    ProjectData applicationData = dbTester.components().insertPublicApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
+    userSessionRule.registerApplication(applicationData.getProjectDto());
 
     SearchWsResponse response = newRequest(application)
       .executeProtobuf(SearchWsResponse.class);
@@ -406,8 +413,10 @@ public class SearchActionIT {
 
   @Test
   public void succeeds_on_private_project_with_permission() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(USER, project);
 
     SearchWsResponse response = newRequest(project)
@@ -419,8 +428,9 @@ public class SearchActionIT {
 
   @Test
   public void succeeds_on_private_application_with_permission() {
-    ComponentDto application = dbTester.components().insertPrivateApplication().getMainBranchComponent();
-    userSessionRule.logIn().registerApplication(application).addProjectPermission(USER, application);
+    ProjectData applicationData = dbTester.components().insertPrivateApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
+    userSessionRule.logIn().registerApplication(applicationData.getProjectDto()).addProjectPermission(USER, applicationData.getProjectDto());
 
     SearchWsResponse response = newRequest(application)
       .executeProtobuf(SearchWsResponse.class);
@@ -431,8 +441,10 @@ public class SearchActionIT {
 
   @Test
   public void does_not_fail_if_rule_of_hotspot_does_not_exist_in_DB() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     indexPermissions();
     IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10))
@@ -449,7 +461,7 @@ public class SearchActionIT {
       .executeProtobuf(SearchWsResponse.class);
 
     assertThat(response.getHotspotsList())
-      .extracting(Hotspots.SearchWsResponse.Hotspot::getKey)
+      .extracting(SearchWsResponse.Hotspot::getKey)
       .containsOnly(Arrays.stream(hotspots)
         .map(IssueDto::getKey)
         .filter(key -> !key.equals(hotspotWithoutRule.getKey()))
@@ -458,8 +470,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_no_hotspot_component_nor_rule_when_project_has_no_hotspot() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     Arrays.stream(RuleType.values())
@@ -478,8 +492,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspot_components_when_project_has_hotspots() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     ComponentDto fileWithHotspot = dbTester.components().insertComponent(newFileDto(project));
@@ -510,8 +526,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_single_component_when_all_hotspots_are_on_project() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10))
       .mapToObj(i -> {
@@ -525,7 +543,7 @@ public class SearchActionIT {
       .executeProtobuf(SearchWsResponse.class);
 
     assertThat(response.getHotspotsList())
-      .extracting(Hotspots.SearchWsResponse.Hotspot::getKey)
+      .extracting(SearchWsResponse.Hotspot::getKey)
       .containsOnly(Arrays.stream(hotspots).map(IssueDto::getKey).toArray(String[]::new));
     assertThat(response.getComponentsList())
       .extracting(Component::getKey)
@@ -534,9 +552,11 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_of_specified_project() {
-    ComponentDto project1 = dbTester.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto project2 = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project1, project2);
+    ProjectData projectData1 = dbTester.components().insertPublicProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
+    ProjectData projectData2 = dbTester.components().insertPublicProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
+    userSessionRule.registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto());
     indexPermissions();
     ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
     ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2));
@@ -572,8 +592,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_only_hotspots_to_review_or_reviewed_of_project() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto[] hotspots = STATUSES.stream()
@@ -598,28 +620,28 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_of_specified_application() {
-    ComponentDto application1 = dbTester.components().insertPublicApplication().getMainBranchComponent();
-    ComponentDto application2 = dbTester.components().insertPublicApplication().getMainBranchComponent();
-    ComponentDto project1 = dbTester.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto project2 = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData application1 = dbTester.components().insertPublicApplication();
+    ProjectData application2 = dbTester.components().insertPublicApplication();
+    ProjectData project1 = dbTester.components().insertPublicProject();
+    ProjectData project2 = dbTester.components().insertPublicProject();
     dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project1, application1));
     dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project2, application2));
     indexViews();
-    userSessionRule.registerApplication(application1, project1)
-      .registerApplication(application2, project2);
+    userSessionRule.registerApplication(application1.getProjectDto(), project1.getProjectDto())
+      .registerApplication(application2.getProjectDto(), project2.getProjectDto());
     indexPermissions();
-    ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
-    ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2));
+    ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1.getMainBranchComponent()));
+    ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2.getMainBranchComponent()));
     IssueDto[] hotspots2 = IntStream.range(0, 1 + RANDOM.nextInt(10))
       .mapToObj(i -> {
         RuleDto rule = newRule(SECURITY_HOTSPOT);
-        insertHotspot(project1, file1, rule);
-        return insertHotspot(project2, file2, rule);
+        insertHotspot(project1.getMainBranchComponent(), file1, rule);
+        return insertHotspot(project2.getMainBranchComponent(), file2, rule);
       })
       .toArray(IssueDto[]::new);
     indexIssues();
 
-    SearchWsResponse responseApplication1 = newRequest(application1)
+    SearchWsResponse responseApplication1 = newRequest(application1.getMainBranchComponent())
       .executeProtobuf(SearchWsResponse.class);
 
     assertThat(responseApplication1.getHotspotsList())
@@ -627,9 +649,9 @@ public class SearchActionIT {
       .doesNotContainAnyElementsOf(Arrays.stream(hotspots2).map(IssueDto::getKey).collect(toList()));
     assertThat(responseApplication1.getComponentsList())
       .extracting(Component::getKey)
-      .containsOnly(project1.getKey(), file1.getKey());
+      .containsOnly(project1.projectKey(), file1.getKey());
 
-    SearchWsResponse responseApplication2 = newRequest(application2)
+    SearchWsResponse responseApplication2 = newRequest(application2.getMainBranchComponent())
       .executeProtobuf(SearchWsResponse.class);
 
     assertThat(responseApplication2.getHotspotsList())
@@ -637,19 +659,22 @@ public class SearchActionIT {
       .containsOnly(Arrays.stream(hotspots2).map(IssueDto::getKey).toArray(String[]::new));
     assertThat(responseApplication2.getComponentsList())
       .extracting(Component::getKey)
-      .containsOnly(project2.getKey(), file2.getKey());
+      .containsOnly(project2.projectKey(), file2.getKey());
   }
 
   @Test
   public void returns_hotspots_of_specified_application_branch() {
-    ComponentDto application = dbTester.components().insertPublicApplication().getMainBranchComponent();
+    ProjectData applicationData = dbTester.components().insertPublicApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
     ComponentDto applicationBranch = dbTester.components().insertProjectBranch(application, b -> b.setKey("appBranch"));
-    ComponentDto project1 = dbTester.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto project2 = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData1 = dbTester.components().insertPublicProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
+    ProjectData projectData2 = dbTester.components().insertPublicProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project1, application));
     dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project2, applicationBranch));
     indexViews();
-    userSessionRule.registerApplication(application, applicationBranch, project1, project2);
+    userSessionRule.registerApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
     indexPermissions();
     ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
     ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2));
@@ -686,8 +711,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspot_of_branch_or_pullRequest() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey("branch"));
     ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST).setKey("prKey"));
@@ -737,8 +764,9 @@ public class SearchActionIT {
   @Test
   @UseDataProvider("onlyMineParamValues")
   public void returns_hotspots_of_specified_project_assigned_to_current_user_if_only_mine_is_set(String onlyMineParameter, boolean shouldFilter) {
-    ComponentDto project1 = dbTester.components().insertPublicProject().getMainBranchComponent();
-    String assigneeUuid = this.userSessionRule.logIn().registerComponents(project1).getUuid();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project1 = projectData.getMainBranchComponent();
+    String assigneeUuid = this.userSessionRule.logIn().registerProjects(projectData.getProjectDto()).getUuid();
 
     indexPermissions();
     ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
@@ -786,9 +814,10 @@ public class SearchActionIT {
 
   @Test
   public void fail_if_hotspots_provided_with_onlyMine_param() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
 
-    userSessionRule.registerComponents(project);
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(USER, project);
 
     TestRequest request = actionTester.newRequest()
@@ -815,8 +844,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotpots_with_any_status_if_no_status_nor_resolution_parameter() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     List<IssueDto> hotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file)
@@ -833,8 +864,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotpots_reviewed_as_safe_and_fixed_if_status_is_REVIEWED_and_resolution_is_not_set() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     List<IssueDto> reviewedHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file)
@@ -852,8 +885,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotpots_reviewed_as_safe_if_status_is_REVIEWED_and_resolution_is_SAFE() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     List<IssueDto> safeHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file)
@@ -871,8 +906,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotpots_reviewed_as_fixed_if_status_is_REVIEWED_and_resolution_is_FIXED() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     List<IssueDto> fixedHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file)
@@ -890,8 +927,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_only_unresolved_hotspots_when_status_is_TO_REVIEW() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -932,8 +971,10 @@ public class SearchActionIT {
   @Test
   @UseDataProvider("validStatusesAndResolutions")
   public void returns_fields_of_hotspot(String status, @Nullable String resolution) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -981,8 +1022,10 @@ public class SearchActionIT {
   @Test
   @UseDataProvider("allSQCategories")
   public void returns_SQCategory_and_VulnerabilityProbability_of_rule(Set<String> securityStandards, SQCategory expected) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT, t -> t.setSecurityStandards(securityStandards));
@@ -993,7 +1036,7 @@ public class SearchActionIT {
       .executeProtobuf(SearchWsResponse.class);
 
     assertThat(response.getHotspotsList()).hasSize(1);
-    Hotspots.SearchWsResponse.Hotspot actual = response.getHotspots(0);
+    SearchWsResponse.Hotspot actual = response.getHotspots(0);
     assertThat(actual.getSecurityCategory()).isEqualTo(expected.getKey());
     assertThat(actual.getVulnerabilityProbability()).isEqualTo(expected.getVulnerability().name());
   }
@@ -1014,8 +1057,10 @@ public class SearchActionIT {
 
   @Test
   public void does_not_fail_when_hotspot_has_none_of_the_nullable_fields() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -1042,8 +1087,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_details_of_components() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto directory = dbTester.components().insertComponent(newDirectory(project, "donut/acme"));
     ComponentDto directory2 = dbTester.components().insertComponent(newDirectory(project, "foo/bar"));
@@ -1091,10 +1138,11 @@ public class SearchActionIT {
 
   @Test
   public void returns_branch_field_of_components_of_branch() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    userSessionRule.registerComponents(project, branch);
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto directory = dbTester.components().insertComponent(newDirectoryOnBranch(branch, "donut/acme", project.uuid()));
     ComponentDto file = dbTester.components().insertComponent(newFileDto(branch, project.uuid()));
@@ -1127,11 +1175,12 @@ public class SearchActionIT {
 
   @Test
   public void returns_pullRequest_field_of_components_of_pullRequest() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     String pullRequestKey = randomAlphanumeric(100);
     ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST)
       .setKey(pullRequestKey));
-    userSessionRule.registerComponents(project, pullRequest);
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto directory = dbTester.components().insertComponent(newDirectoryOnBranch(pullRequest, "donut/acme", project.uuid()));
     ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest, project.uuid()));
@@ -1164,8 +1213,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_ordered_by_vulnerabilityProbability_score_then_rule_uuid() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     List<IssueDto> hotspots = Arrays.stream(SQCategory.values())
@@ -1201,8 +1252,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_ordered_by_file_path_then_line_then_key() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project).setPath("b/c/a"));
     ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project).setPath("b/c/b"));
@@ -1234,8 +1287,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspot_with_secondary_locations() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     ComponentDto anotherFile = dbTester.components().insertComponent(newFileDto(project));
@@ -1279,8 +1334,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_first_page_with_100_results_by_default() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -1304,8 +1361,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_specified_page_with_100_results_by_default() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -1315,8 +1374,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_specified_page_with_specified_number_of_results() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -1372,8 +1433,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_empty_if_none_of_hotspot_keys_exist() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -1391,8 +1454,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_specified_hotspots() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -1414,8 +1479,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_specified_sonarsourceSecurity_category() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@@ -1436,8 +1503,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_specified_cwes() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@@ -1458,8 +1527,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_specified_owaspTop10_category() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@@ -1480,8 +1551,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_specified_pciDss_category() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@@ -1511,8 +1584,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_specified_owaspAsvs_category() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@@ -1542,8 +1617,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_specified_owaspAsvs_level() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@@ -1597,8 +1674,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_specified_owasp2021Top10_category() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@@ -1619,8 +1698,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_specified_sansTop25_category() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@@ -1641,8 +1722,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_specified_files() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project));
     ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project));
@@ -1663,8 +1746,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_on_the_leak_period_when_inNewCodePeriod_is_true() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     long periodDate = 800_996_999_332L;
@@ -1718,8 +1803,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_on_the_leak_period_when_inNewCodePeriod_is_true_and_branch_uses_reference_branch() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     dbTester.components().insertSnapshot(project, t -> t.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
@@ -1762,8 +1849,10 @@ public class SearchActionIT {
     long referenceDate = 800_996_999_332L;
 
     system2.setNow(referenceDate + 10_000);
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(referenceDate).setLast(false));
@@ -1793,9 +1882,10 @@ public class SearchActionIT {
     long referenceDate = 800_996_999_332L;
 
     system2.setNow(referenceDate + 10_000);
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto pr = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey("pr"));
-    userSessionRule.registerComponents(project);
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(pr, project.uuid()));
     dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(referenceDate).setLast(true));
@@ -1926,11 +2016,13 @@ public class SearchActionIT {
 
   @Test
   public void verify_response_example() {
-    ComponentDto project = dbTester.components().insertPublicProject(componentDto -> componentDto
+    ProjectData projectData = dbTester.components().insertPublicProject(componentDto -> componentDto
       .setName("test-project")
       .setLongName("test-project")
-      .setKey("com.sonarsource:test-project")).getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+      .setKey("com.sonarsource:test-project"));
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto fileWithHotspot = dbTester.components().insertComponent(newFileDto(project)
       .setKey("com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java")
@@ -1964,8 +2056,10 @@ public class SearchActionIT {
 
   @Test
   public void returns_hotspots_with_ruleKey() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     indexPermissions();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule1 = newRule(SECURITY_HOTSPOT);
index 88a33c88b68b3d4b60d604945f3b743b78b18d72..4a7e254b19c977bf70fe8f1169d36b7c8c43a3fe 100644 (file)
@@ -52,6 +52,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.protobuf.DbCommons.TextRange;
 import org.sonar.db.protobuf.DbIssues;
@@ -192,8 +193,10 @@ public class ShowActionIT {
 
   @Test
   public void fails_with_ForbiddenException_if_project_is_private_and_not_allowed() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@@ -206,7 +209,8 @@ public class ShowActionIT {
 
   @Test
   public void succeeds_on_hotspot_with_flow() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     ComponentDto anotherFile = dbTester.components().insertComponent(newFileDto(project));
     DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder()
@@ -239,8 +243,7 @@ public class ShowActionIT {
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     var hotspot = dbTester.issues().insertHotspot(rule, project, file, i -> i.setLocations(locations.build()));
     mockChangelogAndCommentsFormattingContext();
-
-    userSessionRule.registerComponents(project);
+    userSessionRule.registerProjects(projectData.getProjectDto());
 
     Hotspots.ShowWsResponse response = newRequest(hotspot)
       .executeProtobuf(Hotspots.ShowWsResponse.class);
@@ -265,8 +268,10 @@ public class ShowActionIT {
 
   @Test
   public void succeeds_on_public_project() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@@ -280,8 +285,10 @@ public class ShowActionIT {
 
   @Test
   public void succeeds_on_private_project_with_permission() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -296,8 +303,10 @@ public class ShowActionIT {
 
   @Test
   public void return_canChangeStatus_false_on_public_project_when_anonymous() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@@ -312,8 +321,10 @@ public class ShowActionIT {
   @Test
   @UseDataProvider("allPublicProjectPermissionsButSECURITYHOTSPOT_ADMIN")
   public void return_canChangeStatus_false_on_public_project_when_authenticated_without_SECURITYHOTSPOT_ADMIN_permission(@Nullable String permission) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.logIn().registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.logIn().registerProjects(projectData.getProjectDto());
     if (permission != null) {
       userSessionRule.addProjectPermission(permission, project);
     }
@@ -331,9 +342,11 @@ public class ShowActionIT {
   @Test
   @UseDataProvider("allPublicProjectPermissionsButSECURITYHOTSPOT_ADMIN")
   public void return_canChangeStatus_true_on_public_project_when_authenticated_with_SECURITYHOTSPOT_ADMIN_permission(@Nullable String permission) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
     if (permission != null) {
       userSessionRule.addProjectPermission(permission, project);
     }
@@ -361,13 +374,14 @@ public class ShowActionIT {
   @Test
   @UseDataProvider("allPrivateProjectPermissionsButSECURITYHOTSPOT_ADMIN_and_USER")
   public void return_canChangeStatus_false_on_private_project_without_SECURITYHOTSPOT_ADMIN_permission(@Nullable String permission) {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     userSessionRule
-      .registerComponents(project)
+      .registerProjects(projectData.getProjectDto())
       .logIn()
-      .addProjectPermission(UserRole.USER, project);
+      .addProjectPermission(UserRole.USER, projectData.getProjectDto());
     if (permission != null) {
-      userSessionRule.addProjectPermission(permission, project);
+      userSessionRule.addProjectPermission(permission, projectData.getProjectDto());
     }
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -383,18 +397,19 @@ public class ShowActionIT {
   @Test
   @UseDataProvider("allPrivateProjectPermissionsButSECURITYHOTSPOT_ADMIN_and_USER")
   public void return_canChangeStatus_false_on_private_project_with_SECURITYHOTSPOT_ADMIN_permission(@Nullable String permission) {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
     userSessionRule
-      .registerComponents(project)
+      .registerProjects(projectData.getProjectDto())
       .logIn()
-      .addProjectPermission(UserRole.USER, project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+      .addProjectPermission(UserRole.USER, projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
     if (permission != null) {
-      userSessionRule.addProjectPermission(permission, project);
+      userSessionRule.addProjectPermission(permission, projectData.getProjectDto());
     }
-    ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
+    ComponentDto file = dbTester.components().insertComponent(newFileDto(mainBranch));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
-    IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
+    IssueDto hotspot = dbTester.issues().insertHotspot(rule, mainBranch, file);
     mockChangelogAndCommentsFormattingContext();
 
     Hotspots.ShowWsResponse response = newRequest(hotspot)
@@ -417,8 +432,10 @@ public class ShowActionIT {
   @Test
   @UseDataProvider("statusAndResolutionCombinations")
   public void returns_status_and_resolution(String status, @Nullable String resolution) {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
@@ -447,8 +464,10 @@ public class ShowActionIT {
 
   @Test
   public void dispatch_description_sections_of_advanced_rule_in_relevant_field() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
 
@@ -481,8 +500,10 @@ public class ShowActionIT {
 
   @Test
   public void fallbacks_to_default_section_in_case_of_legacy_rule() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
 
@@ -505,8 +526,10 @@ public class ShowActionIT {
 
   @Test
   public void ignore_default_section_if_root_cause_provided() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
 
@@ -541,8 +564,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_html_description_for_custom_rules() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
 
@@ -570,8 +595,10 @@ public class ShowActionIT {
 
   @Test
   public void handles_null_description_for_custom_rules() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
 
@@ -588,8 +615,10 @@ public class ShowActionIT {
 
   @Test
   public void handle_given_description_section_with_3_contexts_return_one_alphabetically() {
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
 
@@ -624,8 +653,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_hotspot_component_and_rule() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@@ -643,8 +674,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_no_textRange_when_locations_have_none() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@@ -660,8 +693,10 @@ public class ShowActionIT {
   @Test
   @UseDataProvider("randomTextRangeValues")
   public void returns_textRange(int startLine, int endLine, int startOffset, int endOffset) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@@ -681,8 +716,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_no_assignee_when_user_does_not_exist() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(randomAlphabetic(10)));
@@ -696,8 +733,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_assignee_details_when_user_exists() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     UserDto assignee = dbTester.users().insertUser();
@@ -718,8 +757,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_no_avatar_if_assignee_has_no_email() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     UserDto assignee = dbTester.users().insertUser(t -> t.setEmail(null));
@@ -735,8 +776,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_inactive_when_assignee_is_inactive() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     UserDto assignee = dbTester.users().insertUser(t -> t.setActive(false));
@@ -752,8 +795,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_author_login_when_user_does_not_exist() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     String authorLogin = randomAlphabetic(10);
@@ -769,8 +814,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_author_details_when_user_exists() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     UserDto author = dbTester.users().insertUser();
@@ -790,8 +837,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_no_avatar_if_author_has_no_email() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     UserDto author = dbTester.users().insertUser(t -> t.setEmail(null));
@@ -807,8 +856,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_inactive_if_author_is_inactive() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     UserDto author = dbTester.users().insertUser(t -> t.setActive(false));
@@ -835,8 +886,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_textRange_missing_fields() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@@ -860,8 +913,10 @@ public class ShowActionIT {
   @UseDataProvider("allSQCategoryAndVulnerabilityProbability")
   public void returns_securityCategory_and_vulnerabilityProbability_of_rule(Set<String> standards,
     SQCategory expected) {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT, t -> t.setSecurityStandards(standards));
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@@ -896,8 +951,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_project_twice_when_hotspot_on_project() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, project,
       t -> t.setLocations(DbIssues.Locations.newBuilder()
@@ -914,12 +971,13 @@ public class ShowActionIT {
 
   @Test
   public void returns_branch_but_no_pullRequest_on_component_and_project_on_non_main_branch() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey(branchName));
     userSessionRule.addProjectBranchMapping(project.uuid(), branch);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(branch, project.uuid()));
-    userSessionRule.registerComponents(project);
+    userSessionRule.registerProjects(projectData.getProjectDto());
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, branch, file,
       t -> t.setLocations(DbIssues.Locations.newBuilder()
@@ -936,13 +994,14 @@ public class ShowActionIT {
 
   @Test
   public void returns_pullRequest_but_no_branch_on_component_and_project_on_pullRequest() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     String pullRequestKey = randomAlphanumeric(100);
     ComponentDto pullRequest = dbTester.components().insertProjectBranch(project,
       t -> t.setBranchType(BranchType.PULL_REQUEST).setKey(pullRequestKey));
     userSessionRule.addProjectBranchMapping(project.uuid(), pullRequest);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest));
-    userSessionRule.registerComponents(project);
+    userSessionRule.registerProjects(projectData.getProjectDto());
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, pullRequest, file,
       t -> t.setLocations(DbIssues.Locations.newBuilder()
@@ -959,8 +1018,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_hotspot_changelog_and_comments() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@@ -996,8 +1057,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_user_details_of_users_from_ChangelogAndComments() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@@ -1020,8 +1083,10 @@ public class ShowActionIT {
 
   @Test
   public void returns_user_of_users_from_ChangelogAndComments_and_assignee_and_author() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     UserDto author = dbTester.users().insertUser();
@@ -1042,16 +1107,18 @@ public class ShowActionIT {
       .extracting(User::getLogin, User::getName, User::getActive)
       .containsExactlyInAnyOrder(
         Stream.concat(
-          Stream.of(author, assignee),
-          changeLogAndCommentsUsers.stream())
+            Stream.of(author, assignee),
+            changeLogAndCommentsUsers.stream())
           .map(t -> tuple(t.getLogin(), t.getName(), t.isActive()))
           .toArray(Tuple[]::new));
   }
 
   @Test
   public void do_not_duplicate_user_if_author_assignee_ChangeLogComment_user() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     UserDto author = dbTester.users().insertUser();
@@ -1071,8 +1138,10 @@ public class ShowActionIT {
 
   @Test
   public void response_shouldContainCodeVariants() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    userSessionRule.registerComponents(project);
+    ProjectData projectData = dbTester.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto());
     ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
     RuleDto rule = newRule(SECURITY_HOTSPOT);
     IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setCodeVariants(List.of("variant1", "variant2")));
@@ -1086,12 +1155,14 @@ public class ShowActionIT {
 
   @Test
   public void verify_response_example() {
-    ComponentDto project = dbTester.components().insertPublicProject(componentDto -> componentDto
+    ProjectData projectData = dbTester.components().insertPublicProject(componentDto -> componentDto
       .setName("test-project")
       .setLongName("test-project")
-      .setKey("com.sonarsource:test-project")).getMainBranchComponent();
-    userSessionRule.registerComponents(project)
-      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+      .setKey("com.sonarsource:test-project"));
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSessionRule.registerProjects(projectData.getProjectDto())
+      .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
 
     ComponentDto file = dbTester.components().insertComponent(
       newFileDto(project)
index 9b7c46f407080c3b453454405bcf10ee72fea1ac..cc0564d78a3f26a4f2c4bd37257fab313987fd3d 100644 (file)
@@ -33,7 +33,9 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.issue.AvatarResolverImpl;
@@ -111,10 +113,11 @@ public class SearchActionComponentsIT {
   @Test
   public void search_all_issues_when_no_parameter() {
     RuleDto rule = db.rules().insertIssueRule();
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
     IssueDto issue = db.issues().insertIssue(rule, project, projectFile);
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssues();
 
     SearchWsResponse result = ws.newRequest().executeProtobuf(SearchWsResponse.class);
@@ -126,13 +129,15 @@ public class SearchActionComponentsIT {
   @Test
   public void issues_on_different_projects() {
     RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPublicProject();
+    ComponentDto project = projectData1.getMainBranchComponent();
     ComponentDto file = db.components().insertComponent(newFileDto(project));
     IssueDto issue1 = db.issues().insertIssue(rule, project, file);
-    ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPublicProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     ComponentDto file2 = db.components().insertComponent(newFileDto(project2));
     IssueDto issue2 = db.issues().insertIssue(rule, project2, file2);
-    allowAnyoneOnProjects(project, project2);
+    allowAnyoneOnProjects(projectData1.getProjectDto(), projectData2.getProjectDto());
     indexIssues();
 
     SearchWsResponse response = ws.newRequest().executeProtobuf(SearchWsResponse.class);
@@ -149,7 +154,8 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_since_in_new_code_period_on_project() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
     db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime()));
     RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
@@ -159,7 +165,7 @@ public class SearchActionComponentsIT {
     IssueDto issueBeforeLeak = db.issues().insertIssue(rule, project, file, i -> i.setKee(UUID_EXAMPLE_02)
       .setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100"))
       .setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")));
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssues();
 
     ws.newRequest()
@@ -171,11 +177,12 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_by_file_uuid() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
     RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
     IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssues();
 
     ws.newRequest()
@@ -191,13 +198,14 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_by_file_key() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
     ComponentDto unitTest = db.components().insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setKey("FK2"));
     RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
     IssueDto issueOnFile = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
     IssueDto issueOnTest = db.issues().insertIssue(rule, project, unitTest, i -> i.setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4"));
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssues();
 
     ws.newRequest()
@@ -213,12 +221,13 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_by_directory_path() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto directory = db.components().insertComponent(newDirectory(project, "D1", "src/main/java/dir"));
     ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1").setPath(directory.path() + "/MyComponent.java"));
     RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
     db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssues();
 
     ws.newRequest()
@@ -244,13 +253,16 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_by_view_uuid() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
     ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setKey("MyView"));
     db.components().insertComponent(newProjectCopy(project, view));
     RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
     db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
-    allowAnyoneOnProjects(project, view);
+    allowAnyoneOnProjects(projectData.getProjectDto());
+    allowAnyoneOnPortfolios(view);
+
     indexIssuesAndViews();
 
     ws.newRequest()
@@ -261,14 +273,16 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_by_sub_view_uuid() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
     RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
     db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
     ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setKey("MyView"));
     ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SV1", "MySubView"));
     db.components().insertComponent(newProjectCopy(project, subView));
-    allowAnyoneOnProjects(project, view, subView);
+    allowAnyoneOnProjects(projectData.getProjectDto());
+    allowAnyoneOnPortfolios(view, subView);
     indexIssuesAndViews();
 
     ws.newRequest()
@@ -279,7 +293,8 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_by_sub_view_uuid_return_only_authorized_view() {
-    ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
     RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
     db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
@@ -287,7 +302,7 @@ public class SearchActionComponentsIT {
     ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SV1", "MySubView"));
     db.components().insertComponent(newProjectCopy(project, subView));
     // User has no permission on the view, no issue will be returned
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssuesAndViews();
 
     ws.newRequest()
@@ -298,15 +313,18 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_by_application_key() {
-    ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData applicationData = db.components().insertPrivateApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPrivateProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPrivateProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     db.components().insertComponents(newProjectCopy(project1, application));
     db.components().insertComponents(newProjectCopy(project2, application));
     RuleDto rule = db.rules().insertIssueRule();
     IssueDto issue1 = db.issues().insertIssue(rule, project1, project1);
     IssueDto issue2 = db.issues().insertIssue(rule, project2, project2);
-    allowAnyoneOnApplication(application, project1, project2);
+    allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
     userSession.addProjectPermission(USER, application);
     indexIssuesAndViews();
 
@@ -320,18 +338,21 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_by_application_key_and_branch() {
-    ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app")).getMainBranchComponent();
+    ProjectData applicatioData = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app"));
+    ComponentDto application = applicatioData.getMainBranchComponent();
     String appBranch1 = "app-branch1";
     String appBranch2 = "app-branch2";
     String proj1branch1 = "proj1branch1";
     String proj1branch2 = "proj1branch2";
     ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey(appBranch1));
     ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey(appBranch2));
-    ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1")).getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPrivateProject(p -> p.setKey("prj1"));
+    ComponentDto project1 = projectData1.getMainBranchComponent();
     ComponentDto project1Branch1 = db.components().insertProjectBranch(project1, b -> b.setKey(proj1branch1));
     ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1, project1.uuid()));
     ComponentDto project1Branch2 = db.components().insertProjectBranch(project1, b -> b.setKey(proj1branch2));
-    ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2")).getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPrivateProject(p -> p.setKey("prj2"));
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1));
     db.components().insertComponents(newProjectCopy(project2, applicationBranch1));
     db.components().insertComponents(newProjectCopy(project1Branch2, applicationBranch2));
@@ -345,7 +366,7 @@ public class SearchActionComponentsIT {
     IssueDto issueOnProject1Branch2 = db.issues().insertIssue(issueRule, project1Branch2, project1Branch2);
     IssueDto issueOnProject2 = db.issues().insertIssue(issueRule, project2, project2);
     db.issues().insertHotspot(hotspotRule, project2, project2);
-    allowAnyoneOnProjects(project1, project2, application);
+    allowAnyoneOnProjects(projectData1.getProjectDto(), projectData2.getProjectDto(), applicatioData.getProjectDto());
     userSession.addProjectPermission(USER, application);
     indexIssuesAndViews();
 
@@ -374,12 +395,13 @@ public class SearchActionComponentsIT {
 
   @Test
   public void ignore_application_without_browse_permission() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
     db.components().insertComponents(newProjectCopy("PC1", project, application));
     RuleDto rule = db.rules().insertIssueRule();
     db.issues().insertIssue(rule, project, project);
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest()
@@ -391,11 +413,13 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_application_without_projects() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+    ProjectData applicationData = db.components().insertPublicApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
     RuleDto rule = db.rules().insertIssueRule();
     db.issues().insertIssue(rule, project, project);
-    allowAnyoneOnProjects(project, application);
+    allowAnyoneOnProjects(projectData.getProjectDto(), applicationData.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest()
@@ -409,21 +433,24 @@ public class SearchActionComponentsIT {
   public void search_by_application_and_by_new_code_period() {
     Date now = new Date();
     RuleDto rule = db.rules().insertIssueRule();
-    ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+    ProjectData applicationData = db.components().insertPublicApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
     // Project 1
-    ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPublicProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
     db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
     db.components().insertComponents(newProjectCopy("PC1", project1, application));
     IssueDto project1Issue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10)));
     IssueDto project1Issue2 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20)));
     // Project 2
-    ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPublicProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     db.components().insertSnapshot(project2, s -> s.setPeriodDate(addDays(now, -25).getTime()));
     db.components().insertComponents(newProjectCopy("PC2", project2, application));
     IssueDto project2Issue1 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15)));
     IssueDto project2Issue2 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30)));
     // Permissions and index
-    allowAnyoneOnApplication(application, project1, project2);
+    allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest()
@@ -438,15 +465,18 @@ public class SearchActionComponentsIT {
 
   @Test
   public void search_by_application_and_project() {
-    ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPublicProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPublicProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
+    ProjectData applicationData = db.components().insertPublicApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
     db.components().insertComponents(newProjectCopy("PC1", project1, application));
     db.components().insertComponents(newProjectCopy("PC2", project2, application));
     RuleDto rule = db.rules().insertIssueRule();
     IssueDto issue1 = db.issues().insertIssue(rule, project1, project1);
     IssueDto issue2 = db.issues().insertIssue(rule, project2, project2);
-    allowAnyoneOnApplication(application, project1, project2);
+    allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest()
@@ -463,21 +493,24 @@ public class SearchActionComponentsIT {
   public void search_by_application_and_project_and_new_code_period() {
     Date now = new Date();
     RuleDto rule = db.rules().insertIssueRule();
-    ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+    ProjectData applicationData = db.components().insertPublicApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
     // Project 1
-    ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPublicProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
     db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
     db.components().insertComponents(newProjectCopy("PC1", project1, application));
     IssueDto project1Issue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10)));
     IssueDto project1Issue2 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20)));
     // Project 2
-    ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPublicProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     db.components().insertSnapshot(project2, s -> s.setPeriodDate(addDays(now, -25).getTime()));
     db.components().insertComponents(newProjectCopy("PC2", project2, application));
     IssueDto project2Issue1 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15)));
     IssueDto project2Issue2 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30)));
     // Permissions and index
-    allowAnyoneOnApplication(application, project1, project2);
+    allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest()
@@ -495,21 +528,24 @@ public class SearchActionComponentsIT {
   public void search_by_application_and_by_new_code_period_when_one_project_has_no_leak() {
     Date now = new Date();
     RuleDto rule = db.rules().insertIssueRule();
-    ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+    ProjectData applicationData = db.components().insertPublicApplication();
+    ComponentDto application = applicationData.getMainBranchComponent();
     // Project 1
-    ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData1 = db.components().insertPublicProject();
+    ComponentDto project1 = projectData1.getMainBranchComponent();
     db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
     db.components().insertComponents(newProjectCopy("PC1", project1, application));
     IssueDto project1Issue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10)));
     IssueDto project1Issue2 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20)));
     // Project 2, without leak => no issue form it should be returned
-    ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData2 = db.components().insertPublicProject();
+    ComponentDto project2 = projectData2.getMainBranchComponent();
     db.components().insertSnapshot(project2, s -> s.setPeriodDate(null));
     db.components().insertComponents(newProjectCopy("PC2", project2, application));
     IssueDto project2Issue1 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15)));
     IssueDto project2Issue2 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30)));
     // Permissions and index
-    allowAnyoneOnApplication(application, project1, project2);
+    allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest()
@@ -525,7 +561,8 @@ public class SearchActionComponentsIT {
   @Test
   public void search_by_branch() {
     RuleDto rule = db.rules().insertIssueRule();
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto file = db.components().insertComponent(newFileDto(project));
     IssueDto issue = db.issues().insertIssue(rule, project, file);
 
@@ -533,7 +570,7 @@ public class SearchActionComponentsIT {
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
     ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
     IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssuesAndViews();
 
     // On component key + branch
@@ -563,14 +600,15 @@ public class SearchActionComponentsIT {
   @Test
   public void return_branch_in_component_list() {
     RuleDto rule = db.rules().insertIssueRule();
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
     IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
     String branchName = randomAlphanumeric(248);
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
     ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
     IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest()
@@ -588,7 +626,8 @@ public class SearchActionComponentsIT {
   @Test
   public void search_by_pull_request() {
     RuleDto rule = db.rules().insertIssueRule();
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
     IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
 
@@ -596,7 +635,7 @@ public class SearchActionComponentsIT {
     ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
     ComponentDto pullRequestFile = db.components().insertComponent(newFileDto(pullRequest, project.uuid()));
     IssueDto pullRequestIssue = db.issues().insertIssue(rule, pullRequest, pullRequestFile);
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest()
@@ -617,10 +656,11 @@ public class SearchActionComponentsIT {
   @Test
   public void search_using_main_branch_name() {
     RuleDto rule = db.rules().insertIssueRule();
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
     IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest()
@@ -641,13 +681,14 @@ public class SearchActionComponentsIT {
   @Test
   public void does_not_return_branch_issues_on_not_contextualized_search() {
     RuleDto rule = db.rules().insertIssueRule();
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPrivateProject();
+    ComponentDto project = projectData.getMainBranchComponent();
     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, project.uuid()));
     IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
-    allowAnyoneOnProjects(project);
+    allowAnyoneOnProjects(projectData.getProjectDto());
     indexIssuesAndViews();
 
     SearchWsResponse result = ws.newRequest().executeProtobuf(SearchWsResponse.class);
@@ -657,12 +698,17 @@ public class SearchActionComponentsIT {
       .doesNotContain(branchIssue.getKey());
   }
 
-  private void allowAnyoneOnProjects(ComponentDto... projects) {
-    userSession.registerComponents(projects);
+  private void allowAnyoneOnProjects(ProjectDto... projects) {
+    userSession.registerProjects(projects);
     Arrays.stream(projects).forEach(p -> permissionIndexer.allowOnlyAnyone(p));
   }
 
-  private void allowAnyoneOnApplication(ComponentDto application, ComponentDto... projects) {
+  private void allowAnyoneOnPortfolios(ComponentDto... portfolios) {
+    userSession.registerPortfolios(portfolios);
+    Arrays.stream(portfolios).forEach(p -> permissionIndexer.allowOnlyAnyone(p));
+  }
+
+  private void allowAnyoneOnApplication(ProjectDto application, ProjectDto... projects) {
     userSession.registerApplication(application);
     Arrays.stream(projects).forEach(p -> permissionIndexer.allowOnlyAnyone(p));
   }
index 16af4cabf5e9199379297367de8c427f0d56dff7..25f5602b8899b66dac925ec693670a085f535d58 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.function.Consumer;
 import javax.annotation.Nullable;
+import org.jetbrains.annotations.NotNull;
 import org.junit.Rule;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -36,8 +37,10 @@ import org.sonar.core.issue.FieldDiffs;
 import org.sonar.core.util.SequenceUuidFactory;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.IssueDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.es.EsTester;
@@ -244,16 +247,24 @@ public class SetTagsActionIT {
 
   private void logIn(IssueDto issueDto) {
     UserDto user = db.users().insertUser("john");
+    ProjectDto projectDto = retrieveProjectDto(issueDto);
     userSession.logIn(user)
-      .registerComponents(
-        dbClient.componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get(),
-        dbClient.componentDao().selectByUuid(db.getSession(), issueDto.getComponentUuid()).get());
+      .registerProjects(projectDto);
+  }
+
+  @NotNull
+  private ProjectDto retrieveProjectDto(IssueDto issueDto) {
+    BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), issueDto.getProjectUuid())
+      .orElseThrow();
+    return db.getDbClient().projectDao().selectByUuid(db.getSession(), branchDto.getProjectUuid())
+      .orElseThrow();
   }
 
   private void logInAndAddProjectPermission(IssueDto issueDto, String permission) {
     UserDto user = db.users().insertUser("john");
+    ProjectDto projectDto = retrieveProjectDto(issueDto);
     userSession.logIn(user)
-      .addProjectPermission(permission, dbClient.componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get());
+      .addProjectPermission(permission, projectDto);
   }
 
   private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) {
index 70b99ddff61b4f8605e90e9cc6390d36c726aa89..4c4e0166f7b68270aa55571aa0bef03d2fd58e33 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.measure.LiveMeasureDto;
@@ -711,7 +712,7 @@ public class ComponentTreeActionIT {
   public void portfolio_local_reference_in_portfolio() {
     ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("VIEW1-UUID")
       .setKey("Apache-Projects").setName("Apache Projects"));
-    userSession.registerComponents(view);
+    userSession.registerPortfolios(view);
     ComponentDto view2 = db.components().insertPrivatePortfolio();
     userSession.addProjectPermission(USER, view2);
     ComponentDto localView = db.components().insertComponent(
@@ -757,15 +758,17 @@ public class ComponentTreeActionIT {
   @Test
   public void project_branch_reference_from_application_branch() {
     MetricDto ncloc = insertNclocMetric();
-    ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app-key")).getMainBranchComponent();
-    userSession.registerApplication(application);
+    ProjectData applicationData = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app-key"));
+    ComponentDto application = applicationData.getMainBranchComponent();
+    userSession.registerApplication(applicationData.getProjectDto());
     String branchName = "app-branch";
     ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey(branchName), a -> a.setUuid("custom-uuid"));
-    userSession.addProjectBranchMapping(application.uuid(), applicationBranch);
-    ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key")).getMainBranchComponent();
+    userSession.addProjectBranchMapping(applicationData.projectUuid(), applicationBranch);
+    ProjectData projectData = db.components().insertPrivateProject(p -> p.setKey("project-key"));
+    ComponentDto project = projectData.getMainBranchComponent();
 
     ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch"));
-    userSession.addProjectBranchMapping(project.uuid(), projectBranch);
+    userSession.addProjectBranchMapping(projectData.projectUuid(), projectBranch);
     ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch)
       .setKey(applicationBranch.getKey() + branchName + projectBranch.getKey()));
 
index a21b270da00b6154a7ebf55212d1ea1980136e53..be7772152b2758ffce69be3e3e3e8b3c3aa969d4 100644 (file)
@@ -44,6 +44,7 @@ import org.sonar.db.component.AnalysisPropertyDto;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.event.EventComponentChangeDto;
 import org.sonar.db.event.EventComponentChangeDto.ChangeCategory;
@@ -420,7 +421,7 @@ public class SearchActionIT {
   @Test
   public void return_analyses_of_portfolio() {
     ComponentDto view = db.components().insertPublicPortfolio();
-    userSession.registerComponents(view);
+    userSession.registerPortfolios(view);
     SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(1_000_000L));
     SnapshotDto secondAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(2_000_000L));
     SnapshotDto thirdAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(3_000_000L));
@@ -667,10 +668,11 @@ public class SearchActionIT {
 
   @Test
   public void fail_if_not_a_project_portfolio_or_application() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
-    db.components().insertSnapshot(newAnalysis(project));
-    userSession.registerComponents(project, file);
+    ProjectData projectData = db.components().insertPrivateProject();
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
+    ComponentDto file = db.components().insertComponent(newFileDto(mainBranch));
+    db.components().insertSnapshot(newAnalysis(mainBranch));
+    userSession.registerProjects(projectData.getProjectDto());
 
     var fileDbKey = file.getKey();
     assertThatThrownBy(() -> call(fileDbKey))
@@ -680,18 +682,19 @@ public class SearchActionIT {
 
   @Test
   public void fail_if_branch_does_not_exist() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
-    db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
+    ProjectData projectData = db.components().insertPrivateProject();
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
+    userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
+    db.components().insertProjectBranch(mainBranch, b -> b.setKey("my_branch"));
 
     var searchRequest = SearchRequest.builder()
-      .setProject(project.getKey())
+      .setProject(mainBranch.getKey())
       .setBranch("another_branch")
       .build();
 
     assertThatThrownBy(() -> call(searchRequest))
       .isInstanceOf(NotFoundException.class)
-      .hasMessage(format("Component '%s' on branch '%s' not found", project.getKey(), "another_branch"));
+      .hasMessage(format("Component '%s' on branch '%s' not found", mainBranch.getKey(), "another_branch"));
   }
 
   @Test
index 77481837ca7b48da14c39f8d8dd13a55882e1030..f6c058b9dbe33a261a1109fd36c1258f22821553 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.ProjectLinkDto;
 import org.sonar.server.component.TestComponentFinder;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -159,8 +160,11 @@ public class CreateActionIT {
   @Test
   public void fail_if_anonymous() {
     userSession.anonymous();
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(project);
+
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto project = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
 
     assertThatThrownBy(() -> ws.newRequest()
       .setParam(PARAM_PROJECT_KEY, project.getKey())
index d6a4da3abe1162551388a4e66299796b2c885d95..006ce113b4b18f6cac7f31547ec126ff1d3c3f5b 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.audit.NoOpAuditPersister;
 import org.sonar.db.component.ComponentDao;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.SnapshotDao;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.protobuf.DbFileSources;
@@ -145,10 +146,11 @@ public class LinesActionIT {
 
   @Test
   public void pull_request() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPrivateProject();
+    ComponentDto mainBranch = projectData.getMainBranchComponent();
     String pullRequestKey = randomAlphanumeric(100);
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
+    ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()));
     db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto()
       .setUuid(Uuids.createFast())
       .setProjectUuid(branch.uuid())
@@ -157,9 +159,9 @@ public class LinesActionIT {
     db.commit();
 
     userSession.logIn("login")
-      .addProjectPermission(UserRole.USER, project)
-      .addProjectPermission(UserRole.CODEVIEWER, project, file)
-      .registerComponents(branch);
+      .addProjectPermission(UserRole.USER, projectData.getProjectDto())
+      .addProjectPermission(UserRole.CODEVIEWER, projectData.getProjectDto())
+      .addProjectPermission(UserRole.CODEVIEWER, file);
 
     tester.newRequest()
       .setParam("key", file.getKey())
@@ -348,8 +350,10 @@ public class LinesActionIT {
 
   @Test
   public void hide_scmAuthors() {
-    ComponentDto publicProject = db.components().insertPublicProject().getMainBranchComponent();
-    userSession.registerComponents(publicProject);
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto publicProject = projectData.getMainBranchComponent();
+
+    userSession.registerProjects(projectData.getProjectDto());
 
     DbFileSources.Data data = DbFileSources.Data.newBuilder()
       .addLines(newLineBuilder().setScmAuthor("isaac@asimov.com"))
@@ -365,10 +369,10 @@ public class LinesActionIT {
 
   @Test
   public void show_scmAuthors() {
-    ComponentDto publicProject = db.components().insertPublicProject().getMainBranchComponent();
+    ProjectData projectData = db.components().insertPublicProject();
+    ComponentDto publicProject = projectData.getMainBranchComponent();
     UserDto user = db.users().insertUser();
-    userSession.logIn(user)
-      .registerComponents(publicProject);
+    userSession.logIn(user).registerProjects(projectData.getProjectDto());
 
     DbFileSources.Data data = DbFileSources.Data.newBuilder()
       .addLines(newLineBuilder().setScmAuthor("isaac@asimov.com"))
index c40a7452f9528ebd2c49cef2ad1e98fa8f9ed81d..dbb9df2c4884de33586428570da50599093bd781 100644 (file)
@@ -49,6 +49,7 @@ import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.metric.MetricDto;
 import org.sonar.db.permission.GlobalPermission;
@@ -444,10 +445,11 @@ public class ComponentActionIT {
       .setScope(COMPONENT)
       .setComponentQualifiers(Qualifier.VIEW, Qualifier.APP)
       .build();
-    ComponentDto application = componentDbTester.insertPublicApplication().getMainBranchComponent();
+    ProjectData projectData = componentDbTester.insertPublicApplication();
+    ComponentDto application = projectData.getMainBranchComponent();
     QualityGateDto qualityGateDto = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way"));
     db.qualityGates().associateProjectToQualityGate(project, qualityGateDto);
-    userSession.registerComponents(application);
+    userSession.registerProjects(projectData.getProjectDto());
     init(page);
 
     String result = ws.newRequest()