]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19888 Update test framework to not use addProjectPermission(java.lang.String... 10.2.0.77647
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Thu, 31 Aug 2023 10:00:49 +0000 (12:00 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 31 Aug 2023 20:02:57 +0000 (20:02 +0000)
31 files changed:
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/ce/queue/ReportSubmitterIT.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/developers/ws/SearchEventsActionNewIssuesIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/favorite/ws/AddActionIT.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/issue/IssueFinderIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetSeverityActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetTypeActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/TransitionActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/TransitionServiceIT.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/SetSeverityActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/ComponentActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/measure/ws/SearchHistoryActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/notification/ws/AddActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/AddUserActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/UsersActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/DeleteActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/DeleteActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/DeleteEventActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/UpdateEventActionIT.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/qualitygate/ws/DeselectActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SelectActionIT.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/source/ws/ScmActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/source/ws/ShowActionIT.java

index cf638ea7a4d4328557b319e0db802ecc81d8666a..f16fd49a39218752deedefcc6d17ee2e51d28a1a 100644 (file)
@@ -177,6 +177,10 @@ public class ComponentTesting {
     return newProjectCopy(Uuids.createFast(), project.getMainBranchComponent(), view.getMainBranchComponent());
   }
 
+  public static ComponentDto newProjectCopy(ProjectData project, PortfolioData view) {
+    return newProjectCopy(Uuids.createFast(), project.getMainBranchComponent(), view.getRootComponent());
+  }
+
   public static ComponentDto newProjectCopy(ComponentDto project, ComponentDto view) {
     return newProjectCopy(Uuids.createFast(), project, view);
   }
@@ -254,10 +258,23 @@ public class ComponentTesting {
       .setBranchType(BranchType.BRANCH);
   }
 
+  public static BranchDto newMainBranchDto(String projectUUid) {
+    return new BranchDto()
+      .setKey(DEFAULT_MAIN_BRANCH_NAME)
+      .setIsMain(true)
+      .setUuid(Uuids.createFast())
+      .setProjectUuid(projectUUid)
+      .setBranchType(BranchType.BRANCH);
+  }
+
   public static ProjectDto newProjectDto() {
+    return newProjectDto("uuid").setPrivate(true);
+  }
+
+  public static ProjectDto newProjectDto(String projectUuid) {
     return new ProjectDto()
       .setKey("projectKey")
-      .setUuid("uuid")
+      .setUuid(projectUuid)
       .setName("projectName")
       .setQualifier(Qualifiers.PROJECT);
   }
index d74811ef709529963197090724e7b88635554f4f..bbbecc7cc628bf3eb350323b470bd570154ce0e7 100644 (file)
@@ -143,7 +143,8 @@ public class ReportSubmitterIT {
   public void submit_a_report_on_existing_project() {
     ProjectData project = db.components().insertPrivateProject();
     UserDto user = db.users().insertUser();
-    userSession.logIn(user).addProjectPermission(SCAN.getKey(), project.getMainBranchComponent());
+    userSession.logIn(user).addProjectPermission(SCAN.getKey(), project.getProjectDto())
+      .addProjectBranchMapping(project.projectUuid(), project.getMainBranchComponent());
     mockSuccessfulPrepareSubmitCall();
 
     underTest.submit(project.projectKey(), project.getProjectDto().getName(), emptyMap(), IOUtils.toInputStream("{binary}", UTF_8));
@@ -255,11 +256,13 @@ public class ReportSubmitterIT {
 
   @Test
   public void submit_a_report_on_existing_project_with_project_scan_permission() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(SCAN.getKey(), project);
+    ProjectData projectData = db.components().insertPrivateProject();
+    ProjectDto project = projectData.getProjectDto();
+    userSession.addProjectPermission(SCAN.getKey(), project)
+      .addProjectBranchMapping(project.getUuid(), projectData.getMainBranchComponent());
     mockSuccessfulPrepareSubmitCall();
 
-    underTest.submit(project.getKey(), project.name(), emptyMap(), IOUtils.toInputStream("{binary}", UTF_8));
+    underTest.submit(project.getKey(), project.getName(), emptyMap(), IOUtils.toInputStream("{binary}", UTF_8));
 
     verify(queue).submit(any(CeTaskSubmit.class));
   }
index a99b7cdba70601147e9903b1b450fc420c320441..7758926fc24a47131fe8b5c7f4ee9755a8dbfcf2 100644 (file)
@@ -436,7 +436,7 @@ public class ShowActionIT {
   public void fail_if_component_is_removed() {
     ProjectData projectData = db.components().insertPrivateProject();
     ComponentDto mainBranch = projectData.getMainBranchComponent();
-    userSession.addProjectPermission(USER, mainBranch)
+    userSession.addProjectPermission(USER, projectData.getProjectDto())
       .registerBranches(projectData.getMainBranchDto());
     db.components().insertComponent(newFileDto(mainBranch).setKey("file-key").setEnabled(false));
 
index 8c1ff9c38c9bc939598a0ae236b8a14bcabfb127..1e52e2443877d96816b4280e07d73112bf79b8aa 100644 (file)
@@ -377,13 +377,13 @@ public class TreeActionIT {
 
   @Test
   public void branch() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
     String branchKey = "my_branch";
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchKey));
-    userSession.addProjectBranchMapping(project.uuid(), branch);
-    ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch, "dir", project.uuid()));
-    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory, project.uuid()));
+    ComponentDto branch = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setKey(branchKey));
+    userSession.addProjectBranchMapping(project.projectUuid(), branch);
+    ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch, "dir", project.mainBranchUuid()));
+    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory, project.mainBranchUuid()));
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, branch.getKey())
@@ -400,9 +400,10 @@ public class TreeActionIT {
 
   @Test
   public void dont_show_branch_if_main_branch() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
-    userSession.addProjectPermission(UserRole.USER, project);
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertFile(project.getMainBranchDto());
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto())
+      .addProjectBranchMapping(project.projectUuid(), project.getMainBranchComponent());
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, file.getKey())
@@ -415,13 +416,13 @@ public class TreeActionIT {
 
   @Test
   public void pull_request() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
     String pullRequestId = "pr-123";
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(pullRequestId).setBranchType(PULL_REQUEST));
-    userSession.addProjectBranchMapping(project.uuid(), branch);
-    ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch, "dir", project.uuid()));
-    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory, project.uuid()));
+    ComponentDto branch = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setKey(pullRequestId).setBranchType(PULL_REQUEST));
+    userSession.addProjectBranchMapping(project.projectUuid(), branch);
+    ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch, "dir", project.mainBranchUuid()));
+    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(directory, project.mainBranchUuid()));
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, directory.getKey())
@@ -437,13 +438,13 @@ public class TreeActionIT {
 
   @Test
   public void fail_when_not_enough_privileges() {
-    ComponentDto project = db.components().insertPrivateProject("project-uuid").getMainBranchComponent();
+    ProjectData project = db.components().insertPrivateProject("project-uuid");
     userSession.logIn()
-      .addProjectPermission(UserRole.CODEVIEWER, project);
+      .addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto());
     db.commit();
 
     TestRequest request = ws.newRequest()
-      .setParam(PARAM_COMPONENT, project.getKey());
+      .setParam(PARAM_COMPONENT, project.projectKey());
     assertThatThrownBy(request::execute)
       .isInstanceOf(ForbiddenException.class);
   }
