@@ -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); | |||
} |
@@ -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)); | |||
} |
@@ -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)); | |||
@@ -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) { |
@@ -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); | |||
@@ -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) |
@@ -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(","))) |
@@ -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); | |||
} | |||
} |
@@ -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() { |
@@ -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() { |
@@ -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); | |||
} | |||
} |
@@ -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()); | |||
@@ -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 |
@@ -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) { |
@@ -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) { |
@@ -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) |
@@ -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); |
@@ -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]"); | |||
} |
@@ -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; |
@@ -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(); |
@@ -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); | |||
} |
@@ -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) |
@@ -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()); | |||
} | |||
} |
@@ -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()); | |||
} | |||
} |
@@ -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; | |||
} |
@@ -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") |
@@ -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); | |||
} |
@@ -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); | |||
} |
@@ -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) { |
@@ -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() |
@@ -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( | |||
" */", |