use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method search_issue_on_component_only_from_branch.
@Test
public void search_issue_on_component_only_from_branch() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
assertThat(underTest.create(new SearchRequest().setComponents(singletonList(file.getKey())).setBranch(branch.getBranch()).setOnComponentOnly(true))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.componentUuids()), IssueQuery::isMainBranch).containsOnly(branch.uuid(), singletonList(file.uuid()), false);
}
use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method fail_if_components_and_components_uuid_params_are_set_at_the_same_time.
@Test
public void fail_if_components_and_components_uuid_params_are_set_at_the_same_time() {
SearchRequest request = new SearchRequest().setComponents(singletonList("foo")).setComponentUuids(singletonList("bar"));
assertThatThrownBy(() -> underTest.create(request)).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("At most one of the following parameters can be provided: componentKeys and componentUuids");
}
use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method set_created_after_from_created_since.
@Test
public void set_created_after_from_created_since() {
Date now = parseDateTime("2013-07-25T07:35:00+0100");
when(clock.instant()).thenReturn(now.toInstant());
when(clock.getZone()).thenReturn(ZoneOffset.UTC);
SearchRequest request = new SearchRequest().setCreatedInLast("1y2m3w4d");
assertThat(underTest.create(request).createdAfter().date()).isEqualTo(parseDateTime("2012-04-30T07:35:00+0100"));
assertThat(underTest.create(request).createdAfter().inclusive()).isTrue();
}
use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method application_search_project_issues_returns_empty_if_user_cannot_access_child_projects.
@Test
public void application_search_project_issues_returns_empty_if_user_cannot_access_child_projects() {
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto project2 = db.components().insertPrivateProject();
ComponentDto application = db.components().insertPublicApplication();
db.components().insertComponents(newProjectCopy("PC1", project1, application));
db.components().insertComponents(newProjectCopy("PC2", project2, application));
IssueQuery result = underTest.create(new SearchRequest().setComponentUuids(singletonList(application.uuid())));
assertThat(result.viewUuids()).containsOnly("<UNKNOWN>");
}
use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.
the class IssueQueryFactoryTest method application_search_project_issues_in_new_code.
@Test
public void application_search_project_issues_in_new_code() {
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())).setInNewCodePeriod(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());
}
Aggregations