@@ -531,16 +532,16 @@ public class TreeActionIT {
 
   @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 project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
+    db.components().insertProjectBranch(project.getProjectDto(), b -> b.setKey("my_branch"));
 
     TestRequest request = ws.newRequest()
-      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(PARAM_COMPONENT, project.projectKey())
       .setParam(PARAM_BRANCH, "another_branch");
     assertThatThrownBy(request::execute)
       .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", project.projectKey(), "another_branch"));
   }
 
   private static ComponentDto newFileDto(ComponentDto moduleOrProject, @Nullable ComponentDto directory, int i) {
index c06c5b9517b58f90b9ff5fe3ed2a2bf00fd59095..6d593244ddad0c69f7d484a4879053d84eb0cca7 100644 (file)
@@ -136,14 +136,15 @@ public class SearchEventsActionNewIssuesIT {
   @Test
   public void does_not_return_old_issue() {
     userSession.logIn();
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(USER, project);
-    SnapshotDto analysis = insertAnalysis(project, 1_500_000_000_000L);
-    db.issues().insert(db.rules().insert(), project, project, i -> i.setIssueCreationDate(new Date(analysis.getCreatedAt() - 10_000L)));
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(USER, project.getProjectDto());
+    SnapshotDto analysis = insertAnalysis(project.getMainBranchComponent(), 1_500_000_000_000L);
+    db.issues().insert(db.rules().insert(), project.getMainBranchComponent(), project.getMainBranchComponent(),
+      i -> i.setIssueCreationDate(new Date(analysis.getCreatedAt() - 10_000L)));
     issueIndexer.indexAllIssues();
 
     SearchEventsWsResponse result = ws.newRequest()
-      .setParam(PARAM_PROJECTS, project.getKey())
+      .setParam(PARAM_PROJECTS, project.projectKey())
       .setParam(PARAM_FROM, formatDateTime(analysis.getCreatedAt() - 1_000L))
       .executeProtobuf(SearchEventsWsResponse.class);
 
index 4128e6f14026de7f6002db3ab9f5ab3f98bf4727..52308a8b0028ccdc26daf385826f33ee448bb076 100644 (file)
@@ -29,6 +29,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.project.ProjectDto;
 import org.sonar.db.property.PropertyDto;
 import org.sonar.db.property.PropertyQuery;
@@ -84,7 +85,7 @@ public class AddActionIT {
 
   @Test
   public void fail_when_no_browse_permission_on_the_project() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     assertThatThrownBy(() -> call(project.getKey()))
@@ -109,10 +110,10 @@ public class AddActionIT {
 
   @Test
   public void fail_on_file() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project.getMainBranchComponent()));
     UserDto user = db.users().insertUser();
-    userSession.logIn(user).addProjectPermission(USER, project);
+    userSession.logIn(user).addProjectPermission(USER, project.getProjectDto());
 
     assertThatThrownBy(() -> call(file.getKey()))
       .isInstanceOf(NotFoundException.class)
index 0721fe906f4a96dc6ea530b3ad7d5a7c28e03289..fa19542e1038aa7dd668aa372a28b80355bbaf21 100644 (file)
@@ -813,10 +813,9 @@ public class SearchActionIT {
   @Test
   public void fail_if_hotspots_provided_with_onlyMine_param() {
     ProjectData projectData = dbTester.components().insertPrivateProject();
-    ComponentDto project = projectData.getMainBranchComponent();
 
     userSessionRule.registerProjects(projectData.getProjectDto());
-    userSessionRule.logIn().addProjectPermission(USER, project);
+    userSessionRule.logIn().addProjectPermission(USER, projectData.getProjectDto());
 
     TestRequest request = actionTester.newRequest()
       .setParam(PARAM_HOTSPOTS, IntStream.range(2, 10).mapToObj(String::valueOf).collect(joining(",")))
index cc653b50d1252c14e247c49b37ddf8e49803b185..607c384dcfdb77b892098ac3d9fd59adbc6ce9fd 100644 (file)
@@ -23,9 +23,12 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.issue.IssueDbTester;
 import org.sonar.db.issue.IssueDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.rule.RuleDbTester;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -70,7 +73,7 @@ public class IssueFinderIT {
     IssueDto issueDto = insertIssue();
     addProjectPermission(issueDto, USER);
 
-    assertThatThrownBy(() ->  underTest.getByKey(db.getSession(), "UNKNOWN"))
+    assertThatThrownBy(() -> underTest.getByKey(db.getSession(), "UNKNOWN"))
       .isInstanceOf(NotFoundException.class)
       .hasMessage("Issue with key 'UNKNOWN' does not exist");
   }
@@ -86,12 +89,16 @@ public class IssueFinderIT {
 
   private IssueDto insertIssue() {
     RuleDto rule = ruleDbTester.insert(newRule());
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
-    return issueDbTester.insert(newIssue(rule, project, file));
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project.getMainBranchComponent()));
+    return issueDbTester.insert(newIssue(rule, project.getMainBranchComponent(), file));
   }
 
   private void addProjectPermission(IssueDto issueDto, String permission) {
-    userSession.addProjectPermission(permission, db.getDbClient().componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get());
+    BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), issueDto.getProjectUuid())
+      .orElseThrow(() -> new IllegalStateException("Couldn't find branch :" + issueDto.getProjectUuid()));
+    ProjectDto projectDto = db.getDbClient().projectDao().selectByUuid(db.getSession(), branchDto.getProjectUuid()).get();
+    userSession.addProjectPermission(permission, projectDto)
+      .registerBranches(branchDto);
   }
 }
index bf4be8145f0435addaa88c2aa7d1da91c138c911..82696ad63da3e8c908672f6f7281751b177a243c 100644 (file)
@@ -30,9 +30,11 @@ import org.sonar.api.rules.RuleType;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.FieldDiffs;
 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.issue.IssueTesting;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.server.tester.AnonymousMockUserSession;
 import org.sonar.server.tester.UserSessionRule;
@@ -120,11 +122,14 @@ public class SetSeverityActionIT {
   }
 
   private void setUserWithBrowseAndAdministerIssuePermission(IssueDto issue) {
-    ComponentDto project = db.getDbClient().componentDao().selectByUuid(db.getSession(), issue.getProjectUuid()).get();
-    ComponentDto component = db.getDbClient().componentDao().selectByUuid(db.getSession(), issue.getComponentUuid()).get();
+
+    BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), issue.getProjectUuid())
+      .orElseThrow(() -> new IllegalStateException("Couldn't find branch :" + issue.getProjectUuid()));
+    ProjectDto project = db.getDbClient().projectDao().selectByUuid(db.getSession(), branchDto.getProjectUuid()).get();
     userSession.logIn(USER_LOGIN)
-      .addProjectPermission(ISSUE_ADMIN, project, component)
-      .addProjectPermission(USER, project, component);
+      .addProjectPermission(ISSUE_ADMIN, project)
+      .addProjectPermission(USER, project)
+      .registerBranches(branchDto);
   }
 
   private IssueDto newIssue() {
index 035c7ecc286f8610bb66aa985b013688a6525606..8200d8690a4d9d84e53bb28d89f47c603746c782 100644 (file)
@@ -29,9 +29,11 @@ import org.sonar.api.issue.Issue;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.FieldDiffs;
 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.issue.IssueTesting;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.server.tester.UserSessionRule;
 
@@ -115,11 +117,13 @@ public class SetTypeActionIT {
   }
 
   private void setUserWithBrowseAndAdministerIssuePermission(IssueDto issueDto) {
-    ComponentDto project = db.getDbClient().componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get();
-    ComponentDto component = db.getDbClient().componentDao().selectByUuid(db.getSession(), issueDto.getComponentUuid()).get();
+    BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), issueDto.getProjectUuid())
+      .orElseThrow(() -> new IllegalStateException("Couldn't find branch :" + issueDto.getProjectUuid()));
+    ProjectDto project = db.getDbClient().projectDao().selectByUuid(db.getSession(), branchDto.getProjectUuid()).get();
     userSession.logIn(USER_LOGIN)
-      .addProjectPermission(ISSUE_ADMIN, project, component)
-      .addProjectPermission(USER, project, component);
+      .addProjectPermission(ISSUE_ADMIN, project)
+      .addProjectPermission(USER, project)
+      .registerBranches(branchDto);
   }
 
   private IssueDto newIssue() {
index 48be82bd93f7bd5e6e3b32b96082a66fa4b7868d..8bdd09d65edc97dbcc92d6e0373abcbeb70c0915 100644 (file)
@@ -29,10 +29,13 @@ import org.sonar.api.issue.Issue;
 import org.sonar.api.rules.RuleType;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.util.Uuids;
+import org.sonar.db.component.BranchDto;
+import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.issue.IssueTesting;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.server.issue.workflow.FunctionExecutor;
 import org.sonar.server.issue.workflow.IssueWorkflow;
@@ -113,6 +116,7 @@ public class TransitionActionIT {
     assertThat(action.supports(new DefaultIssue().setResolution(Issue.RESOLUTION_FIXED))).isTrue();
   }
 
+
   private IssueDto newIssue() {
     RuleDto rule = newRule().setUuid(Uuids.createFast());
     ComponentDto project = ComponentTesting.newPrivateProjectDto();
@@ -121,7 +125,10 @@ public class TransitionActionIT {
   }
 
   private void loginAndAddProjectPermission(String login, String permission) {
-    userSession.logIn(login).addProjectPermission(permission, ComponentTesting.newPrivateProjectDto(issue.projectUuid()));
+    ProjectDto projectDto = ComponentTesting.newProjectDto();
+    BranchDto branchDto = ComponentTesting.newBranchDto(projectDto.getUuid(), BranchType.BRANCH).setIsMain(true).setUuid(issue.projectUuid());
+    userSession.logIn(login).addProjectPermission(permission, projectDto)
+      .registerBranches(branchDto);
   }
 
 }
index a024aaee6bbde94a3cb82508526dfab1a5ef3e9f..95c04cd67f3986c4521d728d4917ee37e568d00d 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.IssueChangeContext;
 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.issue.workflow.FunctionExecutor;
@@ -63,11 +64,12 @@ public class TransitionServiceIT {
 
   @Test
   public void list_transitions() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project.getMainBranchComponent()));
     RuleDto rule = db.rules().insert();
-    IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL));
-    userSession.logIn().addProjectPermission(ISSUE_ADMIN, project);
+    IssueDto issue = db.issues().insert(rule, project.getMainBranchComponent(), file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL));
+    userSession.logIn().addProjectPermission(ISSUE_ADMIN, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     List<Transition> result = underTest.listTransitions(issue.toDefaultIssue());
 
@@ -76,11 +78,12 @@ public class TransitionServiceIT {
 
   @Test
   public void list_transitions_returns_empty_list_on_external_issue() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project.getMainBranchComponent()));
     RuleDto externalRule = db.rules().insert(r -> r.setIsExternal(true));
