Search in sources :

Example 16 with SearchRequest

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

the class IssueQueryFactoryTest method add_unknown_when_no_component_found.

@Test
public void add_unknown_when_no_component_found() {
    SearchRequest request = new SearchRequest().setComponents(asList("does_not_exist"));
    IssueQuery query = underTest.create(request);
    assertThat(query.componentUuids()).containsOnly("<UNKNOWN>");
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test)

Example 17 with SearchRequest

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

the class IssueQueryFactoryTest method new_code_period_does_not_rely_on_date_for_reference_branch.

@Test
public void new_code_period_does_not_rely_on_date_for_reference_branch() {
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    SnapshotDto analysis = db.components().insertSnapshot(project, s -> s.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
    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.newCodeOnReference()).isTrue();
    assertThat(query.createdAfter()).isNull();
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 18 with SearchRequest

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

the class IssueQueryFactoryTest method leak_period_does_not_rely_on_date_for_reference_branch.

@Test
public void leak_period_does_not_rely_on_date_for_reference_branch() {
    long leakPeriodStart = 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.setPeriodMode(REFERENCE_BRANCH.name()).setPeriodParam("master"));
    SearchRequest request = new SearchRequest().setComponentUuids(Collections.singletonList(file.uuid())).setOnComponentOnly(true).setSinceLeakPeriod(true);
    IssueQuery query = underTest.create(request);
    assertThat(query.componentUuids()).containsOnly(file.uuid());
    assertThat(query.newCodeOnReference()).isTrue();
    assertThat(query.createdAfter()).isNull();
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Date(java.util.Date) Test(org.junit.Test)

Example 19 with SearchRequest

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

the class ComponentTagsAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String componentUuid = request.mandatoryParam(PARAM_COMPONENT_UUID);
    checkIfAnyComponentsNeedIssueSync(componentUuid);
    SearchRequest searchRequest = new SearchRequest().setComponentUuids(singletonList(componentUuid)).setTypes(ISSUE_TYPE_NAMES).setResolved(false).setCreatedAfter(request.param(PARAM_CREATED_AFTER));
    IssueQuery query = queryService.create(searchRequest);
    int pageSize = request.mandatoryParamAsInt(PAGE_SIZE);
    try (JsonWriter json = response.newJsonWriter()) {
        json.beginObject().name("tags").beginArray();
        for (Map.Entry<String, Long> tag : issueIndex.countTags(query, pageSize).entrySet()) {
            json.beginObject().prop("key", tag.getKey()).prop("value", tag.getValue()).endObject();
        }
        json.endArray().endObject();
    }
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) IssueQuery(org.sonar.server.issue.index.IssueQuery) JsonWriter(org.sonar.api.utils.text.JsonWriter) Map(java.util.Map)

Example 20 with SearchRequest

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

the class ComponentTagsActionTest method should_return_tag_list_with_created_after.

@Test
public void should_return_tag_list_with_created_after() {
    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);
    String componentUuid = "polop";
    String createdAfter = "2011-04-25";
    TestResponse response = tester.newRequest().setParam("componentUuid", componentUuid).setParam("createdAfter", createdAfter).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(componentUuid);
    assertThat(captor.getValue().getResolved()).isFalse();
    assertThat(captor.getValue().getCreatedAfter()).isEqualTo(createdAfter);
    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