}
public SnapshotDto insertSnapshot(ProjectData project, Consumer<SnapshotDto> consumer) {
- return insertSnapshot(project.getProjectDto(), consumer);
+ return insertSnapshot(project.getMainBranchDto(), consumer);
}
+ /**
+ * Add a snapshot to the main branch of a project
+ * Should use insertSnapshot(org.sonar.db.component.BranchDto, java.util.function.Consumer<org.sonar.db.component.SnapshotDto>) instead
+ */
+ @Deprecated
public SnapshotDto insertSnapshot(ProjectDto project, Consumer<SnapshotDto> consumer) {
- SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(project.getUuid());
+ BranchDto mainBranchDto = db.getDbClient().branchDao().selectMainBranchByProjectUuid(dbSession, project.getUuid()).orElseThrow();
+ SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(mainBranchDto.getUuid());
consumer.accept(snapshotDto);
return insertSnapshot(snapshotDto);
}
.setQualifier(Qualifiers.PROJECT);
}
+ public static ProjectDto newApplicationDto() {
+ return new ProjectDto()
+ .setKey("appKey")
+ .setUuid("uuid")
+ .setName("appName")
+ .setQualifier(Qualifiers.APP);
+ }
+
public static ComponentDto newBranchComponent(ProjectDto project, BranchDto branchDto) {
String uuid = branchDto.getUuid();
return new ComponentDto()
.setGroups(group);
ProjectDto subProjectDto = new ProjectDto().setQualifier(Qualifiers.PROJECT).setUuid("subproject-uuid");
- ComponentDto applicationAsComponentDto = new ComponentDto().setQualifier(Qualifiers.APP).setUuid("application-component-uuid").setBranchUuid("application-project-uuid");
ProjectDto applicationAsProjectDto = new ProjectDto().setQualifier(Qualifiers.APP).setUuid("application-project-uuid");
expected.registerProjects(subProjectDto);
expected.registerApplication(applicationAsProjectDto, subProjectDto);
- expected.registerComponents(applicationAsComponentDto);
threadLocalUserSession.set(expected);
- assertThat(threadLocalUserSession.checkChildProjectsPermission(USER, applicationAsComponentDto)).isEqualTo(threadLocalUserSession);
assertThat(threadLocalUserSession.checkChildProjectsPermission(USER, applicationAsProjectDto)).isEqualTo(threadLocalUserSession);
}
}
return clazz.cast(this);
}
- public T registerApplication(ComponentDto application, ComponentDto... appProjects) {
- registerComponents(application);
- registerComponents(appProjects);
-
- var appProjectsUuid = Arrays.stream(appProjects)
- .map(ComponentDto::uuid)
- .collect(Collectors.toSet());
- this.applicationProjects.put(application.uuid(), appProjectsUuid);
-
- return clazz.cast(this);
- }
-
public T registerApplication(ProjectDto application, ProjectDto... appProjects) {
registerProjects(application);
registerProjects(appProjects);
setCurrentUserSession(userSession);
}
- public UserSessionRule registerComponents(ComponentDto... componentDtos) {
- ensureAbstractMockUserSession().registerComponents(componentDtos);
+ public UserSessionRule registerPortfolios(ComponentDto... portfolios) {
+ ensureAbstractMockUserSession().registerComponents(portfolios);
return this;
}
return this;
}
- public UserSessionRule registerApplication(ComponentDto application, ComponentDto... appProjects) {
- ensureAbstractMockUserSession().registerApplication(application, appProjects);
- return this;
- }
-
public UserSessionRule addProjectPermission(String projectPermission, ComponentDto... components) {
ensureAbstractMockUserSession().addProjectPermission(projectPermission, components);
return this;
return this;
}
- public UserSession registerBranches(BranchDto... branchDtos) {
+ public UserSessionRule registerBranches(BranchDto... branchDtos) {
ensureAbstractMockUserSession().registerBranches(branchDtos);
return this;
}
import org.sonar.api.testfixtures.log.LogTester;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDbTester;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.user.UserDto;
ComponentDto view = db.components().insertPublicPortfolio();
SearchRequest request = new SearchRequest()
.setComponentUuids(singletonList(view.uuid()));
- userSession.registerComponents(view);
+ userSession.registerPortfolios(view);
IssueQuery query = underTest.create(request);
@Test
public void application_search_project_issues() {
- ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPublicProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPublicProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
+ ProjectData applicationData = db.components().insertPublicApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
db.components().insertComponents(newProjectCopy("PC1", project1, application));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
- userSession.registerApplication(application, project1, project2);
+ userSession.registerApplication(applicationData.getProjectDto())
+ .registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto());
IssueQuery result = underTest.create(new SearchRequest().setComponentUuids(singletonList(application.uuid())));
public void application_search_project_issues_in_new_code_with_and_without_analysis_after_sonarqube_94() {
Date now = new Date();
when(clock.millis()).thenReturn(now.getTime());
- ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPublicProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
SnapshotDto analysis1 = db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
- ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPublicProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
db.components().insertSnapshot(project2, s -> s.setPeriodDate(null));
- ComponentDto project3 = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto project4 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData3 = db.components().insertPublicProject();
+ ComponentDto project3 = projectData3.getMainBranchComponent();
+ ProjectData projectData4 = db.components().insertPublicProject();
+ ComponentDto project4 = projectData4.getMainBranchComponent();
SnapshotDto analysis2 = db.components().insertSnapshot(project4,
s -> s.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+ ProjectData applicationData = db.components().insertPublicApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
MetricDto analysisMetric = db.measures().insertMetric(m -> m.setKey(ANALYSIS_FROM_SONARQUBE_9_4_KEY));
db.measures().insertLiveMeasure(project4, analysisMetric, measure -> measure.setData("true"));
db.components().insertComponents(newProjectCopy("PC1", project1, application));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
db.components().insertComponents(newProjectCopy("PC3", project3, application));
db.components().insertComponents(newProjectCopy("PC4", project4, application));
- userSession.registerApplication(application, project1, project2, project3, project4);
+ userSession.registerApplication(applicationData.getProjectDto());
+ userSession.registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto(), projectData3.getProjectDto(), projectData4.getProjectDto());
IssueQuery result = underTest.create(new SearchRequest()
.setComponentUuids(singletonList(application.uuid()))
@Test
public void search_by_application_key() {
- ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData applicationData = db.components().insertPrivateApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
db.components().insertComponents(newProjectCopy(project1, application));
db.components().insertComponents(newProjectCopy(project2, application));
- userSession.registerApplication(application, project1, project2)
- .addProjectPermission(USER, application)
- .addProjectPermission(USER, project1)
- .addProjectPermission(USER, project2);
+ userSession.registerApplication(applicationData.getProjectDto())
+ .registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto())
+ .addProjectPermission(USER, applicationData.getProjectDto())
+ .addProjectPermission(USER, projectData1.getProjectDto())
+ .addProjectPermission(USER, projectData2.getProjectDto());
assertThat(underTest.create(new SearchRequest()
.setComponents(singletonList(application.getKey())))
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create();
+ public DbTester db = DbTester.create(true);
private final MapSettings mapSettings = new MapSettings();
private final Configuration config = mapSettings.asConfig();
@Test
public void int_measure() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createIntMetricAndMeasure(project, BUGS_KEY, 10_000);
TestResponse response = ws.newRequest()
@Test
public void percent_measure() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY).setValueType(PERCENT.name()));
db.measures().insertLiveMeasure(project, metric, m -> m.setValue(12.345d));
@Test
public void duration_measure() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(TECHNICAL_DEBT_KEY).setValueType(WORK_DUR.name()));
db.measures().insertLiveMeasure(project, metric, m -> m.setValue(10_000d));
@Test
@UseDataProvider("ratings")
public void rating_measure(Rating rating, Color color) {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(SQALE_RATING_KEY).setValueType(RATING.name()));
db.measures().insertLiveMeasure(project, metric, m -> m.setValue((double) rating.getIndex()).setData(rating.name()));
@Test
@UseDataProvider("qualityGates")
public void quality_gate(Level status, String expectedValue, Color expectedColor) {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setData(status.name()));
@Test
public void security_hotspots() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createIntMetricAndMeasure(project, SECURITY_HOTSPOTS_KEY, 42);
TestResponse response = ws.newRequest()
@Test
public void display_deprecated_warning_quality_gate() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setData(WARN.name()));
@Test
public void measure_on_non_main_branch() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setPrivate(false)).getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setPrivate(false));
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createIntMetricAndMeasure(project, BUGS_KEY, 5_000);
String branchName = randomAlphanumeric(248);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
@Test
public void measure_on_application() {
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
- userSession.registerComponents(application);
+ ProjectData projectData = db.components().insertPublicApplication();
+ ComponentDto application = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createIntMetricAndMeasure(application, BUGS_KEY, 10_000);
TestResponse response = ws.newRequest()
@Test
public void return_error_if_branch_does_not_exist() throws ParseException {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY));
TestResponse response = ws.newRequest()
@Test
public void return_error_if_measure_not_found() throws ParseException {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY));
TestResponse response = ws.newRequest()
@Test
public void return_error_on_directory() throws ParseException {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(project, "path"));
- userSession.registerComponents(project);
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY).setValueType(INT.name()));
TestResponse response = ws.newRequest()
@UseDataProvider("publicProject_forceAuth_accessGranted")
public void badge_accessible_on_private_project_with_token(boolean publicProject, boolean forceAuth,
boolean validToken, boolean accessGranted) throws ParseException {
- ComponentDto projectAsComponent = publicProject ? db.components().insertPublicProject().getMainBranchComponent() : db.components().insertPrivateProject().getMainBranchComponent();
- userSession.registerComponents(projectAsComponent);
- MetricDto metric = createIntMetricAndMeasure(projectAsComponent, BUGS_KEY, 10_000);
-
- ProjectDto project = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), projectAsComponent.getKey())
- .orElseThrow(() -> new IllegalStateException("project not found"));
+ ProjectData project = publicProject ? db.components().insertPublicProject() : db.components().insertPrivateProject();
+ userSession.registerProjects(project.getProjectDto());
+ MetricDto metric = createIntMetricAndMeasure(project.getMainBranchComponent(), BUGS_KEY, 10_000);
String token = db.getDbClient().projectBadgeTokenDao()
- .insert(db.getSession(), UuidFactoryFast.getInstance().create(), project, "user-uuid", "user-login")
+ .insert(db.getSession(), UuidFactoryFast.getInstance().create(), project.getProjectDto(), "user-uuid", "user-login")
.getToken();
db.commit();
mapSettings.setProperty(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY, forceAuth);
TestResponse response = ws.newRequest()
- .setParam("project", projectAsComponent.getKey())
+ .setParam("project", project.getProjectDto().getKey())
.setParam("metric", metric.getKey())
.setParam("token", validToken ? token : "invalid-token")
.execute();
@Test
public void return_error_on_provisioned_project() throws ParseException {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+
+ userSession.registerProjects(project);
MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY).setValueType(INT.name()));
TestResponse response = ws.newRequest()
@Test
public void fail_on_invalid_quality_gate() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setData("UNKNOWN"));
@Test
public void fail_when_measure_value_is_null() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = db.measures().insertMetric(m -> m.setKey(BUGS_KEY).setValueType(INT.name()));
db.measures().insertLiveMeasure(project, metric, m -> m.setValue(null));
@Test
public void fail_when_metric_not_found() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
TestRequest request = ws.newRequest()
.setParam("project", project.getKey())
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.project.ProjectDto;
@Test
public void quality_gate_passed() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
@Test
public void quality_gate_failed() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setData(ERROR.name()));
@UseDataProvider("publicProject_forceAuth_validToken_accessGranted")
public void badge_accessible_on_private_project_with_token(boolean publicProject, boolean forceAuth,
boolean validToken, boolean accessGranted) throws ParseException {
- ComponentDto projectAsComponent = publicProject ? db.components().insertPublicProject().getMainBranchComponent() : db.components().insertPrivateProject().getMainBranchComponent();
- userSession.registerComponents(projectAsComponent);
+ ProjectData projectData = publicProject ? db.components().insertPublicProject() : db.components().insertPrivateProject();
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
- db.measures().insertLiveMeasure(projectAsComponent, metric, m -> m.setData(OK.name()));
- ProjectDto project = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), projectAsComponent.getKey())
+ db.measures().insertLiveMeasure(projectData, metric, m -> m.setData(OK.name()));
+ ProjectDto project = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), projectData.getProjectDto().getKey())
.orElseThrow(() -> new IllegalStateException("project not found"));
String token = db.getDbClient().projectBadgeTokenDao()
mapSettings.setProperty(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY, forceAuth);
TestResponse response = ws.newRequest()
- .setParam("project", projectAsComponent.getKey())
+ .setParam("project", projectData.getProjectDto().getKey())
.setParam("token", validToken ? token : "invalid-token")
.execute();
@Test
public void etag_should_be_different_if_quality_gate_is_different() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
LiveMeasureDto liveMeasure = db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
@Test
public void when_IfNoneMatch_match_etag_http_304_must_be_send() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
@Test
public void quality_gate_on_branch() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setPrivate(false)).getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setPrivate(false));
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
String branchName = randomAlphanumeric(248);
@Test
public void quality_gate_on_application() {
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
- userSession.registerComponents(application);
+ ProjectData projectData = db.components().insertPublicApplication();
+ ComponentDto application = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(application, metric, m -> m.setData(ERROR.name()));
@Test
public void return_error_on_directory() throws ParseException {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto directory = db.components().insertComponent(ComponentTesting.newDirectory(project, "path"));
- userSession.registerComponents(project);
+ userSession.registerProjects(projectData.getProjectDto());
TestResponse response = ws.newRequest()
.setParam("project", directory.getKey())
@Test
public void return_error_on_provisioned_project() throws ParseException {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@Test
public void return_error_on_not_existing_branch() throws ParseException {
- ComponentDto project = db.components().insertPublicProject(p -> p.setPrivate(false)).getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setPrivate(false));
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
TestResponse response = ws.newRequest()
@Test
public void return_error_if_measure_not_found() throws ParseException {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
TestResponse response = ws.newRequest()
.setParam("project", project.getKey())
@Test
public void return_error_if_measure_value_is_null() throws ParseException {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setData((String) null));
@Test
public void fail_on_invalid_quality_gate() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setData("UNKNOWN"));
import org.sonar.db.ce.CeTaskMessageType;
import org.sonar.db.ce.CeTaskTypes;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.permission.GlobalPermission;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
private final WsActionTester ws = new WsActionTester(underTest);
private ComponentDto privateProject;
- private ComponentDto publicProject;
+ private ComponentDto publicProjectMainBranch;
+ private ProjectDto publicProject;
@Before
public void setUp() {
privateProject = db.components().insertPrivateProject().getMainBranchComponent();
userSession.logIn().addProjectPermission(ADMIN, privateProject);
- publicProject = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData publicProjectData = db.components().insertPublicProject();
+ publicProject = publicProjectData.getProjectDto();
+ publicProjectMainBranch = publicProjectData.getMainBranchComponent();
}
@Test
@Test
public void getting_project_queue_task_of_public_project_fails_with_ForbiddenException() {
UserDto user = db.users().insertUser();
- userSession.logIn().registerComponents(publicProject);
- CeQueueDto task = createAndPersistQueueTask(publicProject, user);
+ userSession.logIn().registerProjects(publicProject);
+ CeQueueDto task = createAndPersistQueueTask(publicProjectMainBranch, user);
String uuid = task.getUuid();
assertThatThrownBy(() -> call(uuid))
@Test
public void getting_archived_task_of_public_project_fails_with_ForbiddenException() {
- userSession.logIn().registerComponents(publicProject);
- CeActivityDto task = createAndPersistArchivedTask(publicProject);
+ userSession.logIn().registerProjects(publicProject);
+ CeActivityDto task = createAndPersistArchivedTask(publicProjectMainBranch);
String uuid = task.getUuid();
assertThatThrownBy(() -> call(uuid))
@Test
public void get_warnings_on_public_project_archived_task_if_not_admin_fails_with_ForbiddenException() {
- userSession.logIn().registerComponents(publicProject);
+ userSession.logIn().registerProjects(publicProject);
- CeActivityDto persistArchivedTask = createAndPersistArchivedTask(publicProject);
+ CeActivityDto persistArchivedTask = createAndPersistArchivedTask(publicProjectMainBranch);
assertThatThrownBy(() -> insertWarningsCallEndpointAndAssertWarnings(persistArchivedTask))
.isInstanceOf(ForbiddenException.class);
}
import org.sonar.api.web.UserRole;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
@Test
public void should_return_visibility_for_public_project() {
- ComponentDto publicProject = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(publicProject);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto publicProject = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
ShowWsResponse result = newRequest(publicProject.getKey());
assertThat(result.getComponent().hasVisibility()).isTrue();
ComponentDto subview = db.components().insertSubView(portfolio1);
String pullRequestKey1 = randomAlphanumeric(100);
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey1)
.setNeedIssueSync(true));
ComponentDto directory = db.components().insertComponent(newDirectoryOnBranch(branch1, "dir", project1.uuid()));
ComponentDto file = db.components().insertComponent(newFileDto(project1.uuid(), branch1, directory));
- userSession.addProjectBranchMapping(project1.uuid(), branch1);
+ userSession.addProjectBranchMapping(projectData1.projectUuid(), branch1);
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
String branchName2 = randomAlphanumeric(248);
ComponentDto branch2 = db.components().insertProjectBranch(project2, b -> b.setBranchType(BRANCH).setNeedIssueSync(true).setKey(branchName2));
String branchName3 = randomAlphanumeric(248);
ComponentDto branch3 = db.components().insertProjectBranch(project2, b -> b.setBranchType(BRANCH).setNeedIssueSync(false).setKey(branchName3));
- userSession.addProjectBranchMapping(project2.uuid(), branch2);
- userSession.addProjectBranchMapping(project2.uuid(), branch3);
+ userSession.addProjectBranchMapping(projectData2.projectUuid(), branch2);
+ userSession.addProjectBranchMapping(projectData2.projectUuid(), branch3);
- ComponentDto project3 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData3 = db.components().insertPrivateProject();
+ ComponentDto project3 = projectData3.getMainBranchComponent();
String pullRequestKey4 = randomAlphanumeric(100);
ComponentDto branch4 = db.components().insertProjectBranch(project3, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey4).setNeedIssueSync(false));
ComponentDto directoryOfBranch4 = db.components().insertComponent(newDirectoryOnBranch(branch4, "dir", project3.uuid()));
ComponentDto fileOfBranch4 = db.components().insertComponent(newFileDto(project3.uuid(), branch4, directoryOfBranch4));
String branchName5 = randomAlphanumeric(248);
ComponentDto branch5 = db.components().insertProjectBranch(project3, b -> b.setBranchType(BRANCH).setNeedIssueSync(false).setKey(branchName5));
- userSession.addProjectBranchMapping(project3.uuid(), branch4);
- userSession.addProjectBranchMapping(project3.uuid(), branch5);
+ userSession.addProjectBranchMapping(projectData3.projectUuid(), branch4);
+ userSession.addProjectBranchMapping(projectData3.projectUuid(), branch5);
- userSession.addProjectPermission(UserRole.USER, project1, project2, project3);
- userSession.registerComponents(portfolio1, portfolio2, subview, project1, project2, project3);
+ userSession.addProjectPermission(UserRole.USER, projectData1.getProjectDto(), projectData2.getProjectDto(), projectData3.getProjectDto());
+ userSession.registerPortfolios(portfolio1, portfolio2, subview);
+ userSession.registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto(), projectData3.getProjectDto());
// for portfolios, sub-views need issue sync flag is set to true if any project need sync
assertNeedIssueSyncEqual(null, null, portfolio1, true);
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.ResourceTypesRule;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
@Test
public void json_example() throws IOException {
- ComponentDto project = initJsonExampleComponents();
+ ProjectDto project = initJsonExampleComponents();
logInWithBrowsePermission(project);
String response = ws.newRequest()
@Test
public void return_children() {
- ComponentDto project = newPrivateProjectDto("project-uuid");
- db.components().insertProjectAndSnapshot(project);
- ComponentDto dir = newDirectory(project, "dir");
+ ProjectData projectData = db.components().insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+ ComponentDto projectMainBranch = projectData.getMainBranchComponent();
+ db.components().insertSnapshot(projectMainBranch);
+ ComponentDto dir = newDirectory(projectMainBranch, "dir");
db.components().insertComponent(dir);
- db.components().insertComponent(newFileDto(project, 1));
+ db.components().insertComponent(newFileDto(projectMainBranch, 1));
for (int i = 2; i <= 9; i++) {
db.components().insertComponent(newFileDto(dir, i));
}
ComponentDto directory = newDirectory(dir, "directory-path-1");
db.components().insertComponent(directory);
- db.components().insertComponent(newFileDto(project, directory, 10));
+ db.components().insertComponent(newFileDto(projectMainBranch, directory, 10));
db.commit();
- logInWithBrowsePermission(project);
+ logInWithBrowsePermission(projectData.getProjectDto());
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "children")
@Test
public void return_descendants() {
- ComponentDto project = newPrivateProjectDto("project-uuid");
- db.components().insertProjectAndSnapshot(project);
- ComponentDto module = newDirectory(project, "path");
+ ProjectData projectData = db.components()
+ .insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+ ComponentDto projectMainBranch = projectData.getMainBranchComponent();
+ db.components().insertSnapshot(projectMainBranch);
+ ComponentDto module = newDirectory(projectMainBranch, "path");
db.components().insertComponent(module);
- db.components().insertComponent(newFileDto(project, 10));
+ db.components().insertComponent(newFileDto(projectMainBranch, 10));
for (int i = 2; i <= 9; i++) {
db.components().insertComponent(newFileDto(module, i));
}
db.components().insertComponent(directory);
db.components().insertComponent(newFileDto(module, directory, 1));
db.commit();
- logInWithBrowsePermission(project);
+ logInWithBrowsePermission(projectData.getProjectDto());
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
@Test
public void filter_descendants_by_qualifier() {
- ComponentDto project = newPrivateProjectDto("project-uuid");
- db.components().insertProjectAndSnapshot(project);
- db.components().insertComponent(newFileDto(project, 1));
- db.components().insertComponent(newFileDto(project, 2));
+ ProjectData projectData = db.components()
+ .insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+ ComponentDto projectMainBranch = projectData.getMainBranchComponent();
+ db.components().insertSnapshot(projectMainBranch);
+ db.components().insertComponent(newFileDto(projectMainBranch, 1));
+ db.components().insertComponent(newFileDto(projectMainBranch, 2));
db.commit();
- logInWithBrowsePermission(project);
+ logInWithBrowsePermission(projectData.getProjectDto());
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
.setParam(PARAM_QUALIFIERS, FILE)
- .setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(TreeWsResponse.class);
+ .setParam(PARAM_COMPONENT, projectMainBranch.getKey()).executeProtobuf(TreeWsResponse.class);
assertThat(response.getComponentsList()).extracting("key").containsExactly("file-key-1", "file-key-2");
}
@Test
public void return_leaves() {
- ComponentDto project = newPrivateProjectDto("project-uuid");
- db.components().insertProjectAndSnapshot(project);
- db.components().insertComponent(newFileDto(project, 1));
- db.components().insertComponent(newFileDto(project, 2));
- ComponentDto directory = newDirectory(project, "directory-path-1");
+ ProjectData projectData = db.components()
+ .insertPrivateProject(p->p.setUuid("mainBranch-uuid").setBranchUuid("mainBranch-uuid"));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
+ db.components().insertComponent(newFileDto(mainBranch, 1));
+ db.components().insertComponent(newFileDto(mainBranch, 2));
+ ComponentDto directory = newDirectory(mainBranch, "directory-path-1");
db.components().insertComponent(directory);
- db.components().insertComponent(newFileDto(project, directory, 3));
+ db.components().insertComponent(newFileDto(mainBranch, directory, 3));
db.commit();
- logInWithBrowsePermission(project);
+ logInWithBrowsePermission(projectData.getProjectDto());
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "leaves")
- .setParam(PARAM_COMPONENT, project.getKey())
+ .setParam(PARAM_COMPONENT, mainBranch.getKey())
.setParam(PARAM_QUALIFIERS, FILE).executeProtobuf(TreeWsResponse.class);
assertThat(response.getComponentsCount()).isEqualTo(3);
@Test
public void sort_descendants_by_qualifier() {
- ComponentDto project = newPrivateProjectDto("project-uuid");
- db.components().insertProjectAndSnapshot(project);
- db.components().insertComponent(newFileDto(project, 1));
- db.components().insertComponent(newFileDto(project, 2));
- db.components().insertComponent(newDirectory(project, "path/directory/", "directory-uuid-1"));
+ ProjectData projectData = db.components()
+ .insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid").setKey("project-key"));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
+ db.components().insertComponent(newFileDto(mainBranch, 1));
+ db.components().insertComponent(newFileDto(mainBranch, 2));
+ db.components().insertComponent(newDirectory(mainBranch, "path/directory/", "directory-uuid-1"));
db.commit();
- logInWithBrowsePermission(project);
+ logInWithBrowsePermission(projectData.getProjectDto());
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "all")
.setParam(Param.SORT, "qualifier, name")
- .setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(TreeWsResponse.class);
+ .setParam(PARAM_COMPONENT, mainBranch.getKey()).executeProtobuf(TreeWsResponse.class);
- assertThat(response.getComponentsList()).extracting("key").containsExactly("KEY_project-uuid:directory-uuid-1", "file-key-1", "file-key-2");
+ assertThat(response.getComponentsList()).extracting("key").containsExactly("project-key:directory-uuid-1", "file-key-1", "file-key-2");
}
@Test
public void project_reference_from_portfolio() {
ComponentDto view = ComponentTesting.newPortfolio("view-uuid");
db.components().insertPortfolioAndSnapshot(view);
- ComponentDto project = newPrivateProjectDto("project-uuid-1").setName("project-name").setKey("project-key-1");
- db.components().insertProjectAndSnapshot(project);
- db.components().insertComponent(newProjectCopy("project-uuid-1-copy", project, view));
+ ProjectData project = db.components().insertPrivateProject(p->p.setUuid("project-uuid-1").setBranchUuid("project-uuid-1").setName("project-name").setKey("project-key-1"));
+ db.components().insertSnapshot(project.getMainBranchComponent());
+ db.components().insertComponent(newProjectCopy("project-uuid-1-copy", project.getMainBranchComponent(), view));
db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"));
db.commit();
userSession.logIn()
- .registerComponents(view, project);
+ .registerPortfolios(view)
+ .registerProjects(project.getProjectDto());
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "children")
public void project_branch_reference_from_portfolio() {
ComponentDto view = ComponentTesting.newPortfolio("view-uuid");
db.components().insertPortfolioAndSnapshot(view);
- ComponentDto project = newPrivateProjectDto("project-uuid-1").setName("project-name").setKey("project-key-1");
- db.components().insertProjectAndSnapshot(project);
- db.components().insertComponent(newProjectBranchCopy("project-uuid-1-copy", project, view, "branch1"));
+ ProjectData projectData = db.components().insertPrivateProject(p->p.setUuid("project-uuid-1").setBranchUuid("project-uuid-1").setName("project-name").setKey("project-key-1"));
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ db.components().insertSnapshot(mainBranch);
+ db.components().insertComponent(newProjectBranchCopy("project-uuid-1-copy", mainBranch, view, "branch1"));
db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name"));
db.commit();
userSession.logIn()
- .registerComponents(view, project);
+ .registerPortfolios(view)
+ .registerProjects(projectData.getProjectDto());
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_STRATEGY, "children")
String appBranchName = "app-branch";
String projectBranchName = "project-branch";
- ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app-key")).getMainBranchComponent();
- ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey(appBranchName));
+ ProjectData applicationData = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app-key"));
+ ProjectDto application = applicationData.getProjectDto();
+ ComponentDto applicationBranch = db.components().insertProjectBranch(applicationData.getMainBranchComponent(), a -> a.setKey(appBranchName));
ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key")).getMainBranchComponent();
ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey(projectBranchName));
ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch)
- .setKey(applicationBranch.getKey() + project.getKey()).setMainBranchProjectUuid(application.uuid()));
+ .setKey(applicationBranch.getKey() + project.getKey()).setMainBranchProjectUuid(application.getUuid()));
logInWithBrowsePermission(application);
- userSession.addProjectBranchMapping(application.uuid(), applicationBranch);
+ userSession.addProjectBranchMapping(application.getUuid(), applicationBranch);
TreeWsResponse result = ws.newRequest()
.setParam(MeasuresWsParameters.PARAM_COMPONENT, applicationBranch.getKey())
@Test
public void response_is_empty_on_provisioned_projects() {
- ComponentDto project = db.components().insertPrivateProject("project-uuid").getMainBranchComponent();
+ ProjectDto project = db.components().insertPrivateProject("project-uuid").getProjectDto();
logInWithBrowsePermission(project);
TreeWsResponse response = ws.newRequest()
@Test
public void return_projects_composing_a_view() {
- ComponentDto project = newPrivateProjectDto("project-uuid");
- db.components().insertProjectAndSnapshot(project);
+ ProjectData projectData = db.components().insertPrivateProject(p -> p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+ ComponentDto project = projectData.getMainBranchComponent();
+ db.components().insertSnapshot(project);
ComponentDto view = ComponentTesting.newPortfolio("view-uuid");
db.components().insertPortfolioAndSnapshot(view);
ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view));
userSession.logIn()
- .registerComponents(project, view);
+ .registerProjects(projectData.getProjectDto())
+ .registerPortfolios(view);
TreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, view.getKey())
@Test
public void fail_when_base_component_is_removed() {
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
- db.components().insertComponent(ComponentTesting.newFileDto(project).setKey("file-key").setEnabled(false));
- logInWithBrowsePermission(project);
+
+ ProjectData projectData = db.components().insertPrivateProject(p->p.setKey("file-key").setEnabled(false));
+ db.components().insertSnapshot(projectData.getMainBranchComponent());
+ logInWithBrowsePermission(projectData.getProjectDto());
TestRequest request = ws.newRequest()
.setParam(PARAM_COMPONENT, "file-key");
return newFileDto(moduleOrProject, null, i);
}
- private ComponentDto initJsonExampleComponents() throws IOException {
- ComponentDto project = db.components().insertPrivateProject(c -> c.setUuid("MY_PROJECT_ID")
+ private ProjectDto initJsonExampleComponents() throws IOException {
+ ProjectData projectData = db.components().insertPrivateProject(c -> c.setUuid("MY_PROJECT_ID")
.setDescription("MY_PROJECT_DESCRIPTION")
.setKey("MY_PROJECT_KEY")
.setName("Project Name")
.setBranchUuid("MY_PROJECT_ID"),
- p -> p.setTagsString("abc,def")).getMainBranchComponent();
- db.components().insertSnapshot(project);
+ p -> p.setTagsString("abc,def"));
+ db.components().insertSnapshot(projectData.getMainBranchComponent());
Date now = new Date();
JsonParser jsonParser = new JsonParser();
JsonElement componentAsJsonElement = components.get(i);
JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject();
String uuid = format("child-component-uuid-%d", i);
- db.components().insertComponent(newChildComponent(uuid, project, project)
+ db.components().insertComponent(newChildComponent(uuid, projectData.getMainBranchComponent(), projectData.getMainBranchComponent())
.setKey(getJsonField(componentAsJsonObject, "key"))
.setName(getJsonField(componentAsJsonObject, "name"))
.setLanguage(getJsonField(componentAsJsonObject, "language"))
.setCreatedAt(now));
}
db.commit();
- return project;
+ return projectData.getProjectDto();
}
@CheckForNull
return jsonElement == null ? null : jsonElement.getAsString();
}
- private void logInWithBrowsePermission(ComponentDto project) {
+ private void logInWithBrowsePermission(ProjectDto project) {
userSession.logIn().addProjectPermission(UserRole.USER, project);
}
@Test
public void doHandle_whenPassingUnsupportedQualifier_ShouldThrowIllegalArgumentException() {
- ComponentDto project = newPrivateProjectDto("project-uuid");
- db.components().insertProjectAndSnapshot(project);
+ ProjectData project = db.components().insertPrivateProject(p->p.setUuid("project-uuid").setBranchUuid("project-uuid"));
+ db.components().insertSnapshot(project.getMainBranchComponent());
db.commit();
- logInWithBrowsePermission(project);
+ logInWithBrowsePermission(project.getProjectDto());
TestRequest testRequest = ws.newRequest()
.setParam(PARAM_QUALIFIERS, "BRC")
- .setParam(PARAM_COMPONENT, project.getKey());
+ .setParam(PARAM_COMPONENT, project.getProjectDto().getKey());
assertThatThrownBy(testRequest::execute).isInstanceOf(IllegalArgumentException.class)
.hasMessage("Value of parameter 'qualifiers' (BRC) must be one of: [UTS, FIL, DIR, TRK]");
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.exceptions.ForbiddenException;
@Test
public void fails_with_ForbiddenException_if_project_is_private_and_not_allowed() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = dbTester.rules().insertHotspotRule();
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@Test
public void succeeds_on_public_project() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = dbTester.rules().insertHotspotRule();
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@Test
public void succeeds_on_private_project_with_permission() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project).addProjectPermission(UserRole.USER, project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.USER, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = dbTester.rules().insertHotspotRule();
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
public void persists_comment_if_hotspot_status_changes_and_transition_done(String currentStatus, @Nullable String currentResolution) {
long now = RANDOM.nextInt(232_323);
when(system2.now()).thenReturn(now);
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = dbTester.rules().insertHotspotRule();
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(currentStatus).setResolution(currentResolution));
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleTesting;
@Test
public void wsExecution_whenAssignedForPublicProject() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
UserDto userDto = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(userDto).registerComponents(project);
+ userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
UserDto assignee = insertUser(randomAlphanumeric(15));
when(issueFieldsSetter.assign(eq(hotspot.toDefaultIssue()), userMatcher(assignee), any(IssueChangeContext.class))).thenReturn(true);
@Test
public void wsExecution_whenUnassignedForPublicProject() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
UserDto assignee = insertUser(randomAlphanumeric(15));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setAssigneeUuid(assignee.getUuid()));
UserDto userDto = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(userDto).registerComponents(project);
+ userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
when(issueFieldsSetter.assign(eq(hotspot.toDefaultIssue()), isNull(), any(IssueChangeContext.class))).thenReturn(true);
executeRequest(hotspot, null, null);
@Test
public void wsExecution_whenMyselfAssignedForPublicProject() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
UserDto me = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(me).registerComponents(project);
+ userSessionRule.logIn(me).registerProjects(projectData.getProjectDto());
when(issueFieldsSetter.assign(eq(hotspot.toDefaultIssue()), userMatcher(me), any(IssueChangeContext.class))).thenReturn(true);
@Test
public void wsExecution_whenMyselfUnassignedForPublicProject() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
UserDto me = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(me).registerComponents(project);
+ userSessionRule.logIn(me).registerProjects(projectData.getProjectDto());
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setAssigneeUuid(me.getUuid()));
when(issueFieldsSetter.assign(eq(hotspot.toDefaultIssue()), isNull(), any(IssueChangeContext.class))).thenReturn(true);
@Test
public void wsExecution_whenAssignHotspotWithComment() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
UserDto userDto = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(userDto).registerComponents(project);
+ userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
UserDto assignee = insertUser(randomAlphanumeric(15));
@Test
public void wsExecution_whenAssignTwiceSameUserHotspotDoesNotReload_shouldFail() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
UserDto userDto = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(userDto).registerComponents(project);
+ userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
UserDto assignee = insertUser(randomAlphanumeric(15));
@Test
public void wsExecution_whenBranchTypeIsBranch_shouldDistributeEvents() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
UserDto userDto = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(userDto).registerComponents(project);
+ userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
UserDto assignee = insertUser(randomAlphanumeric(15));
when(branchDto.getBranchType()).thenReturn(BranchType.BRANCH);
@Test
public void wsExecution_whenBranchIsPullRequest_shouldNotDistributeEvents() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
UserDto userDto = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(userDto).registerComponents(project);
+ userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
UserDto assignee = insertUser(randomAlphanumeric(15));
when(branchDto.getBranchType()).thenReturn(BranchType.PULL_REQUEST);
@Test
public void wsExecution_whenAssigningToNonExistingUser_shouldFail() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
UserDto userDto = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(userDto).registerComponents(project);
+ userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
String notExistingUserLogin = randomAlphanumeric(10);
@Test
@UseDataProvider("allIssueStatusesAndResolutionsThatThrowOnAssign")
public void wsExecution_whenAssigningToUserIfForbidden_shouldFail(String status, String resolution) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> {
h.setStatus(status);
});
UserDto userDto = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(userDto).registerComponents(project);
+ userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
String login = userSessionRule.getLogin();
assertThatThrownBy(() -> executeRequest(hotspot, login, null))
@Test
@UseDataProvider("allIssueStatusesAndResolutionsThatDoNotThrowOnAssign")
public void wsExecution_whenAssigningToUserIfAllowed_shouldNotFail(String status, String resolution) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> {
h.setStatus(status);
});
UserDto userDto = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn(userDto).registerComponents(project);
+ userSessionRule.logIn(userDto).registerProjects(projectData.getProjectDto());
String login = userSessionRule.getLogin();
assertThatNoException().isThrownBy(() -> executeRequest(hotspot, login, null));
@Test
public void wsExecution_whenHotspotDoesNotExist_shouldFail() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
UserDto me = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn().registerComponents(project);
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto());
String notExistingHotspotKey = randomAlphanumeric(10);
String login = me.getLogin();
@Test
@UseDataProvider("allRuleTypesWithStatusesExceptHotspot")
public void wsExecution_whenAssigningToNonexistantIssue_shouldFail(RuleType ruleType, String status) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(ruleType);
IssueDto issue = dbTester.issues().insertIssue(rule, project, file, i -> i
.setType(ruleType));
UserDto me = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn().registerComponents(project);
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto());
String login = me.getLogin();
assertThatThrownBy(() -> executeRequest(issue, login, null))
@Test
public void wsExecution_whenHotspotIsClosed_shouldFailWithNotFoundException() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto issue = dbTester.issues().insertHotspot(rule, project, file, t -> t.setStatus(STATUS_CLOSED));
UserDto me = insertUser(randomAlphanumeric(10));
- userSessionRule.logIn().registerComponents(project);
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto());
String login = me.getLogin();
assertThatThrownBy(() -> executeRequest(issue, login, null))
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.IssueTesting;
import org.sonar.db.project.ProjectDto;
@Test
@UseDataProvider("anyPublicProjectPermissionButHotspotAdmin")
public void fails_with_ForbiddenException_if_project_is_public_and_user_has_no_HotspotAdmin_permission_on_it(String permission) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(permission, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(permission, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
@Test
@UseDataProvider("anyPrivateProjectPermissionButHotspotAdmin")
public void fails_with_ForbiddenException_if_project_is_private_and_has_no_IssueAdmin_permission_on_it(String permission) {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(permission, project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(permission, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
@Test
@UseDataProvider("validStatusAndResolutions")
public void succeeds_on_public_project_with_HotspotAdmin_permission(String status, @Nullable String resolution) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
@Test
@UseDataProvider("validStatusAndResolutions")
public void succeeds_on_private_project_with_HotspotAdmin_permission(String status, @Nullable String resolution) {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
@Test
@UseDataProvider("validStatusAndResolutions")
public void no_effect_and_success_if_hotspot_already_has_specified_status_and_resolution(String status, @Nullable String resolution) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(status).setResolution(resolution));
public void success_to_change_hostpot_to_review_into_reviewed_status(String resolution, String expectedTransitionKey, boolean transitionDone) {
long now = RANDOM.nextInt(232_323);
when(system2.now()).thenReturn(now);
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(STATUS_TO_REVIEW).setResolution(null));
when(transitionService.doTransition(any(), any(), any())).thenReturn(transitionDone);
@Test
public void wsExecution_whenOnMainBranch_shouldDistributeEvents() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
when(branchDto.getBranchType()).thenReturn(BranchType.BRANCH);
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
IssueDto hotspot = dbTester.issues().insertHotspot(branchComponentDto, file);
when(transitionService.doTransition(any(), any(), any())).thenReturn(true);
- userSessionRule.logIn().registerComponents(projectComponentDto)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectComponentDto, branchComponentDto);
+ userSessionRule.logIn().registerProjects(project)
+ .registerBranches(branch)
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
newRequest(hotspot, STATUS_REVIEWED, RESOLUTION_FIXED, NO_COMMENT).execute();
verify(hotspotChangeEventService).distributeHotspotChangedEvent(eq(branchDto.getProjectUuid()), any(HotspotChangedEvent.class));
@Test
public void wsExecution_whenBranchTypeIsPullRequest_shouldNotDistributeEvents() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
when(branchDto.getBranchType()).thenReturn(BranchType.PULL_REQUEST);
IssueDto hotspot = dbTester.issues().insertHotspot(project, file);
public void success_to_change_reviewed_hotspot_back_to_to_review(String resolution, boolean transitionDone) {
long now = RANDOM.nextInt(232_323);
when(system2.now()).thenReturn(now);
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(STATUS_REVIEWED).setResolution(resolution));
String newStatus, @Nullable String newResolution, boolean transitionDone) {
long now = RANDOM.nextInt(232_323);
when(system2.now()).thenReturn(now);
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(currentStatus).setResolution(currentResolution));
public void do_not_persist_comment_if_no_status_change(String status, @Nullable String resolution) {
long now = RANDOM.nextInt(232_323);
when(system2.now()).thenReturn(now);
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(project, file, h -> h.setStatus(status).setResolution(resolution));
String comment = randomAlphabetic(12);
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.user.UserDto;
public void delete_comment_from_hotspot_public_project() {
UserDto userAddingComment = dbTester.users().insertUser();
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
IssueDto hotspot = dbTester.issues().insertHotspot(h -> h.setProject(project));
IssueChangeDto comment = dbTester.issues().insertComment(hotspot, userAddingComment, "Some comment");
.isNotEmpty();
userSessionRule.logIn(userAddingComment);
- userSessionRule.registerComponents(project);
+ userSessionRule.registerProjects(projectData.getProjectDto());
TestRequest request = newRequest(comment.getKey());
UserDto userTryingToDelete = dbTester.users().insertUser();
UserDto userWithHotspotComment = dbTester.users().insertUser();
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
IssueDto hotspot = dbTester.issues().insertHotspot(h -> h.setProject(project));
IssueChangeDto comment = dbTester.issues().insertComment(hotspot, userWithHotspotComment, "Some comment");
-
- userSessionRule.logIn(userTryingToDelete)
- .registerComponents(project);
+ userSessionRule.logIn(userTryingToDelete).registerProjects(projectData.getProjectDto());
TestRequest request = newRequest(comment.getKey());
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.user.UserDto;
public void edit_comment_from_hotspot_public_project() {
UserDto userEditingComment = dbTester.users().insertUser();
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
IssueDto hotspot = dbTester.issues().insertHotspot(h -> h.setProject(project));
IssueChangeDto comment = dbTester.issues().insertComment(hotspot, userEditingComment, "Some comment");
userSessionRule.logIn(userEditingComment);
- userSessionRule.registerComponents(project);
+ userSessionRule.registerProjects(projectData.getProjectDto());
TestRequest request = newRequest(comment.getKey(), "new comment");
UserDto userTryingToEdit = dbTester.users().insertUser();
UserDto userWithHotspotComment = dbTester.users().insertUser();
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
-
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
IssueDto hotspot = dbTester.issues().insertHotspot(h -> h.setProject(project));
IssueChangeDto comment = dbTester.issues().insertComment(hotspot, userWithHotspotComment, "Some comment");
-
- userSessionRule.logIn(userTryingToEdit)
- .registerComponents(project);
+ userSessionRule.logIn(userTryingToEdit).registerProjects(projectData.getProjectDto());
TestRequest request = newRequest(comment.getKey(), "new comment");
@Test
public void fails_with_ForbiddenException_if_project_is_private_and_not_allowed() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
TestRequest request = newRequest(project);
assertThatThrownBy(request::execute)
@Test
public void fails_with_ForbiddenException_if_application_is_private_and_not_allowed() {
- ComponentDto application = dbTester.components().insertPrivateApplication().getMainBranchComponent();
- userSessionRule.registerComponents(application);
+ ProjectData projectData = dbTester.components().insertPrivateApplication();
+ ComponentDto application = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
TestRequest request = newRequest(application);
assertThatThrownBy(request::execute)
@Test
public void succeeds_on_public_project() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
SearchWsResponse response = newRequest(project)
.executeProtobuf(SearchWsResponse.class);
@Test
public void succeeds_on_public_application() {
- ComponentDto application = dbTester.components().insertPublicApplication().getMainBranchComponent();
- userSessionRule.registerApplication(application);
+ ProjectData applicationData = dbTester.components().insertPublicApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
+ userSessionRule.registerApplication(applicationData.getProjectDto());
SearchWsResponse response = newRequest(application)
.executeProtobuf(SearchWsResponse.class);
@Test
public void succeeds_on_private_project_with_permission() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(USER, project);
SearchWsResponse response = newRequest(project)
@Test
public void succeeds_on_private_application_with_permission() {
- ComponentDto application = dbTester.components().insertPrivateApplication().getMainBranchComponent();
- userSessionRule.logIn().registerApplication(application).addProjectPermission(USER, application);
+ ProjectData applicationData = dbTester.components().insertPrivateApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
+ userSessionRule.logIn().registerApplication(applicationData.getProjectDto()).addProjectPermission(USER, applicationData.getProjectDto());
SearchWsResponse response = newRequest(application)
.executeProtobuf(SearchWsResponse.class);
@Test
public void does_not_fail_if_rule_of_hotspot_does_not_exist_in_DB() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
indexPermissions();
IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10))
.executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList())
- .extracting(Hotspots.SearchWsResponse.Hotspot::getKey)
+ .extracting(SearchWsResponse.Hotspot::getKey)
.containsOnly(Arrays.stream(hotspots)
.map(IssueDto::getKey)
.filter(key -> !key.equals(hotspotWithoutRule.getKey()))
@Test
public void returns_no_hotspot_component_nor_rule_when_project_has_no_hotspot() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
Arrays.stream(RuleType.values())
@Test
public void returns_hotspot_components_when_project_has_hotspots() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
ComponentDto fileWithHotspot = dbTester.components().insertComponent(newFileDto(project));
@Test
public void returns_single_component_when_all_hotspots_are_on_project() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
IssueDto[] hotspots = IntStream.range(0, 1 + RANDOM.nextInt(10))
.mapToObj(i -> {
.executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList())
- .extracting(Hotspots.SearchWsResponse.Hotspot::getKey)
+ .extracting(SearchWsResponse.Hotspot::getKey)
.containsOnly(Arrays.stream(hotspots).map(IssueDto::getKey).toArray(String[]::new));
assertThat(response.getComponentsList())
.extracting(Component::getKey)
@Test
public void returns_hotspots_of_specified_project() {
- ComponentDto project1 = dbTester.components().insertPublicProject().getMainBranchComponent();
- ComponentDto project2 = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project1, project2);
+ ProjectData projectData1 = dbTester.components().insertPublicProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = dbTester.components().insertPublicProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
+ userSessionRule.registerProjects(projectData1.getProjectDto(), projectData2.getProjectDto());
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2));
@Test
public void returns_only_hotspots_to_review_or_reviewed_of_project() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto[] hotspots = STATUSES.stream()
@Test
public void returns_hotspots_of_specified_application() {
- ComponentDto application1 = dbTester.components().insertPublicApplication().getMainBranchComponent();
- ComponentDto application2 = dbTester.components().insertPublicApplication().getMainBranchComponent();
- ComponentDto project1 = dbTester.components().insertPublicProject().getMainBranchComponent();
- ComponentDto project2 = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData application1 = dbTester.components().insertPublicApplication();
+ ProjectData application2 = dbTester.components().insertPublicApplication();
+ ProjectData project1 = dbTester.components().insertPublicProject();
+ ProjectData project2 = dbTester.components().insertPublicProject();
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project1, application1));
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project2, application2));
indexViews();
- userSessionRule.registerApplication(application1, project1)
- .registerApplication(application2, project2);
+ userSessionRule.registerApplication(application1.getProjectDto(), project1.getProjectDto())
+ .registerApplication(application2.getProjectDto(), project2.getProjectDto());
indexPermissions();
- ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
- ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2));
+ ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1.getMainBranchComponent()));
+ ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2.getMainBranchComponent()));
IssueDto[] hotspots2 = IntStream.range(0, 1 + RANDOM.nextInt(10))
.mapToObj(i -> {
RuleDto rule = newRule(SECURITY_HOTSPOT);
- insertHotspot(project1, file1, rule);
- return insertHotspot(project2, file2, rule);
+ insertHotspot(project1.getMainBranchComponent(), file1, rule);
+ return insertHotspot(project2.getMainBranchComponent(), file2, rule);
})
.toArray(IssueDto[]::new);
indexIssues();
- SearchWsResponse responseApplication1 = newRequest(application1)
+ SearchWsResponse responseApplication1 = newRequest(application1.getMainBranchComponent())
.executeProtobuf(SearchWsResponse.class);
assertThat(responseApplication1.getHotspotsList())
.doesNotContainAnyElementsOf(Arrays.stream(hotspots2).map(IssueDto::getKey).collect(toList()));
assertThat(responseApplication1.getComponentsList())
.extracting(Component::getKey)
- .containsOnly(project1.getKey(), file1.getKey());
+ .containsOnly(project1.projectKey(), file1.getKey());
- SearchWsResponse responseApplication2 = newRequest(application2)
+ SearchWsResponse responseApplication2 = newRequest(application2.getMainBranchComponent())
.executeProtobuf(SearchWsResponse.class);
assertThat(responseApplication2.getHotspotsList())
.containsOnly(Arrays.stream(hotspots2).map(IssueDto::getKey).toArray(String[]::new));
assertThat(responseApplication2.getComponentsList())
.extracting(Component::getKey)
- .containsOnly(project2.getKey(), file2.getKey());
+ .containsOnly(project2.projectKey(), file2.getKey());
}
@Test
public void returns_hotspots_of_specified_application_branch() {
- ComponentDto application = dbTester.components().insertPublicApplication().getMainBranchComponent();
+ ProjectData applicationData = dbTester.components().insertPublicApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
ComponentDto applicationBranch = dbTester.components().insertProjectBranch(application, b -> b.setKey("appBranch"));
- ComponentDto project1 = dbTester.components().insertPublicProject().getMainBranchComponent();
- ComponentDto project2 = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData1 = dbTester.components().insertPublicProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = dbTester.components().insertPublicProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project1, application));
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project2, applicationBranch));
indexViews();
- userSessionRule.registerApplication(application, applicationBranch, project1, project2);
+ userSessionRule.registerApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2));
@Test
public void returns_hotspot_of_branch_or_pullRequest() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey("branch"));
ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST).setKey("prKey"));
@Test
@UseDataProvider("onlyMineParamValues")
public void returns_hotspots_of_specified_project_assigned_to_current_user_if_only_mine_is_set(String onlyMineParameter, boolean shouldFilter) {
- ComponentDto project1 = dbTester.components().insertPublicProject().getMainBranchComponent();
- String assigneeUuid = this.userSessionRule.logIn().registerComponents(project1).getUuid();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project1 = projectData.getMainBranchComponent();
+ String assigneeUuid = this.userSessionRule.logIn().registerProjects(projectData.getProjectDto()).getUuid();
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project1));
@Test
public void fail_if_hotspots_provided_with_onlyMine_param() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(USER, project);
TestRequest request = actionTester.newRequest()
@Test
public void returns_hotpots_with_any_status_if_no_status_nor_resolution_parameter() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
List<IssueDto> hotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file)
@Test
public void returns_hotpots_reviewed_as_safe_and_fixed_if_status_is_REVIEWED_and_resolution_is_not_set() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
List<IssueDto> reviewedHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file)
@Test
public void returns_hotpots_reviewed_as_safe_if_status_is_REVIEWED_and_resolution_is_SAFE() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
List<IssueDto> safeHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file)
@Test
public void returns_hotpots_reviewed_as_fixed_if_status_is_REVIEWED_and_resolution_is_FIXED() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
List<IssueDto> fixedHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file)
@Test
public void returns_only_unresolved_hotspots_when_status_is_TO_REVIEW() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
@UseDataProvider("validStatusesAndResolutions")
public void returns_fields_of_hotspot(String status, @Nullable String resolution) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
@UseDataProvider("allSQCategories")
public void returns_SQCategory_and_VulnerabilityProbability_of_rule(Set<String> securityStandards, SQCategory expected) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT, t -> t.setSecurityStandards(securityStandards));
.executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList()).hasSize(1);
- Hotspots.SearchWsResponse.Hotspot actual = response.getHotspots(0);
+ SearchWsResponse.Hotspot actual = response.getHotspots(0);
assertThat(actual.getSecurityCategory()).isEqualTo(expected.getKey());
assertThat(actual.getVulnerabilityProbability()).isEqualTo(expected.getVulnerability().name());
}
@Test
public void does_not_fail_when_hotspot_has_none_of_the_nullable_fields() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
public void returns_details_of_components() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto directory = dbTester.components().insertComponent(newDirectory(project, "donut/acme"));
ComponentDto directory2 = dbTester.components().insertComponent(newDirectory(project, "foo/bar"));
@Test
public void returns_branch_field_of_components_of_branch() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
String branchName = randomAlphanumeric(248);
ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey(branchName));
- userSessionRule.registerComponents(project, branch);
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto directory = dbTester.components().insertComponent(newDirectoryOnBranch(branch, "donut/acme", project.uuid()));
ComponentDto file = dbTester.components().insertComponent(newFileDto(branch, project.uuid()));
@Test
public void returns_pullRequest_field_of_components_of_pullRequest() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
String pullRequestKey = randomAlphanumeric(100);
ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST)
.setKey(pullRequestKey));
- userSessionRule.registerComponents(project, pullRequest);
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto directory = dbTester.components().insertComponent(newDirectoryOnBranch(pullRequest, "donut/acme", project.uuid()));
ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest, project.uuid()));
@Test
public void returns_hotspots_ordered_by_vulnerabilityProbability_score_then_rule_uuid() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
List<IssueDto> hotspots = Arrays.stream(SQCategory.values())
@Test
public void returns_hotspots_ordered_by_file_path_then_line_then_key() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project).setPath("b/c/a"));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project).setPath("b/c/b"));
@Test
public void returns_hotspot_with_secondary_locations() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
ComponentDto anotherFile = dbTester.components().insertComponent(newFileDto(project));
@Test
public void returns_first_page_with_100_results_by_default() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
public void returns_specified_page_with_100_results_by_default() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
public void returns_specified_page_with_specified_number_of_results() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
public void returns_empty_if_none_of_hotspot_keys_exist() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
public void returns_specified_hotspots() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
public void returns_hotspots_with_specified_sonarsourceSecurity_category() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@Test
public void returns_hotspots_with_specified_cwes() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@Test
public void returns_hotspots_with_specified_owaspTop10_category() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@Test
public void returns_hotspots_with_specified_pciDss_category() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@Test
public void returns_hotspots_with_specified_owaspAsvs_category() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@Test
public void returns_hotspots_with_specified_owaspAsvs_level() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@Test
public void returns_hotspots_with_specified_owasp2021Top10_category() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@Test
public void returns_hotspots_with_specified_sansTop25_category() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule1 = newRule(SECURITY_HOTSPOT);
@Test
public void returns_hotspots_with_specified_files() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project));
@Test
public void returns_hotspots_on_the_leak_period_when_inNewCodePeriod_is_true() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
long periodDate = 800_996_999_332L;
@Test
public void returns_hotspots_on_the_leak_period_when_inNewCodePeriod_is_true_and_branch_uses_reference_branch() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
dbTester.components().insertSnapshot(project, t -> t.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
long referenceDate = 800_996_999_332L;
system2.setNow(referenceDate + 10_000);
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(referenceDate).setLast(false));
long referenceDate = 800_996_999_332L;
system2.setNow(referenceDate + 10_000);
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto pr = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST).setKey("pr"));
- userSessionRule.registerComponents(project);
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(pr, project.uuid()));
dbTester.components().insertSnapshot(project, t -> t.setPeriodDate(referenceDate).setLast(true));
@Test
public void verify_response_example() {
- ComponentDto project = dbTester.components().insertPublicProject(componentDto -> componentDto
+ ProjectData projectData = dbTester.components().insertPublicProject(componentDto -> componentDto
.setName("test-project")
.setLongName("test-project")
- .setKey("com.sonarsource:test-project")).getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ .setKey("com.sonarsource:test-project"));
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto fileWithHotspot = dbTester.components().insertComponent(newFileDto(project)
.setKey("com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java")
@Test
public void returns_hotspots_with_ruleKey() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule1 = newRule(SECURITY_HOTSPOT);
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.protobuf.DbCommons.TextRange;
import org.sonar.db.protobuf.DbIssues;
@Test
public void fails_with_ForbiddenException_if_project_is_private_and_not_allowed() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@Test
public void succeeds_on_hotspot_with_flow() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
ComponentDto anotherFile = dbTester.components().insertComponent(newFileDto(project));
DbIssues.Locations.Builder locations = DbIssues.Locations.newBuilder()
RuleDto rule = newRule(SECURITY_HOTSPOT);
var hotspot = dbTester.issues().insertHotspot(rule, project, file, i -> i.setLocations(locations.build()));
mockChangelogAndCommentsFormattingContext();
-
- userSessionRule.registerComponents(project);
+ userSessionRule.registerProjects(projectData.getProjectDto());
Hotspots.ShowWsResponse response = newRequest(hotspot)
.executeProtobuf(Hotspots.ShowWsResponse.class);
@Test
public void succeeds_on_public_project() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@Test
public void succeeds_on_private_project_with_permission() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
public void return_canChangeStatus_false_on_public_project_when_anonymous() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@Test
@UseDataProvider("allPublicProjectPermissionsButSECURITYHOTSPOT_ADMIN")
public void return_canChangeStatus_false_on_public_project_when_authenticated_without_SECURITYHOTSPOT_ADMIN_permission(@Nullable String permission) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.logIn().registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.logIn().registerProjects(projectData.getProjectDto());
if (permission != null) {
userSessionRule.addProjectPermission(permission, project);
}
@Test
@UseDataProvider("allPublicProjectPermissionsButSECURITYHOTSPOT_ADMIN")
public void return_canChangeStatus_true_on_public_project_when_authenticated_with_SECURITYHOTSPOT_ADMIN_permission(@Nullable String permission) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
if (permission != null) {
userSessionRule.addProjectPermission(permission, project);
}
@Test
@UseDataProvider("allPrivateProjectPermissionsButSECURITYHOTSPOT_ADMIN_and_USER")
public void return_canChangeStatus_false_on_private_project_without_SECURITYHOTSPOT_ADMIN_permission(@Nullable String permission) {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
userSessionRule
- .registerComponents(project)
+ .registerProjects(projectData.getProjectDto())
.logIn()
- .addProjectPermission(UserRole.USER, project);
+ .addProjectPermission(UserRole.USER, projectData.getProjectDto());
if (permission != null) {
- userSessionRule.addProjectPermission(permission, project);
+ userSessionRule.addProjectPermission(permission, projectData.getProjectDto());
}
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
@UseDataProvider("allPrivateProjectPermissionsButSECURITYHOTSPOT_ADMIN_and_USER")
public void return_canChangeStatus_false_on_private_project_with_SECURITYHOTSPOT_ADMIN_permission(@Nullable String permission) {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
userSessionRule
- .registerComponents(project)
+ .registerProjects(projectData.getProjectDto())
.logIn()
- .addProjectPermission(UserRole.USER, project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ .addProjectPermission(UserRole.USER, projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
if (permission != null) {
- userSessionRule.addProjectPermission(permission, project);
+ userSessionRule.addProjectPermission(permission, projectData.getProjectDto());
}
- ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
+ ComponentDto file = dbTester.components().insertComponent(newFileDto(mainBranch));
RuleDto rule = newRule(SECURITY_HOTSPOT);
- IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
+ IssueDto hotspot = dbTester.issues().insertHotspot(rule, mainBranch, file);
mockChangelogAndCommentsFormattingContext();
Hotspots.ShowWsResponse response = newRequest(hotspot)
@Test
@UseDataProvider("statusAndResolutionCombinations")
public void returns_status_and_resolution(String status, @Nullable String resolution) {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
@Test
public void dispatch_description_sections_of_advanced_rule_in_relevant_field() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
@Test
public void fallbacks_to_default_section_in_case_of_legacy_rule() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
@Test
public void ignore_default_section_if_root_cause_provided() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
@Test
public void returns_html_description_for_custom_rules() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
@Test
public void handles_null_description_for_custom_rules() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
@Test
public void handle_given_description_section_with_3_contexts_return_one_alphabetically() {
- ComponentDto project = dbTester.components().insertPrivateProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
userSessionRule.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
@Test
public void returns_hotspot_component_and_rule() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@Test
public void returns_no_textRange_when_locations_have_none() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@Test
@UseDataProvider("randomTextRangeValues")
public void returns_textRange(int startLine, int endLine, int startOffset, int endOffset) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@Test
public void returns_no_assignee_when_user_does_not_exist() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setAssigneeUuid(randomAlphabetic(10)));
@Test
public void returns_assignee_details_when_user_exists() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
UserDto assignee = dbTester.users().insertUser();
@Test
public void returns_no_avatar_if_assignee_has_no_email() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
UserDto assignee = dbTester.users().insertUser(t -> t.setEmail(null));
@Test
public void returns_inactive_when_assignee_is_inactive() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
UserDto assignee = dbTester.users().insertUser(t -> t.setActive(false));
@Test
public void returns_author_login_when_user_does_not_exist() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
String authorLogin = randomAlphabetic(10);
@Test
public void returns_author_details_when_user_exists() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
UserDto author = dbTester.users().insertUser();
@Test
public void returns_no_avatar_if_author_has_no_email() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
UserDto author = dbTester.users().insertUser(t -> t.setEmail(null));
@Test
public void returns_inactive_if_author_is_inactive() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
UserDto author = dbTester.users().insertUser(t -> t.setActive(false));
@Test
public void returns_textRange_missing_fields() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@UseDataProvider("allSQCategoryAndVulnerabilityProbability")
public void returns_securityCategory_and_vulnerabilityProbability_of_rule(Set<String> standards,
SQCategory expected) {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT, t -> t.setSecurityStandards(standards));
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@Test
public void returns_project_twice_when_hotspot_on_project() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, project,
t -> t.setLocations(DbIssues.Locations.newBuilder()
@Test
public void returns_branch_but_no_pullRequest_on_component_and_project_on_non_main_branch() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
String branchName = randomAlphanumeric(248);
ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey(branchName));
userSessionRule.addProjectBranchMapping(project.uuid(), branch);
ComponentDto file = dbTester.components().insertComponent(newFileDto(branch, project.uuid()));
- userSessionRule.registerComponents(project);
+ userSessionRule.registerProjects(projectData.getProjectDto());
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, branch, file,
t -> t.setLocations(DbIssues.Locations.newBuilder()
@Test
public void returns_pullRequest_but_no_branch_on_component_and_project_on_pullRequest() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
String pullRequestKey = randomAlphanumeric(100);
ComponentDto pullRequest = dbTester.components().insertProjectBranch(project,
t -> t.setBranchType(BranchType.PULL_REQUEST).setKey(pullRequestKey));
userSessionRule.addProjectBranchMapping(project.uuid(), pullRequest);
ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest));
- userSessionRule.registerComponents(project);
+ userSessionRule.registerProjects(projectData.getProjectDto());
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, pullRequest, file,
t -> t.setLocations(DbIssues.Locations.newBuilder()
@Test
public void returns_hotspot_changelog_and_comments() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
RuleDto rule = newRule(SECURITY_HOTSPOT);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file,
@Test
public void returns_user_details_of_users_from_ChangelogAndComments() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
RuleDto rule = newRule(SECURITY_HOTSPOT);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file);
@Test
public void returns_user_of_users_from_ChangelogAndComments_and_assignee_and_author() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
RuleDto rule = newRule(SECURITY_HOTSPOT);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
UserDto author = dbTester.users().insertUser();
.extracting(User::getLogin, User::getName, User::getActive)
.containsExactlyInAnyOrder(
Stream.concat(
- Stream.of(author, assignee),
- changeLogAndCommentsUsers.stream())
+ Stream.of(author, assignee),
+ changeLogAndCommentsUsers.stream())
.map(t -> tuple(t.getLogin(), t.getName(), t.isActive()))
.toArray(Tuple[]::new));
}
@Test
public void do_not_duplicate_user_if_author_assignee_ChangeLogComment_user() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
RuleDto rule = newRule(SECURITY_HOTSPOT);
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
UserDto author = dbTester.users().insertUser();
@Test
public void response_shouldContainCodeVariants() {
- ComponentDto project = dbTester.components().insertPublicProject().getMainBranchComponent();
- userSessionRule.registerComponents(project);
+ ProjectData projectData = dbTester.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
RuleDto rule = newRule(SECURITY_HOTSPOT);
IssueDto hotspot = dbTester.issues().insertHotspot(rule, project, file, t -> t.setCodeVariants(List.of("variant1", "variant2")));
@Test
public void verify_response_example() {
- ComponentDto project = dbTester.components().insertPublicProject(componentDto -> componentDto
+ ProjectData projectData = dbTester.components().insertPublicProject(componentDto -> componentDto
.setName("test-project")
.setLongName("test-project")
- .setKey("com.sonarsource:test-project")).getMainBranchComponent();
- userSessionRule.registerComponents(project)
- .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, project);
+ .setKey("com.sonarsource:test-project"));
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSessionRule.registerProjects(projectData.getProjectDto())
+ .addProjectPermission(UserRole.SECURITYHOTSPOT_ADMIN, projectData.getProjectDto());
ComponentDto file = dbTester.components().insertComponent(
newFileDto(project)
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.issue.AvatarResolverImpl;
@Test
public void search_all_issues_when_no_parameter() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
IssueDto issue = db.issues().insertIssue(rule, project, projectFile);
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssues();
SearchWsResponse result = ws.newRequest().executeProtobuf(SearchWsResponse.class);
@Test
public void issues_on_different_projects() {
RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPublicProject();
+ ComponentDto project = projectData1.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue1 = db.issues().insertIssue(rule, project, file);
- ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPublicProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
ComponentDto file2 = db.components().insertComponent(newFileDto(project2));
IssueDto issue2 = db.issues().insertIssue(rule, project2, file2);
- allowAnyoneOnProjects(project, project2);
+ allowAnyoneOnProjects(projectData1.getProjectDto(), projectData2.getProjectDto());
indexIssues();
SearchWsResponse response = ws.newRequest().executeProtobuf(SearchWsResponse.class);
@Test
public void search_since_in_new_code_period_on_project() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
db.components().insertSnapshot(project, a -> a.setPeriodDate(parseDateTime("2015-09-03T00:00:00+0100").getTime()));
RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
IssueDto issueBeforeLeak = db.issues().insertIssue(rule, project, file, i -> i.setKee(UUID_EXAMPLE_02)
.setIssueCreationDate(parseDateTime("2014-09-04T00:00:00+0100"))
.setIssueUpdateDate(parseDateTime("2015-10-04T00:00:00+0100")));
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssues();
ws.newRequest()
@Test
public void search_by_file_uuid() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssues();
ws.newRequest()
@Test
public void search_by_file_key() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
ComponentDto unitTest = db.components().insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setKey("FK2"));
RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
IssueDto issueOnFile = db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
IssueDto issueOnTest = db.issues().insertIssue(rule, project, unitTest, i -> i.setKee("2bd4eac2-b650-4037-80bc-7b1182fd47d4"));
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssues();
ws.newRequest()
@Test
public void search_by_directory_path() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto directory = db.components().insertComponent(newDirectory(project, "D1", "src/main/java/dir"));
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1").setPath(directory.path() + "/MyComponent.java"));
RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssues();
ws.newRequest()
@Test
public void search_by_view_uuid() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setKey("MyView"));
db.components().insertComponent(newProjectCopy(project, view));
RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
- allowAnyoneOnProjects(project, view);
+ allowAnyoneOnProjects(projectData.getProjectDto());
+ allowAnyoneOnPortfolios(view);
+
indexIssuesAndViews();
ws.newRequest()
@Test
public void search_by_sub_view_uuid() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("V1").setKey("MyView"));
ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SV1", "MySubView"));
db.components().insertComponent(newProjectCopy(project, subView));
- allowAnyoneOnProjects(project, view, subView);
+ allowAnyoneOnProjects(projectData.getProjectDto());
+ allowAnyoneOnPortfolios(view, subView);
indexIssuesAndViews();
ws.newRequest()
@Test
public void search_by_sub_view_uuid_return_only_authorized_view() {
- ComponentDto project = db.components().insertPublicProject(p -> p.setKey("PK1")).getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject(p -> p.setKey("PK1"));
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setKey("FK1"));
RuleDto rule = db.rules().insertIssueRule(r -> r.setRuleKey(RuleKey.of("xoo", "x1")));
db.issues().insertIssue(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"));
ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubPortfolio(view, "SV1", "MySubView"));
db.components().insertComponent(newProjectCopy(project, subView));
// User has no permission on the view, no issue will be returned
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssuesAndViews();
ws.newRequest()
@Test
public void search_by_application_key() {
- ComponentDto application = db.components().insertPrivateApplication().getMainBranchComponent();
- ComponentDto project1 = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData applicationData = db.components().insertPrivateApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPrivateProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPrivateProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
db.components().insertComponents(newProjectCopy(project1, application));
db.components().insertComponents(newProjectCopy(project2, application));
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue1 = db.issues().insertIssue(rule, project1, project1);
IssueDto issue2 = db.issues().insertIssue(rule, project2, project2);
- allowAnyoneOnApplication(application, project1, project2);
+ allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
userSession.addProjectPermission(USER, application);
indexIssuesAndViews();
@Test
public void search_by_application_key_and_branch() {
- ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app")).getMainBranchComponent();
+ ProjectData applicatioData = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app"));
+ ComponentDto application = applicatioData.getMainBranchComponent();
String appBranch1 = "app-branch1";
String appBranch2 = "app-branch2";
String proj1branch1 = "proj1branch1";
String proj1branch2 = "proj1branch2";
ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey(appBranch1));
ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey(appBranch2));
- ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1")).getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPrivateProject(p -> p.setKey("prj1"));
+ ComponentDto project1 = projectData1.getMainBranchComponent();
ComponentDto project1Branch1 = db.components().insertProjectBranch(project1, b -> b.setKey(proj1branch1));
ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1, project1.uuid()));
ComponentDto project1Branch2 = db.components().insertProjectBranch(project1, b -> b.setKey(proj1branch2));
- ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2")).getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPrivateProject(p -> p.setKey("prj2"));
+ ComponentDto project2 = projectData2.getMainBranchComponent();
db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1));
db.components().insertComponents(newProjectCopy(project2, applicationBranch1));
db.components().insertComponents(newProjectCopy(project1Branch2, applicationBranch2));
IssueDto issueOnProject1Branch2 = db.issues().insertIssue(issueRule, project1Branch2, project1Branch2);
IssueDto issueOnProject2 = db.issues().insertIssue(issueRule, project2, project2);
db.issues().insertHotspot(hotspotRule, project2, project2);
- allowAnyoneOnProjects(project1, project2, application);
+ allowAnyoneOnProjects(projectData1.getProjectDto(), projectData2.getProjectDto(), applicatioData.getProjectDto());
userSession.addProjectPermission(USER, application);
indexIssuesAndViews();
@Test
public void ignore_application_without_browse_permission() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
db.components().insertComponents(newProjectCopy("PC1", project, application));
RuleDto rule = db.rules().insertIssueRule();
db.issues().insertIssue(rule, project, project);
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
@Test
public void search_application_without_projects() {
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+ ProjectData applicationData = db.components().insertPublicApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
RuleDto rule = db.rules().insertIssueRule();
db.issues().insertIssue(rule, project, project);
- allowAnyoneOnProjects(project, application);
+ allowAnyoneOnProjects(projectData.getProjectDto(), applicationData.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
public void search_by_application_and_by_new_code_period() {
Date now = new Date();
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+ ProjectData applicationData = db.components().insertPublicApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
// Project 1
- ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPublicProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
db.components().insertComponents(newProjectCopy("PC1", project1, application));
IssueDto project1Issue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10)));
IssueDto project1Issue2 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20)));
// Project 2
- ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPublicProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
db.components().insertSnapshot(project2, s -> s.setPeriodDate(addDays(now, -25).getTime()));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
IssueDto project2Issue1 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15)));
IssueDto project2Issue2 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30)));
// Permissions and index
- allowAnyoneOnApplication(application, project1, project2);
+ allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
@Test
public void search_by_application_and_project() {
- ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPublicProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPublicProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
+ ProjectData applicationData = db.components().insertPublicApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
db.components().insertComponents(newProjectCopy("PC1", project1, application));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
RuleDto rule = db.rules().insertIssueRule();
IssueDto issue1 = db.issues().insertIssue(rule, project1, project1);
IssueDto issue2 = db.issues().insertIssue(rule, project2, project2);
- allowAnyoneOnApplication(application, project1, project2);
+ allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
public void search_by_application_and_project_and_new_code_period() {
Date now = new Date();
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+ ProjectData applicationData = db.components().insertPublicApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
// Project 1
- ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPublicProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
db.components().insertComponents(newProjectCopy("PC1", project1, application));
IssueDto project1Issue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10)));
IssueDto project1Issue2 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20)));
// Project 2
- ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPublicProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
db.components().insertSnapshot(project2, s -> s.setPeriodDate(addDays(now, -25).getTime()));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
IssueDto project2Issue1 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15)));
IssueDto project2Issue2 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30)));
// Permissions and index
- allowAnyoneOnApplication(application, project1, project2);
+ allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
public void search_by_application_and_by_new_code_period_when_one_project_has_no_leak() {
Date now = new Date();
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto application = db.components().insertPublicApplication().getMainBranchComponent();
+ ProjectData applicationData = db.components().insertPublicApplication();
+ ComponentDto application = applicationData.getMainBranchComponent();
// Project 1
- ComponentDto project1 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData1 = db.components().insertPublicProject();
+ ComponentDto project1 = projectData1.getMainBranchComponent();
db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
db.components().insertComponents(newProjectCopy("PC1", project1, application));
IssueDto project1Issue1 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10)));
IssueDto project1Issue2 = db.issues().insertIssue(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20)));
// Project 2, without leak => no issue form it should be returned
- ComponentDto project2 = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData2 = db.components().insertPublicProject();
+ ComponentDto project2 = projectData2.getMainBranchComponent();
db.components().insertSnapshot(project2, s -> s.setPeriodDate(null));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
IssueDto project2Issue1 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15)));
IssueDto project2Issue2 = db.issues().insertIssue(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30)));
// Permissions and index
- allowAnyoneOnApplication(application, project1, project2);
+ allowAnyoneOnApplication(applicationData.getProjectDto(), projectData1.getProjectDto(), projectData2.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
@Test
public void search_by_branch() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = db.issues().insertIssue(rule, project, file);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssuesAndViews();
// On component key + branch
@Test
public void return_branch_in_component_list() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
String branchName = randomAlphanumeric(248);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
@Test
public void search_by_pull_request() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
ComponentDto pullRequestFile = db.components().insertComponent(newFileDto(pullRequest, project.uuid()));
IssueDto pullRequestIssue = db.issues().insertIssue(rule, pullRequest, pullRequestFile);
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
@Test
public void search_using_main_branch_name() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest()
@Test
public void does_not_return_branch_issues_on_not_contextualized_search() {
RuleDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
ComponentDto branch = db.components().insertProjectBranch(project);
ComponentDto branchFile = db.components().insertComponent(newFileDto(branch, project.uuid()));
IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
- allowAnyoneOnProjects(project);
+ allowAnyoneOnProjects(projectData.getProjectDto());
indexIssuesAndViews();
SearchWsResponse result = ws.newRequest().executeProtobuf(SearchWsResponse.class);
.doesNotContain(branchIssue.getKey());
}
- private void allowAnyoneOnProjects(ComponentDto... projects) {
- userSession.registerComponents(projects);
+ private void allowAnyoneOnProjects(ProjectDto... projects) {
+ userSession.registerProjects(projects);
Arrays.stream(projects).forEach(p -> permissionIndexer.allowOnlyAnyone(p));
}
- private void allowAnyoneOnApplication(ComponentDto application, ComponentDto... projects) {
+ private void allowAnyoneOnPortfolios(ComponentDto... portfolios) {
+ userSession.registerPortfolios(portfolios);
+ Arrays.stream(portfolios).forEach(p -> permissionIndexer.allowOnlyAnyone(p));
+ }
+
+ private void allowAnyoneOnApplication(ProjectDto application, ProjectDto... projects) {
userSession.registerApplication(application);
Arrays.stream(projects).forEach(p -> permissionIndexer.allowOnlyAnyone(p));
}
import java.util.List;
import java.util.function.Consumer;
import javax.annotation.Nullable;
+import org.jetbrains.annotations.NotNull;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.core.util.SequenceUuidFactory;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.es.EsTester;
private void logIn(IssueDto issueDto) {
UserDto user = db.users().insertUser("john");
+ ProjectDto projectDto = retrieveProjectDto(issueDto);
userSession.logIn(user)
- .registerComponents(
- dbClient.componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get(),
- dbClient.componentDao().selectByUuid(db.getSession(), issueDto.getComponentUuid()).get());
+ .registerProjects(projectDto);
+ }
+
+ @NotNull
+ private ProjectDto retrieveProjectDto(IssueDto issueDto) {
+ BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), issueDto.getProjectUuid())
+ .orElseThrow();
+ return db.getDbClient().projectDao().selectByUuid(db.getSession(), branchDto.getProjectUuid())
+ .orElseThrow();
}
private void logInAndAddProjectPermission(IssueDto issueDto, String permission) {
UserDto user = db.users().insertUser("john");
+ ProjectDto projectDto = retrieveProjectDto(issueDto);
userSession.logIn(user)
- .addProjectPermission(permission, dbClient.componentDao().selectByUuid(db.getSession(), issueDto.getProjectUuid()).get());
+ .addProjectPermission(permission, projectDto);
}
private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) {
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.ResourceTypesRule;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.LiveMeasureDto;
public void portfolio_local_reference_in_portfolio() {
ComponentDto view = db.components().insertComponent(ComponentTesting.newPortfolio("VIEW1-UUID")
.setKey("Apache-Projects").setName("Apache Projects"));
- userSession.registerComponents(view);
+ userSession.registerPortfolios(view);
ComponentDto view2 = db.components().insertPrivatePortfolio();
userSession.addProjectPermission(USER, view2);
ComponentDto localView = db.components().insertComponent(
@Test
public void project_branch_reference_from_application_branch() {
MetricDto ncloc = insertNclocMetric();
- ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app-key")).getMainBranchComponent();
- userSession.registerApplication(application);
+ ProjectData applicationData = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app-key"));
+ ComponentDto application = applicationData.getMainBranchComponent();
+ userSession.registerApplication(applicationData.getProjectDto());
String branchName = "app-branch";
ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey(branchName), a -> a.setUuid("custom-uuid"));
- userSession.addProjectBranchMapping(application.uuid(), applicationBranch);
- ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key")).getMainBranchComponent();
+ userSession.addProjectBranchMapping(applicationData.projectUuid(), applicationBranch);
+ ProjectData projectData = db.components().insertPrivateProject(p -> p.setKey("project-key"));
+ ComponentDto project = projectData.getMainBranchComponent();
ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch"));
- userSession.addProjectBranchMapping(project.uuid(), projectBranch);
+ userSession.addProjectBranchMapping(projectData.projectUuid(), projectBranch);
ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch)
.setKey(applicationBranch.getKey() + branchName + projectBranch.getKey()));
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventComponentChangeDto;
import org.sonar.db.event.EventComponentChangeDto.ChangeCategory;
@Test
public void return_analyses_of_portfolio() {
ComponentDto view = db.components().insertPublicPortfolio();
- userSession.registerComponents(view);
+ userSession.registerPortfolios(view);
SnapshotDto firstAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(1_000_000L));
SnapshotDto secondAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(2_000_000L));
SnapshotDto thirdAnalysis = db.components().insertSnapshot(newAnalysis(view).setCreatedAt(3_000_000L));
@Test
public void fail_if_not_a_project_portfolio_or_application() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- ComponentDto file = db.components().insertComponent(newFileDto(project));
- db.components().insertSnapshot(newAnalysis(project));
- userSession.registerComponents(project, file);
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ ComponentDto file = db.components().insertComponent(newFileDto(mainBranch));
+ db.components().insertSnapshot(newAnalysis(mainBranch));
+ userSession.registerProjects(projectData.getProjectDto());
var fileDbKey = file.getKey();
assertThatThrownBy(() -> call(fileDbKey))
@Test
public void fail_if_branch_does_not_exist() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- userSession.addProjectPermission(UserRole.USER, project);
- db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
+ userSession.addProjectPermission(UserRole.USER, projectData.getProjectDto());
+ db.components().insertProjectBranch(mainBranch, b -> b.setKey("my_branch"));
var searchRequest = SearchRequest.builder()
- .setProject(project.getKey())
+ .setProject(mainBranch.getKey())
.setBranch("another_branch")
.build();
assertThatThrownBy(() -> call(searchRequest))
.isInstanceOf(NotFoundException.class)
- .hasMessage(format("Component '%s' on branch '%s' not found", project.getKey(), "another_branch"));
+ .hasMessage(format("Component '%s' on branch '%s' not found", mainBranch.getKey(), "another_branch"));
}
@Test
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.ProjectLinkDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
@Test
public void fail_if_anonymous() {
userSession.anonymous();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(project);
+
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto project = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
assertThatThrownBy(() -> ws.newRequest()
.setParam(PARAM_PROJECT_KEY, project.getKey())
import org.sonar.db.audit.NoOpAuditPersister;
import org.sonar.db.component.ComponentDao;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDao;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.protobuf.DbFileSources;
@Test
public void pull_request() {
- ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPrivateProject();
+ ComponentDto mainBranch = projectData.getMainBranchComponent();
String pullRequestKey = randomAlphanumeric(100);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
- ComponentDto file = db.components().insertComponent(newFileDto(branch, project.uuid()));
+ ComponentDto branch = db.components().insertProjectBranch(mainBranch, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
+ ComponentDto file = db.components().insertComponent(newFileDto(branch, mainBranch.uuid()));
db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto()
.setUuid(Uuids.createFast())
.setProjectUuid(branch.uuid())
db.commit();
userSession.logIn("login")
- .addProjectPermission(UserRole.USER, project)
- .addProjectPermission(UserRole.CODEVIEWER, project, file)
- .registerComponents(branch);
+ .addProjectPermission(UserRole.USER, projectData.getProjectDto())
+ .addProjectPermission(UserRole.CODEVIEWER, projectData.getProjectDto())
+ .addProjectPermission(UserRole.CODEVIEWER, file);
tester.newRequest()
.setParam("key", file.getKey())
@Test
public void hide_scmAuthors() {
- ComponentDto publicProject = db.components().insertPublicProject().getMainBranchComponent();
- userSession.registerComponents(publicProject);
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto publicProject = projectData.getMainBranchComponent();
+
+ userSession.registerProjects(projectData.getProjectDto());
DbFileSources.Data data = DbFileSources.Data.newBuilder()
.addLines(newLineBuilder().setScmAuthor("isaac@asimov.com"))
@Test
public void show_scmAuthors() {
- ComponentDto publicProject = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectData projectData = db.components().insertPublicProject();
+ ComponentDto publicProject = projectData.getMainBranchComponent();
UserDto user = db.users().insertUser();
- userSession.logIn(user)
- .registerComponents(publicProject);
+ userSession.logIn(user).registerProjects(projectData.getProjectDto());
DbFileSources.Data data = DbFileSources.Data.newBuilder()
.addLines(newLineBuilder().setScmAuthor("isaac@asimov.com"))
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ProjectData;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.permission.GlobalPermission;
.setScope(COMPONENT)
.setComponentQualifiers(Qualifier.VIEW, Qualifier.APP)
.build();
- ComponentDto application = componentDbTester.insertPublicApplication().getMainBranchComponent();
+ ProjectData projectData = componentDbTester.insertPublicApplication();
+ ComponentDto application = projectData.getMainBranchComponent();
QualityGateDto qualityGateDto = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way"));
db.qualityGates().associateProjectToQualityGate(project, qualityGateDto);
- userSession.registerComponents(application);
+ userSession.registerProjects(projectData.getProjectDto());
init(page);
String result = ws.newRequest()