use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class PurgeDaoTest method delete_application.
@Test
public void delete_application() {
MetricDto metric = db.measures().insertMetric();
ComponentDto project = db.components().insertPrivateProject();
BranchDto projectBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid()).get();
RuleDefinitionDto rule = db.rules().insert();
ComponentDto app = db.components().insertPrivateApplication();
ComponentDto appBranch = db.components().insertProjectBranch(app);
ComponentDto otherApp = db.components().insertPrivateApplication();
ComponentDto otherAppBranch = db.components().insertProjectBranch(otherApp);
SnapshotDto appAnalysis = db.components().insertSnapshot(app);
SnapshotDto appBranchAnalysis = db.components().insertSnapshot(appBranch);
SnapshotDto otherAppAnalysis = db.components().insertSnapshot(otherApp);
SnapshotDto otherAppBranchAnalysis = db.components().insertSnapshot(otherAppBranch);
MeasureDto appMeasure = db.measures().insertMeasure(app, appAnalysis, metric);
MeasureDto appBranchMeasure = db.measures().insertMeasure(appBranch, appBranchAnalysis, metric);
MeasureDto otherAppMeasure = db.measures().insertMeasure(otherApp, otherAppAnalysis, metric);
MeasureDto otherAppBranchMeasure = db.measures().insertMeasure(otherAppBranch, otherAppBranchAnalysis, metric);
db.components().addApplicationProject(app, project);
db.components().addApplicationProject(otherApp, project);
db.components().addProjectBranchToApplicationBranch(dbClient.branchDao().selectByUuid(dbSession, appBranch.uuid()).get(), projectBranch);
db.components().addProjectBranchToApplicationBranch(dbClient.branchDao().selectByUuid(dbSession, otherAppBranch.uuid()).get(), projectBranch);
underTest.deleteProject(dbSession, app.uuid(), app.qualifier(), project.name(), project.getKey());
dbSession.commit();
assertThat(uuidsIn("components")).containsOnly(project.uuid(), otherApp.uuid(), otherAppBranch.uuid());
assertThat(uuidsIn("projects")).containsOnly(project.uuid(), otherApp.uuid());
assertThat(uuidsIn("snapshots")).containsOnly(otherAppAnalysis.getUuid(), otherAppBranchAnalysis.getUuid());
assertThat(uuidsIn("project_branches")).containsOnly(project.uuid(), otherApp.uuid(), otherAppBranch.uuid());
assertThat(uuidsIn("project_measures")).containsOnly(otherAppMeasure.getUuid(), otherAppBranchMeasure.getUuid());
assertThat(uuidsIn("app_projects", "application_uuid")).containsOnly(otherApp.uuid());
assertThat(uuidsIn("app_branch_project_branch", "application_branch_uuid")).containsOnly(otherAppBranch.uuid());
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class QGChangeEventListenersImplTest method broadcastOnIssueChange_calls_listener_for_each_component_uuid_with_at_least_one_QGChangeEvent.
@Test
public void broadcastOnIssueChange_calls_listener_for_each_component_uuid_with_at_least_one_QGChangeEvent() {
// branch has multiple issues
BranchDto component2 = newBranchDto(project1Uuid + "2");
DefaultIssue[] component2Issues = { newDefaultIssue(component2.getUuid()), newDefaultIssue(component2.getUuid()) };
QGChangeEvent component2QGChangeEvent = newQGChangeEvent(component2);
// branch 3 has multiple QGChangeEvent and only one issue
BranchDto component3 = newBranchDto(project1Uuid + "3");
DefaultIssue component3Issue = newDefaultIssue(component3.getUuid());
QGChangeEvent[] component3QGChangeEvents = { newQGChangeEvent(component3), newQGChangeEvent(component3) };
// branch 4 has multiple QGChangeEvent and multiples issues
BranchDto component4 = newBranchDto(project1Uuid + "4");
DefaultIssue[] component4Issues = { newDefaultIssue(component4.getUuid()), newDefaultIssue(component4.getUuid()) };
QGChangeEvent[] component4QGChangeEvents = { newQGChangeEvent(component4), newQGChangeEvent(component4) };
// branch 5 has no QGChangeEvent but one issue
BranchDto component5 = newBranchDto(project1Uuid + "5");
DefaultIssue component5Issue = newDefaultIssue(component5.getUuid());
List<DefaultIssue> issues = Stream.of(Stream.of(component1Issue), Arrays.stream(component2Issues), Stream.of(component3Issue), Arrays.stream(component4Issues), Stream.of(component5Issue)).flatMap(s -> s).collect(Collectors.toList());
List<DefaultIssue> changedIssues = randomizedList(issues);
List<QGChangeEvent> qgChangeEvents = Stream.of(Stream.of(component1QGChangeEvent), Stream.of(component2QGChangeEvent), Arrays.stream(component3QGChangeEvents), Arrays.stream(component4QGChangeEvents)).flatMap(s -> s).collect(Collectors.toList());
underTest.broadcastOnIssueChange(changedIssues, randomizedList(qgChangeEvents));
listeners.forEach(listener -> {
verifyListenerCalled(listener, component1QGChangeEvent, component1Issue);
verifyListenerCalled(listener, component2QGChangeEvent, component2Issues);
Arrays.stream(component3QGChangeEvents).forEach(component3QGChangeEvent -> verifyListenerCalled(listener, component3QGChangeEvent, component3Issue));
Arrays.stream(component4QGChangeEvents).forEach(component4QGChangeEvent -> verifyListenerCalled(listener, component4QGChangeEvent, component4Issues));
});
verifyNoMoreInteractions(listener1, listener2, listener3);
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class QGChangeEventListenersImplTest method newBranchDto.
private static BranchDto newBranchDto(String uuid) {
BranchDto branchDto = new BranchDto();
branchDto.setUuid(uuid);
return branchDto;
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class AsyncIssueIndexingImplTest method characteristics_are_defined.
@Test
public void characteristics_are_defined() {
BranchDto dto = new BranchDto().setBranchType(BRANCH).setKey("branch_1").setUuid("branch_uuid1").setProjectUuid("project_uuid1");
dbClient.branchDao().insert(dbTester.getSession(), dto);
dbTester.commit();
insertSnapshot("analysis_1", "project_uuid1", 1);
BranchDto dto2 = new BranchDto().setBranchType(PULL_REQUEST).setKey("pr_1").setUuid("pr_uuid_1").setProjectUuid("project_uuid2");
dbClient.branchDao().insert(dbTester.getSession(), dto2);
dbTester.commit();
insertSnapshot("analysis_2", "project_uuid2", 2);
underTest.triggerOnIndexCreation();
ArgumentCaptor<Collection<CeTaskSubmit>> captor = ArgumentCaptor.forClass(Collection.class);
verify(ceQueue, times(1)).massSubmit(captor.capture());
List<Collection<CeTaskSubmit>> captures = captor.getAllValues();
assertThat(captures).hasSize(1);
Collection<CeTaskSubmit> tasks = captures.get(0);
assertThat(tasks).hasSize(2);
assertThat(tasks).extracting(p -> p.getCharacteristics().get(BRANCH_TYPE_KEY), p -> p.getCharacteristics().get(CeTaskCharacteristicDto.BRANCH_KEY), p -> p.getCharacteristics().get(CeTaskCharacteristicDto.PULL_REQUEST)).containsExactlyInAnyOrder(tuple("BRANCH", "branch_1", null), tuple("PULL_REQUEST", null, "pr_1"));
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class AsyncIssueIndexingImplTest method trigger_with_lot_of_not_analyzed_project_should_not_raise_exception.
@Test
public void trigger_with_lot_of_not_analyzed_project_should_not_raise_exception() {
for (int i = 0; i < 100; i++) {
BranchDto dto = new BranchDto().setBranchType(BRANCH).setKey("branch_" + i).setUuid("branch_uuid" + i).setProjectUuid("project_uuid" + i);
dbClient.branchDao().insert(dbTester.getSession(), dto);
dbTester.commit();
insertSnapshot("analysis_" + i, "project_uuid" + i, 1);
}
for (int i = 100; i < 200; i++) {
BranchDto dto = new BranchDto().setBranchType(BRANCH).setKey("branch_" + i).setUuid("branch_uuid" + i).setProjectUuid("project_uuid" + i);
dbClient.branchDao().insert(dbTester.getSession(), dto);
dbTester.commit();
}
assertThatCode(underTest::triggerOnIndexCreation).doesNotThrowAnyException();
}
Aggregations