-    IssueDto externalIssue = db.issues().insert(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL));
-    userSession.logIn().addProjectPermission(ISSUE_ADMIN, project);
+    IssueDto externalIssue = db.issues().insert(externalRule, project.getMainBranchComponent(), file, i -> i.setStatus(STATUS_OPEN).setResolution(null).setType(CODE_SMELL));
+    userSession.logIn().addProjectPermission(ISSUE_ADMIN, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     List<Transition> result = underTest.listTransitions(externalIssue.toDefaultIssue());
 
index d2098c3ee4ad98f948261c25074b3278824e7786..06bfd9aee92430ac2b27b22c838f612e3f78ac7d 100644 (file)
@@ -37,8 +37,8 @@ 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.common.avatar.AvatarResolverImpl;
+import org.sonar.server.es.EsTester;
 import org.sonar.server.issue.IssueFieldsSetter;
 import org.sonar.server.issue.TextRangeResponseFormatter;
 import org.sonar.server.issue.TransitionService;
@@ -368,7 +368,7 @@ public class SearchActionComponentsIT {
     IssueDto issueOnProject2 = db.issues().insertIssue(issueRule, project2, project2);
     db.issues().insertHotspot(hotspotRule, project2, project2);
     allowAnyoneOnProjects(projectData1.getProjectDto(), projectData2.getProjectDto(), applicatioData.getProjectDto());
-    userSession.addProjectPermission(USER, application);
+    userSession.addProjectPermission(USER, applicatioData.getProjectDto());
     indexIssuesAndViews();
 
     // All issues on applicationBranch1
index 22f778dbafef0a2ac588ddf515fd818f73d372d2..dadb18d6c0ede51a00d6226b05665ce9d7366936 100644 (file)
@@ -32,10 +32,12 @@ 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.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.IssueDbTester;
 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;
@@ -58,6 +60,7 @@ import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
 
+import static java.lang.String.format;
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -123,11 +126,11 @@ public class SetSeverityActionIT {
   @Test
   public void set_severity_is_not_distributed_for_pull_request() {
     RuleDto rule = dbTester.rules().insertIssueRule();
-    ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
+    ComponentDto mainBranch = dbTester.components().insertPrivateProject().getMainBranchComponent();
 
-    ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, b -> b.setKey("myBranch1")
+    ComponentDto pullRequest = dbTester.components().insertProjectBranch(mainBranch, b -> b.setKey("myBranch1")
       .setBranchType(BranchType.PULL_REQUEST)
-      .setMergeBranchUuid(project.uuid()));
+      .setMergeBranchUuid(mainBranch.uuid()));
 
     ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest));
     IssueDto issue = newIssue(rule, pullRequest, file).setType(CODE_SMELL).setSeverity(MAJOR);
@@ -177,7 +180,7 @@ public class SetSeverityActionIT {
 
   @Test
   public void fail_when_not_authenticated() {
-    assertThatThrownBy(() ->  call("ABCD", MAJOR))
+    assertThatThrownBy(() -> call("ABCD", MAJOR))
       .isInstanceOf(UnauthorizedException.class);
   }
 
@@ -217,17 +220,24 @@ public class SetSeverityActionIT {
   }
 
   private void logInAndAddProjectPermission(IssueDto issueDto, String permission) {
+    BranchDto branchDto = dbClient.branchDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid())
+      .orElseThrow(() -> new IllegalStateException(format("Couldn't find branch with uuid : %s", issueDto.getProjectUuid())));
     UserDto user = dbTester.users().insertUser("john");
     userSession.logIn(user)
-      .addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
+      .addProjectPermission(permission, dbClient.projectDao().selectByUuid(dbTester.getSession(), branchDto.getProjectUuid())
+        .orElseThrow(() -> new IllegalStateException(format("Couldn't find project with uuid %s", branchDto.getProjectUuid()))));
   }
 
   private void setUserWithBrowseAndAdministerIssuePermission(IssueDto issueDto) {
-    ComponentDto project = dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get();
+    BranchDto branchDto = dbClient.branchDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid())
+      .orElseThrow(() -> new IllegalStateException(format("Couldn't find branch with uuid : %s", issueDto.getProjectUuid())));
+    ProjectDto project = dbClient.projectDao().selectByUuid(dbTester.getSession(), branchDto.getProjectUuid())
+      .orElseThrow(() -> new IllegalStateException(format("Couldn't find project with uuid : %s", branchDto.getProjectUuid())));
     UserDto user = dbTester.users().insertUser("john");
     userSession.logIn(user)
       .addProjectPermission(ISSUE_ADMIN, project)
-      .addProjectPermission(USER, project);
+      .addProjectPermission(USER, project)
+      .registerBranches(branchDto);
   }
 
   private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) {
index 735b6373632a14ce651380a0dff18ef45045a1e0..9c0235c3be6c555a49328960dbad49cd5b5ab61f 100644 (file)
@@ -41,11 +41,14 @@ 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.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.IssueDbTester;
 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;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
@@ -66,6 +69,7 @@ import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.TestResponse;
 import org.sonar.server.ws.WsActionTester;
 
+import static java.lang.String.format;
 import static java.util.Optional.ofNullable;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -110,7 +114,8 @@ public class SetTypeActionIT {
     new IssueFinder(dbClient, userSession), new IssueFieldsSetter(),
     new IssueUpdater(dbClient,
       new WebIssueStorage(system2, dbClient, new DefaultRuleFinder(dbClient, mock(RuleDescriptionFormatter.class)), issueIndexer, new SequenceUuidFactory()),
-      mock(NotificationManager.class), issueChangePostProcessor, issuesChangesSerializer), responseWriter, system2));
+      mock(NotificationManager.class), issueChangePostProcessor, issuesChangesSerializer),
+    responseWriter, system2));
 
   @Test
   @UseDataProvider("allTypesFromToExceptHotspots")
@@ -262,14 +267,23 @@ public class SetTypeActionIT {
   }
 
   private void setUserWithBrowseAndAdministerIssuePermission(IssueDto issueDto) {
-    ComponentDto project = dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get();
-    userSession.logIn(dbTester.users().insertUser("john"))
+    BranchDto branchDto = dbClient.branchDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid())
+      .orElseThrow(() -> new IllegalStateException(format("Couldn't find branch with uuid : %s", issueDto.getProjectUuid())));
+    ProjectDto project = dbClient.projectDao().selectByUuid(dbTester.getSession(), branchDto.getProjectUuid())
+      .orElseThrow(() -> new IllegalStateException(format("Couldn't find project with uuid : %s", branchDto.getProjectUuid())));
+    UserDto user = dbTester.users().insertUser("john");
+    userSession.logIn(user)
       .addProjectPermission(ISSUE_ADMIN, project)
-      .addProjectPermission(USER, project);
+      .addProjectPermission(USER, project)
+      .registerBranches(branchDto);
   }
 
   private void logInAndAddProjectPermission(String login, IssueDto issueDto, String permission) {
-    userSession.logIn(login).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
+    BranchDto branchDto = dbClient.branchDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid())
+      .orElseThrow(() -> new IllegalStateException(format("Couldn't find branch with uuid : %s", issueDto.getProjectUuid())));
+    userSession.logIn(login)
+      .addProjectPermission(permission, dbClient.projectDao().selectByUuid(dbTester.getSession(), branchDto.getProjectUuid())
+        .orElseThrow(() -> new IllegalStateException(format("Couldn't find project with uuid %s", branchDto.getProjectUuid()))));
   }
 
   private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) {
index d526ae2ccbd0c63b291c30a1d0f5f19fdffb42eb..c95206420925dd0b22d3e5139f56f779c4d333ca 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.PortfolioData;
 import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.measure.LiveMeasureDto;
@@ -191,16 +192,16 @@ public class ComponentActionIT {
 
   @Test
   public void reference_key_in_the_response() {
-    ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto view = db.components().insertPrivatePortfolio();
-    userSession.addProjectPermission(USER, view);
-    db.components().insertSnapshot(view);
-    ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-uuid-copy", mainBranch, view));
+    ProjectData mainBranch = db.components().insertPrivateProject();
+    PortfolioData view = db.components().insertPrivatePortfolioData();
+    userSession.addProjectPermission(USER, view.getRootComponent());
+    db.components().insertSnapshot(view.getPortfolioDto());
+    ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-uuid-copy", mainBranch.getMainBranchComponent(), view.getRootComponent()));
     MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT"));
 
     ComponentWsResponse response = newRequest(projectCopy.getKey(), metric.getKey());
 
-    assertThat(response.getComponent().getRefKey()).isEqualTo(mainBranch.getKey());
+    assertThat(response.getComponent().getRefKey()).isEqualTo(mainBranch.getMainBranchComponent().getKey());
   }
 
   @Test
@@ -244,9 +245,10 @@ public class ComponentActionIT {
 
   @Test
   public void use_best_values() {
-    ComponentDto mainBranch = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(newFileDto(mainBranch));
-    userSession.addProjectPermission(USER, mainBranch);
+    ProjectData projectData = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(projectData.getMainBranchComponent()));
+    userSession.addProjectPermission(USER, projectData.getProjectDto())
+      .registerBranches(projectData.getMainBranchDto());
     MetricDto metric = db.measures().insertMetric(m -> m
       .setValueType("INT")
       .setBestValue(7.0d)
index 5cd7ef3be39d1f3e3c894e7a1992b2e59bd97ef5..885f045241155d1af3762ad303ded12d4846c986 100644 (file)
@@ -33,6 +33,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.component.SnapshotDto;
 import org.sonar.db.measure.MeasureDto;
 import org.sonar.db.metric.MetricDto;
@@ -58,9 +59,7 @@ import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.utils.DateUtils.formatDateTime;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
-import static org.sonar.db.component.ComponentDbTester.toProjectDto;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 import static org.sonar.db.measure.MeasureTesting.newMeasureDto;
@@ -85,7 +84,7 @@ public class SearchHistoryActionIT {
 
   private final WsActionTester ws = new WsActionTester(new SearchHistoryAction(dbClient, TestComponentFinder.from(db), userSession));
 
-  private ComponentDto project;
+  private ProjectData project;
   private SnapshotDto analysis;
   private MetricDto complexityMetric;
   private MetricDto nclocMetric;
@@ -94,9 +93,10 @@ public class SearchHistoryActionIT {
 
   @Before
   public void setUp() {
-    project = newPrivateProjectDto();
-    analysis = db.components().insertProjectAndSnapshot(project);
-    userSession.addProjectPermission(UserRole.USER, project);
+    project = db.components().insertPrivateProject();
+    analysis = db.components().insertSnapshot(project.getProjectDto());
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
     nclocMetric = insertNclocMetric();
     complexityMetric = insertComplexityMetric();
     newViolationMetric = insertNewViolationMetric();
@@ -105,10 +105,11 @@ public class SearchHistoryActionIT {
 
   @Test
   public void empty_response() {
-    project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
+    project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(singletonList(complexityMetric.getKey()))
       .build();
 
@@ -124,12 +125,13 @@ public class SearchHistoryActionIT {
 
   @Test
   public void analyses_but_no_measure() {
-    project = db.components().insertPrivateProject().getMainBranchComponent();
-    analysis = db.components().insertSnapshot(project);
-    userSession.addProjectPermission(UserRole.USER, project);
+    project = db.components().insertPrivateProject();
+    analysis = db.components().insertSnapshot(project.getProjectDto());
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(singletonList(complexityMetric.getKey()))
       .build();
 
@@ -142,11 +144,11 @@ public class SearchHistoryActionIT {
 
   @Test
   public void return_metrics() {
-    dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, analysis).setValue(42.0d));
+    dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project.mainBranchUuid(), analysis).setValue(42.0d));
     db.commit();
 
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey()))
       .build();
 
@@ -159,19 +161,19 @@ public class SearchHistoryActionIT {
 
   @Test
   public void return_measures() {
-    SnapshotDto laterAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(analysis.getCreatedAt() + 42_000));
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    SnapshotDto laterAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project.getMainBranchDto()).setCreatedAt(analysis.getCreatedAt() + 42_000));
+    ComponentDto file = db.components().insertComponent(newFileDto(project.getMainBranchComponent()));
     dbClient.measureDao().insert(dbSession,
-      newMeasureDto(complexityMetric, project, analysis).setValue(101d),
-      newMeasureDto(complexityMetric, project, laterAnalysis).setValue(100d),
+      newMeasureDto(complexityMetric, project.mainBranchUuid(), analysis).setValue(101d),
+      newMeasureDto(complexityMetric, project.mainBranchUuid(), laterAnalysis).setValue(100d),
       newMeasureDto(complexityMetric, file, analysis).setValue(42d),
-      newMeasureDto(nclocMetric, project, analysis).setValue(201d),
-      newMeasureDto(newViolationMetric, project, analysis).setValue(5d),
-      newMeasureDto(newViolationMetric, project, laterAnalysis).setValue(10d));
+      newMeasureDto(nclocMetric, project.mainBranchUuid(), analysis).setValue(201d),
+      newMeasureDto(newViolationMetric, project.mainBranchUuid(), analysis).setValue(5d),
+      newMeasureDto(newViolationMetric, project.mainBranchUuid(), laterAnalysis).setValue(10d));
     db.commit();
 
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey()))
       .build();
     SearchHistoryResponse result = call(request);
@@ -201,17 +203,18 @@ public class SearchHistoryActionIT {
 
   @Test
   public void pagination_applies_to_analyses() {
-    project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
+    project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
     List<String> analysisDates = LongStream.rangeClosed(1, 9)
-      .mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(i * 1_000_000_000)))
-      .peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, a).setValue(101d)))
+      .mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project.mainBranchUuid()).setCreatedAt(i * 1_000_000_000)))
+      .peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project.mainBranchUuid(), a).setValue(101d)))
       .map(a -> formatDateTime(a.getCreatedAt()))
       .toList();
     db.commit();
 
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey()))
       .setPage(2)
       .setPageSize(3)
