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);
}
.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);
}
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));
@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));
}
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));
@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())
@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())
@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())
@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);
}
@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) {
@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);
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;
@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()))
@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)
@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(",")))
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;
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");
}
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);
}
}
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;
}
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() {
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;
}
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() {
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;
assertThat(action.supports(new DefaultIssue().setResolution(Issue.RESOLUTION_FIXED))).isTrue();
}
+
private IssueDto newIssue() {
RuleDto rule = newRule().setUuid(Uuids.createFast());
ComponentDto project = ComponentTesting.newPrivateProjectDto();
}
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);
}
}
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;
@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());
@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());
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;
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
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.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;
@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);
@Test
public void fail_when_not_authenticated() {
- assertThatThrownBy(() -> call("ABCD", MAJOR))
+ assertThatThrownBy(() -> call("ABCD", MAJOR))
.isInstanceOf(UnauthorizedException.class);
}
}
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) {
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;
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;
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")
}
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) {
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;
@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
@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)
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;
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;
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;
@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();
@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();
@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();
@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();
@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);
@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)
@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))
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())
// 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);
@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);
@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));
@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));
@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();
@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();
@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();
@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
@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();
@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);
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;
@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]");
}
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;
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;
@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();
@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);
}
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;
@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);
@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)
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;
@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");
@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"))
@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();
@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"))
.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());
}
}
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;
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;
@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);
@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);
@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);
@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);
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());
}
}
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;
@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())
@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);
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;
}
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;
@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
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")
.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")
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;
@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);
}
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;
@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);
}
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;
@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())
@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());
@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()
@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())
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())
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())
@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)
@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())
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())
@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)
.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())
@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)
.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())
@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())
@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
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) {
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;
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())
@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())
@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()
@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()
@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())
@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())
@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()
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;
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);
@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(
"/*",
@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(
" */",
@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(
" */",