Search in sources :

Example 26 with SearchRequest

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);
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) Date(java.util.Date) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RuleDbTester(org.sonar.db.rule.RuleDbTester) RuleTesting.newRule(org.sonar.db.rule.RuleTesting.newRule) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ZoneOffset(java.time.ZoneOffset) DateUtils.addDays(org.sonar.api.utils.DateUtils.addDays) ComponentTesting.newProjectCopy(org.sonar.db.component.ComponentTesting.newProjectCopy) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) APP(org.sonar.api.resources.Qualifiers.APP) REFERENCE_BRANCH(org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ZoneId(java.time.ZoneId) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTesting.newSubPortfolio(org.sonar.db.component.ComponentTesting.newSubPortfolio) Rule(org.junit.Rule) Qualifiers(org.sonar.api.resources.Qualifiers) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) RuleKey(org.sonar.api.rule.RuleKey) Clock(java.time.Clock) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) Mockito.mock(org.mockito.Mockito.mock) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) SearchRequest(org.sonar.server.issue.SearchRequest) ComponentDto(org.sonar.db.component.ComponentDto) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 27 with SearchRequest

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");
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test)

Example 28 with SearchRequest

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();
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) Date(java.util.Date) Test(org.junit.Test)

Example 29 with SearchRequest

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>");
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 30 with SearchRequest

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());
}
Also used : RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) Date(java.util.Date) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RuleDbTester(org.sonar.db.rule.RuleDbTester) RuleTesting.newRule(org.sonar.db.rule.RuleTesting.newRule) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) ZoneOffset(java.time.ZoneOffset) DateUtils.addDays(org.sonar.api.utils.DateUtils.addDays) ComponentTesting.newProjectCopy(org.sonar.db.component.ComponentTesting.newProjectCopy) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) APP(org.sonar.api.resources.Qualifiers.APP) REFERENCE_BRANCH(org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ZoneId(java.time.ZoneId) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTesting.newSubPortfolio(org.sonar.db.component.ComponentTesting.newSubPortfolio) Rule(org.junit.Rule) Qualifiers(org.sonar.api.resources.Qualifiers) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) RuleKey(org.sonar.api.rule.RuleKey) Clock(java.time.Clock) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) Mockito.mock(org.mockito.Mockito.mock) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) SearchRequest(org.sonar.server.issue.SearchRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Map(java.util.Map) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SearchRequest (org.sonar.server.issue.SearchRequest)45 Test (org.junit.Test)43 ComponentDto (org.sonar.db.component.ComponentDto)26 Date (java.util.Date)11 SnapshotDto (org.sonar.db.component.SnapshotDto)11 Map (java.util.Map)8 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)8 UserDto (org.sonar.db.user.UserDto)8 Clock (java.time.Clock)7 ZoneId (java.time.ZoneId)7 ZoneOffset (java.time.ZoneOffset)7 ArrayList (java.util.ArrayList)7 Arrays.asList (java.util.Arrays.asList)7 Collections (java.util.Collections)7 Collections.singletonList (java.util.Collections.singletonList)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)7 Assertions.tuple (org.assertj.core.api.Assertions.tuple)7 Assert.fail (org.junit.Assert.fail)7 Rule (org.junit.Rule)7