@@ -225,17 +228,18 @@ public class SearchHistoryActionIT {
 
   @Test
   public void inclusive_from_and_to_dates() {
-    project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
+    project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
     List<String> analysisDates = LongStream.rangeClosed(1, 9)
-      .mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(System2.INSTANCE.now() + i * 1_000_000_000L)))
-      .peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, a).setValue(Double.valueOf(a.getCreatedAt()))))
+      .mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project.mainBranchUuid()).setCreatedAt(System2.INSTANCE.now() + i * 1_000_000_000L)))
+      .peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project.mainBranchUuid(), a).setValue(Double.valueOf(a.getCreatedAt()))))
       .map(a -> formatDateTime(a.getCreatedAt()))
       .toList();
     db.commit();
 
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey()))
       .setFrom(analysisDates.get(1))
       .setTo(analysisDates.get(3))
@@ -252,7 +256,7 @@ public class SearchHistoryActionIT {
     dbClient.metricDao().insert(dbSession, newMetricDto().setKey("optimized").setValueType(ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(456d));
     dbClient.metricDao().insert(dbSession, newMetricDto().setKey("new_optimized").setValueType(ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(789d));
     db.commit();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    ComponentDto file = db.components().insertComponent(newFileDto(project.getMainBranchComponent()));
 
     SearchHistoryRequest request = SearchHistoryRequest.builder()
       .setComponent(file.getKey())
@@ -266,7 +270,7 @@ public class SearchHistoryActionIT {
 
     // Best value is not applied to project
     request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(asList("optimized", "new_optimized"))
       .build();
     result = call(request);
@@ -277,11 +281,11 @@ public class SearchHistoryActionIT {
 
   @Test
   public void do_not_return_unprocessed_analyses() {
-    dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setStatus(STATUS_UNPROCESSED));
+    dbClient.snapshotDao().insert(dbSession, newAnalysis(project.getMainBranchDto()).setStatus(STATUS_UNPROCESSED));
     db.commit();
 
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey()))
       .build();
     SearchHistoryResponse result = call(request);
@@ -292,11 +296,11 @@ public class SearchHistoryActionIT {
 
   @Test
   public void branch() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
-    userSession.addProjectBranchMapping(project.uuid(), branch);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
+    ComponentDto branch = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setKey("my_branch"));
+    userSession.addProjectBranchMapping(project.projectUuid(), branch);
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.mainBranchUuid()));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
     MeasureDto measure = db.measures().insertMeasure(file, analysis, nclocMetric, m -> m.setValue(2d));
 
@@ -316,11 +320,11 @@ public class SearchHistoryActionIT {
 
   @Test
   public void pull_request() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
-    userSession.addProjectBranchMapping(project.uuid(), branch);
-    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
+    ComponentDto branch = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
+    userSession.addProjectBranchMapping(project.projectUuid(), branch);
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.mainBranchUuid()));
     SnapshotDto analysis = db.components().insertSnapshot(branch);
     MeasureDto measure = db.measures().insertMeasure(file, analysis, nclocMetric, m -> m.setValue(2d));
 
@@ -341,7 +345,7 @@ public class SearchHistoryActionIT {
   @Test
   public void fail_if_unknown_metric() {
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(asList(complexityMetric.getKey(), nclocMetric.getKey(), "METRIC_42", "42_METRIC"))
       .build();
 
@@ -352,9 +356,9 @@ public class SearchHistoryActionIT {
 
   @Test
   public void fail_if_not_enough_permissions() {
-    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project.getProjectDto());
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(singletonList(complexityMetric.getKey()))
       .build();
 
@@ -364,19 +368,19 @@ public class SearchHistoryActionIT {
 
   @Test
   public void fail_if_not_enough_permissions_for_application() {
-    ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
-    ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData application = db.components().insertPrivateApplication();
+    ProjectData project1 = db.components().insertPrivateProject();
+    ProjectData project2 = db.components().insertPrivateProject();
 
     userSession.logIn()
       .registerApplication(
-        toProjectDto(application, 1L),
-        toProjectDto(project1, 1L),
-        toProjectDto(project2, 1L))
-      .addProjectPermission(UserRole.USER, application, project1);
+        application.getProjectDto(),
+        project1.getProjectDto(),
+        project2.getProjectDto())
+      .addProjectPermission(UserRole.USER, application.getProjectDto(), project1.getProjectDto());
 
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(application.getKey())
+      .setComponent(application.projectKey())
       .setMetrics(singletonList(complexityMetric.getKey()))
       .build();
 
@@ -397,32 +401,32 @@ public class SearchHistoryActionIT {
 
   @Test
   public void fail_when_component_is_removed() {
-    ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
-    db.components().insertComponent(newFileDto(project).setKey("file-key").setEnabled(false));
-    userSession.addProjectPermission(UserRole.USER, project);
+    ProjectData projectData = db.components().insertPrivateProject();
+    db.components().insertComponent(newFileDto(project.getMainBranchComponent()).setKey("file-key").setEnabled(false));
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
 
     assertThatThrownBy(() -> ws.newRequest()
       .setParam(PARAM_COMPONENT, "file-key")
       .setParam(PARAM_METRICS, "ncloc")
       .execute())
-        .isInstanceOf(NotFoundException.class)
-        .hasMessageContaining("Component key 'file-key' not found");
+      .isInstanceOf(NotFoundException.class)
+      .hasMessageContaining("Component key 'file-key' not found");
   }
 
   @Test
   public void fail_if_branch_does_not_exist() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
-    userSession.addProjectPermission(UserRole.USER, project);
-    db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project.getMainBranchComponent()));
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
+    db.components().insertProjectBranch(project.getProjectDto(), b -> b.setKey("my_branch"));
 
     assertThatThrownBy(() -> ws.newRequest()
       .setParam(PARAM_COMPONENT, file.getKey())
       .setParam(PARAM_BRANCH, "another_branch")
       .setParam(PARAM_METRICS, "ncloc")
       .execute())
-        .isInstanceOf(NotFoundException.class)
-        .hasMessageContaining(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch"));
+      .isInstanceOf(NotFoundException.class)
+      .hasMessageContaining(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch"));
   }
 
   @Test
@@ -444,19 +448,20 @@ public class SearchHistoryActionIT {
 
   @Test
   public void json_example() {
-    project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(UserRole.USER, project);
+    project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
     long now = parseDateTime("2017-01-23T17:00:53+0100").getTime();
     LongStream.rangeClosed(0, 2)
-      .mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(now + i * 24 * 1_000 * 60 * 60)))
+      .mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project.getMainBranchDto()).setCreatedAt(now + i * 24 * 1_000 * 60 * 60)))
       .forEach(analysis -> dbClient.measureDao().insert(dbSession,
-        newMeasureDto(complexityMetric, project, analysis).setValue(45d),
-        newMeasureDto(newViolationMetric, project, analysis).setValue(46d),
-        newMeasureDto(nclocMetric, project, analysis).setValue(47d)));
+        newMeasureDto(complexityMetric, project.mainBranchUuid(), analysis).setValue(45d),
+        newMeasureDto(newViolationMetric, project.mainBranchUuid(), analysis).setValue(46d),
+        newMeasureDto(nclocMetric, project.mainBranchUuid(), analysis).setValue(47d)));
     db.commit();
 
     String result = ws.newRequest()
