Search in sources :

Example 41 with SearchRequest

use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.

the class IssueQueryFactoryTest method creation_date_support_zoneddatetime.

@Test
public void creation_date_support_zoneddatetime() {
    SearchRequest request = new SearchRequest().setCreatedAt("2013-04-16T09:08:24+0200");
    IssueQuery query = underTest.create(request);
    assertThat(query.createdAt()).isEqualTo(parseDateTime("2013-04-16T09:08:24+0200"));
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test)

Example 42 with SearchRequest

use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.

the class IssueQueryFactoryTest method search_by_application_key_and_branch.

@Test
public void search_by_application_key_and_branch() {
    ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setDbKey("app"));
    ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1"));
    ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2"));
    ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("prj1"));
    ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
    ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1));
    ComponentDto project1Branch2 = db.components().insertProjectBranch(project1);
    ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("prj2"));
    db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1));
    db.components().insertComponents(newProjectCopy(project2, applicationBranch1));
    db.components().insertComponents(newProjectCopy(project1Branch2, applicationBranch2));
    // Search on applicationBranch1
    assertThat(underTest.create(new SearchRequest().setComponents(singletonList(applicationBranch1.getKey())).setBranch(applicationBranch1.getBranch()))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch).containsOnly(applicationBranch1.uuid(), Collections.emptyList(), false);
    // Search on project1Branch1
    assertThat(underTest.create(new SearchRequest().setComponents(singletonList(applicationBranch1.getKey())).setProjects(singletonList(project1.getKey())).setBranch(applicationBranch1.getBranch()))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch).containsOnly(applicationBranch1.uuid(), singletonList(project1.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 43 with SearchRequest

use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.

the class IssueQueryFactoryTest method query_without_any_parameter.

@Test
public void query_without_any_parameter() {
    SearchRequest request = new SearchRequest();
    IssueQuery query = underTest.create(request);
    assertThat(query.componentUuids()).isEmpty();
    assertThat(query.projectUuids()).isEmpty();
    assertThat(query.moduleUuids()).isEmpty();
    assertThat(query.moduleRootUuids()).isEmpty();
    assertThat(query.directories()).isEmpty();
    assertThat(query.files()).isEmpty();
    assertThat(query.viewUuids()).isEmpty();
    assertThat(query.branchUuid()).isNull();
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test)

Example 44 with SearchRequest

use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.

the class IssueQueryFactoryTest method use_provided_timezone_to_parse_createdBefore.

@Test
public void use_provided_timezone_to_parse_createdBefore() {
    SearchRequest request = new SearchRequest().setCreatedBefore("2020-04-16").setTimeZone("Europe/Moscow");
    IssueQuery query = underTest.create(request);
    assertThat(query.createdBefore()).isEqualTo(parseDateTime("2020-04-17T00:00:00+0300"));
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test)

Example 45 with SearchRequest

use of org.sonar.server.issue.SearchRequest in project sonarqube by SonarSource.

the class ComponentTagsActionTest method should_return_tag_list.

@Test
public void should_return_tag_list() {
    Map<String, Long> tags = ImmutableMap.<String, Long>builder().put("convention", 2771L).put("brain-overload", 998L).put("cwe", 89L).put("bug", 32L).put("cert", 2L).build();
    ArgumentCaptor<SearchRequest> captor = ArgumentCaptor.forClass(SearchRequest.class);
    when(issueQueryFactory.create(captor.capture())).thenReturn(mock(IssueQuery.class));
    when(service.countTags(any(IssueQuery.class), eq(5))).thenReturn(tags);
    TestResponse response = tester.newRequest().setParam("componentUuid", "polop").setParam("ps", "5").execute();
    assertJson(response.getInput()).isSimilarTo(getClass().getResource("ComponentTagsActionTest/component-tags.json"));
    assertThat(captor.getValue().getTypes()).containsExactlyInAnyOrder(ISSUE_RULE_TYPES);
    assertThat(captor.getValue().getComponentUuids()).containsOnly("polop");
    assertThat(captor.getValue().getResolved()).isFalse();
    assertThat(captor.getValue().getCreatedAfter()).isNull();
    verify(issueIndexSyncProgressChecker).checkIfComponentNeedIssueSync(any(), eq("KEY_polop"));
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) TestResponse(org.sonar.server.ws.TestResponse) IssueQuery(org.sonar.server.issue.index.IssueQuery) 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