use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method application_search_project_issues_on_leak.
@Test
public void application_search_project_issues_on_leak() {
Date now = new Date();
when(clock.millis()).thenReturn(now.getTime());
ComponentDto project1 = db.components().insertPublicProject();
SnapshotDto analysis1 = db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime()));
ComponentDto project2 = db.components().insertPublicProject();
db.components().insertSnapshot(project2, s -> s.setPeriodDate(null));
ComponentDto project3 = db.components().insertPublicProject();
ComponentDto project4 = db.components().insertPublicProject();
SnapshotDto analysis2 = db.components().insertSnapshot(project4, s -> s.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
ComponentDto application = db.components().insertPublicApplication();
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);
IssueQuery result = underTest.create(new SearchRequest().setComponentUuids(singletonList(application.uuid())).setSinceLeakPeriod(true));
assertThat(result.createdAfterByProjectUuids()).hasSize(1);
assertThat(result.createdAfterByProjectUuids().entrySet()).extracting(Map.Entry::getKey, e -> e.getValue().date(), e -> e.getValue().inclusive()).containsOnly(tuple(project1.uuid(), new Date(analysis1.getPeriodDate()), false));
assertThat(result.newCodeOnReferenceByProjectUuids()).hasSize(1);
assertThat(result.newCodeOnReferenceByProjectUuids()).containsOnly(project4.uuid());
assertThat(result.viewUuids()).containsExactlyInAnyOrder(application.uuid());
}
use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method fail_if_in_new_code_period_and_created_after_set_at_the_same_time.
@Test
public void fail_if_in_new_code_period_and_created_after_set_at_the_same_time() {
SearchRequest searchRequest = new SearchRequest().setInNewCodePeriod(true).setCreatedAfter("2013-07-25T07:35:00+0100");
assertThatThrownBy(() -> underTest.create(searchRequest)).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Parameters 'createdAfter' and 'inNewCodePeriod' or 'sinceLeakPeriod' cannot be set simultaneously");
}
use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method in_new_code_period_start_date_is_exclusive.
@Test
public void in_new_code_period_start_date_is_exclusive() {
long newCodePeriodStart = addDays(new Date(), -14).getTime();
ComponentDto project = db.components().insertPublicProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setPeriodDate(newCodePeriodStart));
SearchRequest request = new SearchRequest().setComponentUuids(Collections.singletonList(file.uuid())).setOnComponentOnly(true).setInNewCodePeriod(true);
IssueQuery query = underTest.create(request);
assertThat(query.componentUuids()).containsOnly(file.uuid());
assertThat(query.createdAfter().date()).isEqualTo(new Date(newCodePeriodStart));
assertThat(query.createdAfter().inclusive()).isFalse();
assertThat(query.newCodeOnReference()).isNull();
}
use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method onComponentOnly_restricts_search_to_specified_componentKeys.
@Test
public void onComponentOnly_restricts_search_to_specified_componentKeys() {
ComponentDto project = db.components().insertPrivateProject();
SearchRequest request = new SearchRequest().setComponents(asList(project.getDbKey())).setOnComponentOnly(true);
IssueQuery query = underTest.create(request);
assertThat(query.projectUuids()).isEmpty();
assertThat(query.componentUuids()).containsExactly(project.uuid());
assertThat(query.onComponentOnly()).isTrue();
}
use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method search_issue_from_branch.
@Test
public void search_issue_from_branch() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project);
assertThat(underTest.create(new SearchRequest().setProjects(singletonList(branch.getKey())).setBranch(branch.getBranch()))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch).containsOnly(branch.uuid(), singletonList(project.uuid()), false);
assertThat(underTest.create(new SearchRequest().setComponents(singletonList(branch.getKey())).setBranch(branch.getBranch()))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch).containsOnly(branch.uuid(), singletonList(project.uuid()), false);
}
Aggregations