-      .setParam(PARAM_COMPONENT, project.getKey())
+      .setParam(PARAM_COMPONENT, project.projectKey())
       .setParam(PARAM_METRICS, String.join(",", asList(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey())))
       .execute().getInput();
 
@@ -465,11 +470,11 @@ public class SearchHistoryActionIT {
 
   @Test
   public void measure_without_values() {
-    dbClient.measureDao().insert(dbSession, newMeasureDto(stringMetric, project, analysis).setValue(null).setData(null));
+    dbClient.measureDao().insert(dbSession, newMeasureDto(stringMetric, project.mainBranchUuid(), analysis).setValue(null).setData(null));
     db.commit();
 
     SearchHistoryRequest request = SearchHistoryRequest.builder()
-      .setComponent(project.getKey())
+      .setComponent(project.projectKey())
       .setMetrics(singletonList(stringMetric.getKey()))
       .build();
     SearchHistoryResponse result = call(request);
index 95daf2d9739244401511de8541c2bd94fe053558..56ed14647e1ebe30ff240ed6798a823658eb76b5 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.api.notifications.Notification;
 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.project.ProjectDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.component.TestComponentFinder;
@@ -264,13 +265,12 @@ public class AddActionIT {
 
   @Test
   public void fail_when_unknown_project_dispatcher_on_private_project() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.addProjectPermission(USER, project);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.addProjectPermission(USER, project.getProjectDto());
     when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES));
     when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES));
 
-    String projectKey = project.getKey();
-    assertThatThrownBy(() -> call("Dispatcher42", null, projectKey, null))
+    assertThatThrownBy(() -> call("Dispatcher42", null, project.projectKey(), null))
       .isInstanceOf(BadRequestException.class)
       .hasMessageContaining("Value of parameter 'type' (Dispatcher42) must be one of: [Dispatcher1, Dispatcher2]");
   }
index 50856df0e559e52ae4df86d3d4886663593c9e2a..b2fe86e9cc0f4edd9e188658d70d0b4f6f6d11b3 100644 (file)
@@ -31,11 +31,11 @@ import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.portfolio.PortfolioDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.UserDto;
+import org.sonar.server.common.management.ManagedInstanceChecker;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.exceptions.ServerException;
-import org.sonar.server.common.management.ManagedInstanceChecker;
 import org.sonar.server.permission.PermissionService;
 import org.sonar.server.permission.PermissionServiceImpl;
 import org.sonar.server.ws.TestRequest;
index 4b8645f3231a3b6d2db9869eef6bb3e4e28c9610..eb320ef22707edc16080cf72dd22d6febc0ab2f2 100644 (file)
@@ -26,16 +26,18 @@ import org.sonar.api.resources.ResourceTypes;
 import org.sonar.api.server.ws.WebService.Param;
 import org.sonar.api.server.ws.WebService.SelectionMode;
 import org.sonar.api.web.UserRole;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.UserDto;
+import org.sonar.server.common.avatar.AvatarResolverImpl;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.common.avatar.AvatarResolverImpl;
 import org.sonar.server.management.ManagedInstanceService;
 import org.sonar.server.permission.PermissionService;
 import org.sonar.server.permission.PermissionServiceImpl;
@@ -330,14 +332,14 @@ public class UsersActionIT extends BasePermissionWsIT<UsersAction> {
   @Test
   public void fail_when_using_branch_uuid() {
     UserDto user = db.users().insertUser(newUserDto());
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    ComponentDto branch = db.components().insertProjectBranch(project);
-    db.users().insertProjectPermissionOnUser(user, UserRole.ISSUE_ADMIN, project);
-    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
+    ProjectData project = db.components().insertPublicProject();
+    BranchDto branch = db.components().insertProjectBranch(project.getProjectDto());
+    db.users().insertProjectPermissionOnUser(user, UserRole.ISSUE_ADMIN, project.getProjectDto());
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project.getProjectDto());
 
     assertThatThrownBy(() -> {
       newRequest()
-        .setParam(PARAM_PROJECT_ID, branch.uuid())
+        .setParam(PARAM_PROJECT_ID, branch.getUuid())
         .setParam(PARAM_USER_LOGIN, user.getLogin())
         .setParam(PARAM_PERMISSION, GlobalPermission.ADMINISTER.getKey())
         .execute();
index 78e4d1f96a9eb06404f7248d811909b48892e409..a7a77639043e476a4fde1eb561419272d6961e7e 100644 (file)
@@ -150,14 +150,14 @@ public class DeleteActionIT {
 
   @Test
   public void return_403_if_not_project_admin_nor_org_admin() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData project = db.components().insertPrivateProject();
 
     userSessionRule.logIn()
-      .addProjectPermission(UserRole.CODEVIEWER, project)
-      .addProjectPermission(UserRole.ISSUE_ADMIN, project)
-      .addProjectPermission(UserRole.USER, project);
+      .addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto())
+      .addProjectPermission(UserRole.ISSUE_ADMIN, project.getProjectDto())
+      .addProjectPermission(UserRole.USER, project.getProjectDto());
 
-    TestRequest request = tester.newRequest().setParam(PARAM_PROJECT, project.getKey());
+    TestRequest request = tester.newRequest().setParam(PARAM_PROJECT, project.projectKey());
     assertThatThrownBy(() -> call(request))
       .isInstanceOf(ForbiddenException.class);
   }
index 48c186e64564524baa85e7437c4267d4736e64c6..1f9490a9e0dc632f98c2a1b320f6a48290a4f178 100644 (file)
@@ -53,13 +53,13 @@ import org.sonar.db.portfolio.PortfolioDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
+import org.sonar.server.common.management.ManagedInstanceChecker;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.es.Indexers;
 import org.sonar.server.es.TestIndexers;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.UnauthorizedException;
-import org.sonar.server.common.management.ManagedInstanceChecker;
 import org.sonar.server.permission.PermissionService;
 import org.sonar.server.permission.PermissionServiceImpl;
 import org.sonar.server.permission.index.FooIndexDefinition;
@@ -243,10 +243,10 @@ public class UpdateVisibilityActionIT {
 
   @Test
   public void execute_throws_ForbiddenException_if_user_has_all_permissions_but_ADMIN_on_specified_component() {
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    request.setParam(PARAM_PROJECT, project.getKey())
+    ProjectData project = dbTester.components().insertPublicProject();
+    request.setParam(PARAM_PROJECT, project.projectKey())
       .setParam(PARAM_VISIBILITY, randomVisibility);
-    userSessionRule.addProjectPermission(UserRole.ISSUE_ADMIN, project);
+    userSessionRule.addProjectPermission(UserRole.ISSUE_ADMIN, project.getProjectDto());
     Arrays.stream(GlobalPermission.values())
       .forEach(userSessionRule::addPermission);
 
@@ -258,10 +258,10 @@ public class UpdateVisibilityActionIT {
   @Test
   public void execute_throws_ForbiddenException_if_user_has_ADMIN_permission_but_sonar_allowPermissionManagementForProjectAdmins_is_set_to_false() {
     when(configuration.getBoolean(CORE_ALLOW_PERMISSION_MANAGEMENT_FOR_PROJECT_ADMINS_PROPERTY)).thenReturn(of(false));
-    ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-    request.setParam(PARAM_PROJECT, project.getKey())
+    ProjectData project = dbTester.components().insertPublicProject();
+    request.setParam(PARAM_PROJECT, project.projectKey())
       .setParam(PARAM_VISIBILITY, randomVisibility);
-    userSessionRule.addProjectPermission(UserRole.ADMIN, project);
+    userSessionRule.addProjectPermission(UserRole.ADMIN, project.getProjectDto());
 
     assertThatThrownBy(request::execute)
       .isInstanceOf(ForbiddenException.class)
index d747bb04732a35cf07276817fa37645b68c0e4ef..fefb41fb5b54cc3c4d1b935ee6672b6bde2705a4 100644 (file)
@@ -28,6 +28,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.component.SnapshotDto;
 import org.sonar.db.newcodeperiod.NewCodePeriodDto;
 import org.sonar.db.newcodeperiod.NewCodePeriodType;
@@ -57,9 +58,9 @@ public class DeleteActionIT {
 
   @Test
   public void project_administrator_deletes_analysis() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(false).setStatus(STATUS_PROCESSED));
-    db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setLast(true).setStatus(STATUS_PROCESSED));
+    ProjectData project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(newAnalysis(project.getMainBranchDto()).setUuid("A1").setLast(false).setStatus(STATUS_PROCESSED));
+    db.components().insertSnapshot(newAnalysis(project.getMainBranchDto()).setUuid("A2").setLast(true).setStatus(STATUS_PROCESSED));
     logInAsProjectAdministrator(project);
 
     call("A1");
@@ -81,8 +82,8 @@ public class DeleteActionIT {
 
   @Test
   public void last_analysis_cannot_be_deleted() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(true));
+    ProjectData project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(newAnalysis(project.getMainBranchDto()).setUuid("A1").setLast(true));
     logInAsProjectAdministrator(project);
 
     assertThatThrownBy(() -> call("A1"))
@@ -93,11 +94,11 @@ public class DeleteActionIT {
   @Test
   public void fail_when_analysis_is_new_code_period_baseline() {
     String analysisUuid = RandomStringUtils.randomAlphabetic(12);
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setUuid(analysisUuid).setLast(false));
+    ProjectData project = db.components().insertPrivateProject();
+    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project.getMainBranchDto()).setUuid(analysisUuid).setLast(false));
     db.newCodePeriods().insert(new NewCodePeriodDto()
-      .setProjectUuid(project.uuid())
-      .setBranchUuid(project.uuid())
+      .setProjectUuid(project.projectUuid())
+      .setBranchUuid(project.mainBranchUuid())
       .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
       .setValue(analysis.getUuid()));
     db.commit();
@@ -119,8 +120,8 @@ public class DeleteActionIT {
 
   @Test
   public void fail_when_analysis_is_unprocessed() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setLast(false).setStatus(STATUS_UNPROCESSED));
+    ProjectData project = db.components().insertPrivateProject();
+    db.components().insertSnapshot(newAnalysis(project.getMainBranchDto()).setUuid("A1").setLast(false).setStatus(STATUS_UNPROCESSED));
     logInAsProjectAdministrator(project);
 
     assertThatThrownBy(() -> call("A1"))
@@ -144,7 +145,8 @@ public class DeleteActionIT {
       .execute();
   }
 
-  private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
+  private void logInAsProjectAdministrator(ProjectData project) {
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
   }
 }
index d29a25e84c25278df9064d21219fc31ffe1959a1..e2ea72b1d4b624c6bab416cb5cad9c22378d256f 100644 (file)
@@ -29,8 +29,8 @@ import org.sonar.api.web.UserRole;
 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.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.event.EventDto;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -41,7 +41,6 @@ import org.sonar.server.ws.WsActionTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 import static org.sonar.db.event.EventTesting.newEvent;
 import static org.sonar.server.projectanalysis.ws.EventCategory.VERSION;
@@ -59,8 +58,8 @@ public class DeleteEventActionIT {
 
   @Test
   public void delete_event() {
-    ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
+    ProjectData project = db.components().insertPrivateProject();
+    SnapshotDto analysis = db.components().insertSnapshot(project.getMainBranchDto());
     db.events().insertEvent(newEvent(analysis).setUuid("E1"));
     db.events().insertEvent(newEvent(analysis).setUuid("E2"));
     logInAsProjectAdministrator(project);
@@ -73,8 +72,8 @@ public class DeleteEventActionIT {
 
   @Test
   public void delete_version_event() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion("5.6.3").setLast(false));
+    ProjectData project = db.components().insertPrivateProject();
+    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project.getMainBranchDto()).setProjectVersion("5.6.3").setLast(false));
     db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel()));
     logInAsProjectAdministrator(project);
 
@@ -86,8 +85,8 @@ public class DeleteEventActionIT {
 
   @Test
   public void fail_if_version_for_last_analysis() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion("5.6.3").setLast(true));
+    ProjectData project = db.components().insertPrivateProject();
+    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project.getMainBranchDto()).setProjectVersion("5.6.3").setLast(true));
     db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel()));
     logInAsProjectAdministrator(project);
 
