use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ComponentCleanerServiceTest method insertProjectData.
private DbData insertProjectData() {
ComponentDto componentDto = db.components().insertPublicProject();
ProjectDto project = dbClient.projectDao().selectByUuid(dbSession, componentDto.uuid()).get();
BranchDto branch = dbClient.branchDao().selectByUuid(dbSession, project.getUuid()).get();
RuleDefinitionDto rule = db.rules().insert();
IssueDto issue = db.issues().insert(rule, project, componentDto);
SnapshotDto analysis = db.components().insertSnapshot(componentDto);
mockResourceTypeAsValidProject();
return new DbData(project, branch, analysis, issue);
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class DismissAnalysisWarningActionTest method return_403_if_user_has_no_browse_permission_on_private_project.
@Test
public void return_403_if_user_has_no_browse_permission_on_private_project() {
ProjectDto project = db.components().insertPrivateProjectDto();
UserDto user = db.users().insertUser();
userSession.logIn(user);
TestRequest request = underTest.newRequest().setParam("component", project.getKee()).setParam("warning", "55c40b35-4145-4b78-bdf2-dfb242c25f15");
assertThrows("Insufficient privileges", ForbiddenException.class, request::execute);
}
use of org.sonar.db.project.ProjectDto 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.project.ProjectDto in project sonarqube by SonarSource.
the class DeleteActionTest method project_deletion_also_ensure_that_webhooks_on_this_project_if_they_exists_are_deleted.
@Test
public void project_deletion_also_ensure_that_webhooks_on_this_project_if_they_exists_are_deleted() {
ProjectDto project = componentDbTester.insertPrivateProjectDto();
webhookDbTester.insertWebhook(project);
webhookDbTester.insertWebhook(project);
webhookDbTester.insertWebhook(project);
webhookDbTester.insertWebhook(project);
userSessionRule.logIn().addProjectPermission(ADMIN, project);
DeleteAction underTest = new DeleteAction(new ComponentCleanerService(dbClient, mockResourceTypes, new TestProjectIndexers()), from(db), dbClient, userSessionRule, projectLifeCycleListeners);
new WsActionTester(underTest).newRequest().setParam(PARAM_PROJECT, project.getKey()).execute();
List<WebhookDto> webhookDtos = dbClient.webhookDao().selectByProject(dbSession, project);
assertThat(webhookDtos).isEmpty();
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class CreateEventActionTest method create_event_in_db.
@Test
public void create_event_in_db() {
ProjectDto project = db.components().insertPrivateProjectDto();
SnapshotDto analysis = db.components().insertSnapshot(project);
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());
}
Aggregations