use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SearchActionTest method returns_issues_when_sinceLeakPeriod_is_true_and_is_application_for_branch_other_than_main.
@Test
public void returns_issues_when_sinceLeakPeriod_is_true_and_is_application_for_branch_other_than_main() {
long referenceDate = 800_996_999_332L;
system2.setNow(referenceDate + 10_000);
ProjectDto application = dbTester.components().insertPublicApplicationDto();
BranchDto applicationBranch = dbTester.components().insertProjectBranch(application, branchDto -> branchDto.setKey("application_branch_1"));
ProjectDto project = dbTester.components().insertPublicProjectDto();
BranchDto projectBranch = dbTester.components().insertProjectBranch(project, branchDto -> branchDto.setKey("project_1_branch_1"));
ProjectDto project2 = dbTester.components().insertPublicProjectDto();
BranchDto project2Branch = dbTester.components().insertProjectBranch(project2, branchDto -> branchDto.setKey("project_2_branch_1"));
dbTester.components().addApplicationProject(application, project);
dbTester.components().addApplicationProject(application, project2);
dbTester.components().addProjectBranchToApplicationBranch(applicationBranch, projectBranch, project2Branch);
ComponentDto applicationBranchComponentDto = dbClient.componentDao().selectByUuid(dbTester.getSession(), applicationBranch.getUuid()).get();
ComponentDto projectBranchComponentDto = dbClient.componentDao().selectByUuid(dbTester.getSession(), projectBranch.getUuid()).get();
ComponentDto project2BranchComponentDto = dbClient.componentDao().selectByUuid(dbTester.getSession(), project2Branch.getUuid()).get();
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(projectBranchComponentDto, applicationBranchComponentDto));
dbTester.components().insertComponent(ComponentTesting.newProjectCopy(project2BranchComponentDto, applicationBranchComponentDto));
indexViews();
userSessionRule.registerApplication(application, project, project2);
indexPermissions();
ComponentDto file = dbTester.components().insertComponent(newFileDto(projectBranchComponentDto));
dbTester.components().insertSnapshot(projectBranch, t -> t.setPeriodDate(referenceDate).setLast(true));
RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT);
IssueDto afterRef = dbTester.issues().insertHotspot(rule, projectBranchComponentDto, file, t -> t.setIssueCreationTime(referenceDate + 1000));
IssueDto atRef = dbTester.issues().insertHotspot(rule, projectBranchComponentDto, file, t -> t.setType(SECURITY_HOTSPOT).setIssueCreationTime(referenceDate));
IssueDto beforeRef = dbTester.issues().insertHotspot(rule, projectBranchComponentDto, file, t -> t.setIssueCreationTime(referenceDate - 1000));
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project2BranchComponentDto));
IssueDto project2Issue = dbTester.issues().insertHotspot(rule, project2BranchComponentDto, file2, t -> t.setIssueCreationTime(referenceDate - 1000));
indexIssues();
ComponentDto applicationComponentDto = dbClient.componentDao().selectByUuid(dbTester.getSession(), application.getUuid()).get();
SearchWsResponse responseAll = newRequest(applicationComponentDto, t -> t.setParam("branch", applicationBranch.getKey())).executeProtobuf(SearchWsResponse.class);
assertThat(responseAll.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(afterRef.getKey(), atRef.getKey(), beforeRef.getKey(), project2Issue.getKey());
SearchWsResponse responseOnLeak = newRequest(applicationComponentDto, t -> t.setParam("sinceLeakPeriod", "true").setParam("branch", applicationBranch.getKey())).executeProtobuf(SearchWsResponse.class);
assertThat(responseOnLeak.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(afterRef.getKey());
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class CreateEventActionTest method create_event_in_branch.
@Test
public void create_event_in_branch() {
ProjectDto project = db.components().insertPrivateProjectDto();
BranchDto branch = db.components().insertProjectBranch(project);
SnapshotDto analysis = db.components().insertSnapshot(branch);
when(system.now()).thenReturn(123_456_789L);
logInAsProjectAdministrator(project);
CreateEventResponse result = call(VERSION.name(), "5.6.3", analysis.getUuid());
List<EventDto> dbEvents = dbClient.eventDao().selectByComponentUuid(dbSession, analysis.getComponentUuid());
assertThat(dbEvents).hasSize(1);
EventDto dbEvent = dbEvents.get(0);
assertThat(dbEvent.getName()).isEqualTo("5.6.3");
assertThat(dbEvent.getCategory()).isEqualTo(VERSION.getLabel());
assertThat(dbEvent.getDescription()).isNull();
assertThat(dbEvent.getAnalysisUuid()).isEqualTo(analysis.getUuid());
assertThat(dbEvent.getComponentUuid()).isEqualTo(analysis.getComponentUuid());
assertThat(dbEvent.getUuid()).isEqualTo(result.getEvent().getKey());
assertThat(dbEvent.getCreatedAt()).isEqualTo(123_456_789L);
assertThat(dbEvent.getDate()).isEqualTo(analysis.getCreatedAt());
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class UpdateVisibilityActionTest method execute_has_no_effect_if_specified_project_already_has_specified_visibility.
@Test
public void execute_has_no_effect_if_specified_project_already_has_specified_visibility() {
ComponentDto project = randomPublicOrPrivateProject();
boolean initiallyPrivate = project.isPrivate();
BranchDto branchDto = ComponentTesting.newBranchDto(project);
dbClient.branchDao().insert(dbSession, branchDto);
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto).setPrivate(initiallyPrivate);
ComponentDto module = ComponentTesting.newModuleDto(project).setPrivate(initiallyPrivate);
ComponentDto dir = ComponentTesting.newDirectory(project, "path").setPrivate(!initiallyPrivate);
ComponentDto file = ComponentTesting.newFileDto(project).setPrivate(initiallyPrivate);
dbTester.components().insertComponents(branch, module, dir, file);
userSessionRule.addProjectPermission(UserRole.ADMIN, project);
request.setParam(PARAM_PROJECT, project.getDbKey()).setParam(PARAM_VISIBILITY, initiallyPrivate ? PRIVATE : PUBLIC).execute();
assertThat(isPrivateInDb(project)).isEqualTo(initiallyPrivate);
assertThat(isPrivateInDb(branch)).isEqualTo(initiallyPrivate);
assertThat(isPrivateInDb(module)).isEqualTo(initiallyPrivate);
assertThat(isPrivateInDb(dir)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(file)).isEqualTo(initiallyPrivate);
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class UpdateVisibilityActionTest method execute_changes_private_flag_of_specified_project_and_all_children_to_specified_new_visibility.
@Test
public void execute_changes_private_flag_of_specified_project_and_all_children_to_specified_new_visibility() {
ComponentDto project = randomPublicOrPrivateProject();
boolean initiallyPrivate = project.isPrivate();
BranchDto branchDto = ComponentTesting.newBranchDto(project);
dbClient.branchDao().insert(dbSession, branchDto);
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto);
ComponentDto module = ComponentTesting.newModuleDto(project);
ComponentDto dir = ComponentTesting.newDirectory(project, "path");
ComponentDto file = ComponentTesting.newFileDto(project);
dbTester.components().insertComponents(branch, module, dir, file);
userSessionRule.addProjectPermission(UserRole.ADMIN, project);
request.setParam(PARAM_PROJECT, project.getDbKey()).setParam(PARAM_VISIBILITY, initiallyPrivate ? PUBLIC : PRIVATE).execute();
assertThat(isPrivateInDb(project)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(branch)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(module)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(dir)).isEqualTo(!initiallyPrivate);
assertThat(isPrivateInDb(file)).isEqualTo(!initiallyPrivate);
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SetBaselineActionTest method fail_when_branch_does_not_belong_to_project.
@Test
public void fail_when_branch_does_not_belong_to_project() {
ComponentDto project = tester.insertPrivateProject();
SnapshotDto analysis = db.components().insertSnapshot(project);
logInAsProjectAdministrator(project);
ComponentDto otherProject = tester.insertPrivateProjectWithCustomBranch("main");
BranchDto branchOfOtherProject = branchDao.selectByUuid(dbSession, otherProject.uuid()).get();
assertThatThrownBy(() -> call(project.getKey(), branchOfOtherProject.getKey(), analysis.getUuid())).isInstanceOf(NotFoundException.class).hasMessage(String.format("Branch '%s' in project '%s' not found", branchOfOtherProject.getKey(), project.getKey()));
}
Aggregations