@@ -98,8 +97,8 @@ public class DeleteEventActionIT {
 
   @Test
   public void fail_if_category_different_than_other_and_version() {
-    ComponentDto project = newPrivateProjectDto("P1");
-    SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
+    ProjectData project = db.components().insertPrivateProject();
+    SnapshotDto analysis = db.components().insertSnapshot(project.getMainBranchDto());
     db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory("Profile"));
     logInAsProjectAdministrator(project);
 
@@ -149,7 +148,8 @@ public class DeleteEventActionIT {
     request.execute();
   }
 
-  private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
+  private void logInAsProjectAdministrator(ProjectData project) {
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
   }
 }
index 33e94ac67b502e72248d19db0d53ecd0d4a059bd..e66fb872c651136b1c29bb59cdac6dc16150be8b 100644 (file)
@@ -28,8 +28,7 @@ import org.sonar.api.web.UserRole;
 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.ComponentTesting;
+import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.SnapshotDto;
 import org.sonar.db.event.EventDto;
 import org.sonar.server.exceptions.ForbiddenException;
@@ -65,8 +64,8 @@ public class UpdateEventActionIT {
 
   @Test
   public void json_example() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setUuid("A2"));
+    ProjectData project = db.components().insertPrivateProject();
+    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project.getMainBranchDto()).setUuid("A2"));
     db.events().insertEvent(newEvent(analysis)
       .setUuid("E1")
       .setCategory(OTHER.getLabel())
@@ -159,10 +158,10 @@ public class UpdateEventActionIT {
 
   @Test
   public void throw_ForbiddenException_if_not_project_administrator() {
-    ComponentDto project = ComponentTesting.newPrivateProjectDto();
-    SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
+    ProjectData project = db.components().insertPrivateProject();
+    SnapshotDto analysis = db.components().insertSnapshot(project.getMainBranchDto());
     db.events().insertEvent(newEvent(analysis).setUuid("E1"));
-    userSession.logIn().addProjectPermission(UserRole.USER, project);
+    userSession.logIn().addProjectPermission(UserRole.USER, project.getProjectDto());
 
     assertThatThrownBy(() -> call("E1", "name"))
       .isInstanceOf(ForbiddenException.class);
@@ -244,13 +243,14 @@ public class UpdateEventActionIT {
     return request.executeProtobuf(UpdateEventResponse.class);
   }
 
-  private void logInAsProjectAdministrator(ComponentDto project) {
-    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
+  private void logInAsProjectAdministrator(ProjectData project) {
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
   }
 
   private SnapshotDto createAnalysisAndLogInAsProjectAdministrator(String version) {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion(version));
+    ProjectData project = db.components().insertPrivateProject();
+    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project.getMainBranchDto()).setProjectVersion(version));
     logInAsProjectAdministrator(project);
     return analysis;
   }
index bd454fc3a7beb4d79b7a60e5cda01b7993d534e6..88ce46ea2711ba872a88b75b3b57745c205957e9 100644 (file)
@@ -29,8 +29,10 @@ import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 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.PortfolioData;
 import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.ProjectLinkDto;
 import org.sonar.db.project.ProjectDto;
@@ -189,41 +191,56 @@ public class CreateActionIT {
 
   @Test
   public void fail_if_directory() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(project, "A/B"));
-    failIfNotAProjectWithKey(project, directory);
-    failIfNotAProjectWithUuid(project, directory);
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(project.getMainBranchComponent(), "A/B"));
+    failIfNotAProjectWithKey(project.getProjectDto(), directory);
+    failIfNotAProjectWithUuid(project.getProjectDto(), directory);
   }
 
   @Test
   public void fail_if_file() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
-    failIfNotAProjectWithKey(project, file);
-    failIfNotAProjectWithUuid(project, file);
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project.getMainBranchComponent()));
+    failIfNotAProjectWithKey(project.getProjectDto(), file);
+    failIfNotAProjectWithUuid(project.getProjectDto(), file);
   }
 
   @Test
   public void fail_if_view() {
-    ComponentDto view = db.components().insertPrivatePortfolio();
-    failIfNotAProjectWithKey(view, view);
-    failIfNotAProjectWithUuid(view, view);
+    PortfolioData view = db.components().insertPrivatePortfolioData();
+
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, view.getRootComponent());
+    assertThatThrownBy(() -> ws.newRequest()
+      .setParam(PARAM_NAME, "Custom")
+      .setParam(PARAM_URL, "http://example.org")
+      .setParam(PARAM_PROJECT_KEY, view.getPortfolioDto().getKey())
+      .execute())
+      .isInstanceOf(NotFoundException.class)
+      .hasMessageContaining("Project '" + view.getPortfolioDto().getKey() + "' not found");
+
+    assertThatThrownBy(() -> ws.newRequest()
+      .setParam(PARAM_NAME, "Custom")
+      .setParam(PARAM_URL, "http://example.org")
+      .setParam(PARAM_PROJECT_ID, view.getPortfolioDto().getUuid())
+      .execute())
+      .isInstanceOf(NotFoundException.class)
+      .hasMessageContaining("Project '" + view.getPortfolioDto().getUuid() + "' not found");
 
   }
 
   @Test
   public void fail_when_using_branch_db_uuid() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.logIn().addProjectPermission(UserRole.USER, project);
-    ComponentDto branch = db.components().insertProjectBranch(project);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.logIn().addProjectPermission(UserRole.USER, project.getProjectDto());
+    BranchDto branch = db.components().insertProjectBranch(project.getProjectDto());
 
     assertThatThrownBy(() -> ws.newRequest()
-      .setParam(PARAM_PROJECT_ID, branch.uuid())
+      .setParam(PARAM_PROJECT_ID, branch.getUuid())
       .setParam(PARAM_NAME, "Custom")
       .setParam(PARAM_URL, "http://example.org")
       .execute())
       .isInstanceOf(NotFoundException.class)
-      .hasMessageContaining(format("Project '%s' not found", branch.uuid()));
+      .hasMessageContaining(format("Project '%s' not found", branch.getUuid()));
   }
 
   @Test
@@ -236,8 +253,8 @@ public class CreateActionIT {
     assertThat(action.params()).hasSize(4);
   }
 
-  private void failIfNotAProjectWithKey(ComponentDto root, ComponentDto component) {
-    userSession.logIn().addProjectPermission(UserRole.ADMIN, root);
+  private void failIfNotAProjectWithKey(ProjectDto project, ComponentDto component) {
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     assertThatThrownBy(() -> ws.newRequest()
       .setParam(PARAM_NAME, "Custom")
@@ -248,8 +265,8 @@ public class CreateActionIT {
       .hasMessageContaining("Project '" + component.getKey() + "' not found");
   }
 
-  private void failIfNotAProjectWithUuid(ComponentDto root, ComponentDto component) {
-    userSession.logIn().addProjectPermission(UserRole.ADMIN, root);
+  private void failIfNotAProjectWithUuid(ProjectDto project, ComponentDto component) {
+    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
 
     assertThatThrownBy(() -> ws.newRequest()
       .setParam(PARAM_NAME, "Custom")
index a25af07a1786d0ab07272ca7c3fdcd910019c0ec..df3f4ecb4e3c078e21a04d37ab3918cc916ef1bc 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.project.ProjectDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.ComponentFinder;
@@ -138,11 +139,11 @@ public class DeselectActionIT {
 
   @Test
   public void fail_when_not_project_admin() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.logIn().addProjectPermission(UserRole.ISSUE_ADMIN, project);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.logIn().addProjectPermission(UserRole.ISSUE_ADMIN, project.getProjectDto());
 
     assertThatThrownBy(() -> ws.newRequest()
-      .setParam("projectKey", project.getKey())
+      .setParam("projectKey", project.projectKey())
       .execute())
       .isInstanceOf(ForbiddenException.class);
   }
index bc4efd5d2bc915481aab50fb12d6459dec469ec9..618639e0bfad7d7af9e3ee9f315b3babe7a3366e 100644 (file)
@@ -25,6 +25,7 @@ import org.junit.Test;
 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.project.ProjectDto;
 import org.sonar.db.qualitygate.QualityGateDto;
 import org.sonar.server.component.ComponentFinder;
@@ -175,12 +176,12 @@ public class SelectActionIT {
   @Test
   public void fail_when_not_project_admin() {
     QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    userSession.logIn().addProjectPermission(ISSUE_ADMIN, project);
+    ProjectData project = db.components().insertPrivateProject();
+    userSession.logIn().addProjectPermission(ISSUE_ADMIN, project.getProjectDto());
 
     assertThatThrownBy(() -> ws.newRequest()
       .setParam(PARAM_GATE_NAME, qualityGate.getName())
-      .setParam("projectKey", project.getKey())
+      .setParam("projectKey", project.projectKey())
       .execute())
       .isInstanceOf(ForbiddenException.class);
   }
index 8ab9426c4164f8a0fb0a82003cc48181b32aadf0..86f94d69c9ee4b12eed69e413177ca360ad404f0 100644 (file)
@@ -28,11 +28,13 @@ import org.sonar.api.web.UserRole;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.DbTester;
 import org.sonar.db.audit.NoOpAuditPersister;
+import org.sonar.db.component.BranchDto;
 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.project.ProjectDto;
 import org.sonar.db.protobuf.DbFileSources;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.db.user.UserDto;
@@ -79,9 +81,9 @@ public class LinesActionIT {
 
   @Test
   public void show_source() {
-    ComponentDto privateProject = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(3).build(), privateProject);
-    setUserWithValidPermission(file, privateProject);
+    ProjectData privateProject = db.components().insertPrivateProject();
+    ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(3).build(), privateProject.getMainBranchComponent());
+    setUserWithValidPermission(privateProject);
 
     TestResponse response = tester.newRequest()
       .setParam("uuid", file.uuid())
@@ -92,9 +94,9 @@ public class LinesActionIT {
 
   @Test
   public void fail_to_show_source_if_no_source_found() {
-    ComponentDto privateProject = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = insertFile(privateProject);
-    setUserWithValidPermission(file, privateProject);
+    ProjectData privateProject = db.components().insertPrivateProject();
+    ComponentDto file = insertFile(privateProject.getMainBranchComponent());
+    setUserWithValidPermission(privateProject);
 
     TestRequest request = tester.newRequest()
       .setParam("uuid", file.uuid());
@@ -105,9 +107,9 @@ public class LinesActionIT {
 
   @Test
   public void show_paginated_lines() {
-    ComponentDto privateProject = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(3).build(), privateProject);
-    setUserWithValidPermission(file, privateProject);
+    ProjectData privateProject = db.components().insertPrivateProject();
+    ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(3).build(), privateProject.getMainBranchComponent());
+    setUserWithValidPermission(privateProject);
 
     tester
       .newRequest()
@@ -120,11 +122,11 @@ public class LinesActionIT {
 
   @Test
   public void branch() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData project = db.components().insertPrivateProject();
 
     String branchName = randomAlphanumeric(248);
-    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
-    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
+    ComponentDto branch = db.components().insertProjectBranch(project.getMainBranchComponent(), b -> b.setKey(branchName));
+    ComponentDto file = db.components().insertComponent(newFileDto(branch, project.mainBranchUuid()));
     db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto()
       .setUuid(Uuids.createFast())
       .setProjectUuid(branch.uuid())
@@ -133,9 +135,9 @@ public class LinesActionIT {
     db.commit();
 
     userSession.logIn("login")
-      .addProjectPermission(UserRole.USER, project)
-      .addProjectBranchMapping(project.uuid(), branch)
-      .addProjectPermission(UserRole.CODEVIEWER, project, file);
+      .addProjectPermission(UserRole.USER, project.getProjectDto())
+      .addProjectBranchMapping(project.projectUuid(), branch)
+      .addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto());
 
     tester.newRequest()
       .setParam("key", file.getKey())
@@ -161,7 +163,7 @@ public class LinesActionIT {
     userSession.logIn("login")
       .addProjectPermission(UserRole.USER, projectData.getProjectDto())
       .addProjectPermission(UserRole.CODEVIEWER, projectData.getProjectDto())
-      .addProjectPermission(UserRole.CODEVIEWER, file);
+      .addProjectBranchMapping(projectData.projectUuid(), branch);
 
     tester.newRequest()
       .setParam("key", file.getKey())
@@ -193,10 +195,10 @@ public class LinesActionIT {
 
   @Test
   public void fail_when_file_is_removed() {
-    ComponentDto privateProject = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = newFileDto(privateProject).setKey("file-key").setEnabled(false);
+    ProjectData privateProject = db.components().insertPrivateProject();
+    ComponentDto file = newFileDto(privateProject.getMainBranchComponent()).setKey("file-key").setEnabled(false);
     db.components().insertComponents(file);
-    setUserWithValidPermission(file, privateProject);
+    setUserWithValidPermission(privateProject);
 
     assertThatThrownBy(() -> tester.newRequest().setParam("key", "file-key").execute())
       .isInstanceOf(NotFoundException.class)
@@ -220,9 +222,9 @@ public class LinesActionIT {
 
   @Test
   public void display_deprecated_fields() {
-    ComponentDto privateProject = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(1).build(), privateProject);
-    setUserWithValidPermission(file, privateProject);
+    ProjectData privateProject = db.components().insertPrivateProject();
+    ComponentDto file = insertFileWithData(FileSourceTesting.newFakeData(1).build(), privateProject.getMainBranchComponent());
+    setUserWithValidPermission(privateProject);
 
     tester.newRequest()
       .setParam("uuid", file.uuid())
@@ -237,10 +239,10 @@ public class LinesActionIT {
     dataBuilder.addLines(DbFileSources.Line.newBuilder().setLine(2).setScmDate(2000L).build());
     // only this line should be considered as new
     dataBuilder.addLines(DbFileSources.Line.newBuilder().setLine(3).setScmDate(3000L).build());
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    insertPeriod(project, 2000L);
-    ComponentDto file = insertFileWithData(dataBuilder.build(), project);
-    setUserWithValidPermission(file, project);
+    ProjectData project = db.components().insertPrivateProject();
+    insertPeriod(project.getMainBranchComponent(), 2000L);
+    ComponentDto file = insertFileWithData(dataBuilder.build(), project.getMainBranchComponent());
+    setUserWithValidPermission(project);
 
     tester.newRequest()
       .setParam("uuid", file.uuid())
@@ -250,7 +252,7 @@ public class LinesActionIT {
 
   @Test
   public void use_deprecated_overall_coverage_fields_if_exists() {
-    ComponentDto privateProject = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData privateProject = db.components().insertPrivateProject();
     DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder();
     ComponentDto file = insertFileWithData(dataBuilder.addLines(newLineBuilder()
       .setDeprecatedOverallLineHits(1)
@@ -261,8 +263,8 @@ public class LinesActionIT {
       .setDeprecatedUtCoveredConditions(3)
       .setDeprecatedItLineHits(1)
       .setDeprecatedItConditions(2)
-      .setDeprecatedItCoveredConditions(3)).build(), privateProject);
-    setUserWithValidPermission(file, privateProject);
+      .setDeprecatedItCoveredConditions(3)).build(), privateProject.getMainBranchComponent());
+    setUserWithValidPermission(privateProject);
 
     tester.newRequest()
       .setParam("uuid", file.uuid())
@@ -272,7 +274,7 @@ public class LinesActionIT {
 
   @Test
   public void use_deprecated_ut_coverage_fields_if_exists() {
-    ComponentDto privateProject = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData privateProject = db.components().insertPrivateProject();
     DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder();
     ComponentDto file = insertFileWithData(dataBuilder.addLines(newLineBuilder()
       .setDeprecatedUtLineHits(1)
@@ -280,8 +282,8 @@ public class LinesActionIT {
       .setDeprecatedUtCoveredConditions(3)
       .setDeprecatedItLineHits(1)
       .setDeprecatedItConditions(2)
-      .setDeprecatedItCoveredConditions(3)).build(), privateProject);
-    setUserWithValidPermission(file, privateProject);
+      .setDeprecatedItCoveredConditions(3)).build(), privateProject.getMainBranchComponent());
+    setUserWithValidPermission(privateProject);
 
     tester.newRequest()
       .setParam("uuid", file.uuid())
@@ -291,13 +293,13 @@ public class LinesActionIT {
 
   @Test
   public void use_deprecated_it_coverage_fields_if_exists() {
-    ComponentDto privateProject = db.components().insertPrivateProject().getMainBranchComponent();
+    ProjectData privateProject = db.components().insertPrivateProject();
     DbFileSources.Data.Builder dataBuilder = DbFileSources.Data.newBuilder();
     ComponentDto file = insertFileWithData(dataBuilder.addLines(newLineBuilder()
       .setDeprecatedItLineHits(1)
       .setDeprecatedItConditions(2)
-      .setDeprecatedItCoveredConditions(3)).build(), privateProject);
-    setUserWithValidPermission(file, privateProject);
+      .setDeprecatedItCoveredConditions(3)).build(), privateProject.getMainBranchComponent());
+    setUserWithValidPermission(privateProject);
 
     tester.newRequest()
       .setParam("uuid", file.uuid())
@@ -307,45 +309,45 @@ public class LinesActionIT {
 
   @Test
   public void fail_if_branch_does_not_exist() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
-    userSession.addProjectPermission(UserRole.USER, project);
-    db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project.getMainBranchComponent()));
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
+    db.components().insertProjectBranch(project.getProjectDto(), b -> b.setKey("my_branch"));
 
     assertThatThrownBy(() -> tester.newRequest()
       .setParam("key", file.getKey())
       .setParam("branch", "another_branch")
       .execute())
-        .isInstanceOf(NotFoundException.class)
-        .hasMessageContaining(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch"));
+      .isInstanceOf(NotFoundException.class)
+      .hasMessageContaining(String.format("Component '%s' on branch '%s' not found", file.getKey(), "another_branch"));
   }
 
   @Test
   public void fail_when_uuid_and_branch_params_are_used_together() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto file = db.components().insertComponent(newFileDto(project));
-    userSession.addProjectPermission(UserRole.USER, project);
-    db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
+    ProjectData project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project.getMainBranchComponent()));
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
+    db.components().insertProjectBranch(project.getProjectDto(), b -> b.setKey("my_branch"));
 
     assertThatThrownBy(() -> tester.newRequest()
       .setParam("uuid", file.uuid())
       .setParam("branch", "another_branch")
       .execute())
-        .isInstanceOf(IllegalArgumentException.class)
-        .hasMessageContaining("Parameter 'uuid' cannot be used at the same time as 'branch' or 'pullRequest'");
+      .isInstanceOf(IllegalArgumentException.class)
+      .hasMessageContaining("Parameter 'uuid' cannot be used at the same time as 'branch' or 'pullRequest'");
   }
 
   @Test
   public void fail_when_using_branch_uuid() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    ComponentDto branch = db.components().insertProjectBranch(project);
-    userSession.addProjectPermission(UserRole.USER, project);
+    ProjectData project = db.components().insertPrivateProject();
+    BranchDto branch = db.components().insertProjectBranch(project.getProjectDto());
+    userSession.addProjectPermission(UserRole.USER, project.getProjectDto());
 
     assertThatThrownBy(() -> tester.newRequest()
-      .setParam("uuid", branch.uuid())
+      .setParam("uuid", branch.getUuid())
       .execute())
-        .isInstanceOf(NotFoundException.class)
-        .hasMessageContaining(format("Component id '%s' not found", branch.uuid()));
+      .isInstanceOf(NotFoundException.class)
+      .hasMessageContaining(format("Component id '%s' not found", branch.getUuid()));
   }
 
   @Test
@@ -399,9 +401,10 @@ public class LinesActionIT {
     return file;
   }
 
-  private void setUserWithValidPermission(ComponentDto file, ComponentDto privateProject) {
+  private void setUserWithValidPermission(ProjectData privateProject) {
     userSession.logIn("login")
-      .addProjectPermission(UserRole.CODEVIEWER, privateProject, file);
+      .addProjectPermission(UserRole.CODEVIEWER, privateProject.getProjectDto())
+      .registerBranches(privateProject.getMainBranchDto());
   }
 
   private ComponentDto insertFile(ComponentDto project) {
index 8ec90888d791ae48d52aed13fb7f7d39c9979754..4f8a2722aafc616b96377d167424b7ca1237e00e 100644 (file)
@@ -32,6 +32,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.protobuf.DbFileSources;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.server.component.TestComponentFinder;
@@ -59,20 +60,21 @@ public class ScmActionIT {
   private final ScmAction underTest = new ScmAction(dbClient, new SourceService(dbTester.getDbClient(), new HtmlSourceDecorator()),
     userSessionRule, TestComponentFinder.from(dbTester));
   private final WsActionTester tester = new WsActionTester(underTest);
-  private ComponentDto project;
+  private ProjectData project;
   private ComponentDto file;
 
   @Before
   public void setUp() {
-    project = dbTester.components().insertPrivateProject(PROJECT_UUID).getMainBranchComponent();
-    file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY);
+    project = dbTester.components().insertPrivateProject(PROJECT_UUID);
+    file = ComponentTesting.newFileDto(project.getMainBranchComponent(), null, FILE_UUID).setKey(FILE_KEY);
     dbClient.componentDao().insertOnMainBranch(dbTester.getSession(), file);
     dbTester.getSession().commit();
   }
 
   @Test
   public void show_scm() {
-    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
       .setUuid(Uuids.createFast())
@@ -90,7 +92,8 @@ public class ScmActionIT {
 
   @Test
   public void show_scm_from_given_range_lines() {
-    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
       .setUuid(Uuids.createFast())
@@ -114,7 +117,8 @@ public class ScmActionIT {
 
   @Test
   public void not_group_lines_by_commit() {
-    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     // lines 1 and 2 are the same commit, but not 3 (different date)
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
@@ -138,7 +142,8 @@ public class ScmActionIT {
 
   @Test
   public void group_lines_by_commit() {
-    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     // lines 1 and 2 are the same commit, but not 3 (different date)
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
@@ -162,7 +167,8 @@ public class ScmActionIT {
 
   @Test
   public void accept_negative_value_in_from_parameter() {
-    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
       .setUuid(Uuids.createFast())
@@ -186,7 +192,8 @@ public class ScmActionIT {
 
   @Test
   public void return_empty_value_when_no_scm() {
-    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto()
       .setUuid(Uuids.createFast())
@@ -203,7 +210,8 @@ public class ScmActionIT {
 
   @Test
   public void fail_without_code_viewer_permission() {
-    userSessionRule.addProjectPermission(UserRole.USER, project, file);
+    userSessionRule.addProjectPermission(UserRole.USER, project.getProjectDto())
+      .registerBranches(project.getMainBranchDto());
 
     assertThatThrownBy(() -> {
       tester.newRequest()
index efbbffdfaf6710cb3bb13fe1bde7f41718c0ceb2..e5fd03ed987f3b9cc0a28855ea94e6efbdaa5e84 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.db.component.ComponentDao;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 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.source.SourceService;
@@ -56,8 +57,9 @@ public class ShowActionIT {
   private DbSession session = mock(DbSession.class);
   private ComponentDao componentDao = mock(ComponentDao.class);
   private BranchDao branchDao = mock(BranchDao.class);
-  private ComponentDto project = ComponentTesting.newPrivateProjectDto();
-  private ComponentDto file = ComponentTesting.newFileDto(project);
+  private ProjectDto project = ComponentTesting.newProjectDto();
+  private ComponentDto mainBranchComponentDto = ComponentTesting.newBranchComponent(project, ComponentTesting.newMainBranchDto(project.getUuid()));
+  private ComponentDto file = ComponentTesting.newFileDto(mainBranchComponentDto);
   private ShowAction underTest = new ShowAction(sourceService, dbClient, userSessionRule,
     new ComponentFinder(dbClient, new ResourceTypesRule().setRootQualifiers(Qualifiers.PROJECT)));
   private WsActionTester tester = new WsActionTester(underTest);
@@ -72,7 +74,8 @@ public class ShowActionIT {
   @Test
   public void show_source() {
     String fileKey = "src/Foo.java";
-    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project)
+      .addProjectBranchMapping(project.getUuid(), mainBranchComponentDto);
     when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
     when(sourceService.getLinesAsHtml(eq(session), eq(file.uuid()), anyInt(), anyInt())).thenReturn(Optional.of(newArrayList(
       "/*",
@@ -91,7 +94,8 @@ public class ShowActionIT {
   @Test
   public void show_source_with_from_and_to_params() {
     String fileKey = "src/Foo.java";
-    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project)
+      .addProjectBranchMapping(project.getUuid(), mainBranchComponentDto);
     when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
     when(sourceService.getLinesAsHtml(session, file.uuid(), 3, 5)).thenReturn(Optional.of(newArrayList(
       " */",
@@ -108,7 +112,8 @@ public class ShowActionIT {
   @Test
   public void show_source_accept_from_less_than_one() {
     String fileKey = "src/Foo.java";
-    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
+    userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project)
+      .addProjectBranchMapping(project.getUuid(), mainBranchComponentDto);
     when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
     when(sourceService.getLinesAsHtml(session, file.uuid(), 1, 5)).thenReturn(Optional.of(newArrayList(
       " */",