Search in sources :

Example 31 with SearchRequest

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

the class IssueQueryFactoryTest method use_provided_timezone_to_parse_createdAfter.

@Test
public void use_provided_timezone_to_parse_createdAfter() {
    SearchRequest request = new SearchRequest().setCreatedAfter("2020-04-16").setTimeZone("Europe/Volgograd");
    IssueQuery query = underTest.create(request);
    assertThat(query.createdAfter().date()).isEqualTo(parseDateTime("2020-04-16T00:00:00+0400"));
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) Test(org.junit.Test)

Example 32 with SearchRequest

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

the class IssueQueryFactoryTest method create_from_parameters.

@Test
public void create_from_parameters() {
    String ruleAdHocName = "New Name";
    UserDto user = db.users().insertUser(u -> u.setLogin("joanna"));
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto module = db.components().insertComponent(newModuleDto(project));
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    RuleDefinitionDto rule1 = ruleDbTester.insert();
    RuleDefinitionDto rule2 = ruleDbTester.insert();
    ruleDbTester.insertOrUpdateMetadata(rule1, m -> m.setAdHocName(ruleAdHocName));
    ruleDbTester.insertOrUpdateMetadata(rule2, m -> m.setAdHocName(ruleAdHocName));
    newRule(RuleKey.of("findbugs", "NullReference"));
    SearchRequest request = new SearchRequest().setIssues(asList("anIssueKey")).setSeverities(asList("MAJOR", "MINOR")).setStatuses(asList("CLOSED")).setResolutions(asList("FALSE-POSITIVE")).setResolved(true).setProjects(asList(project.getDbKey())).setDirectories(asList("aDirPath")).setFiles(asList(file.uuid())).setAssigneesUuid(asList(user.getUuid())).setScopes(asList("MAIN", "TEST")).setLanguages(asList("xoo")).setTags(asList("tag1", "tag2")).setAssigned(true).setCreatedAfter("2013-04-16T09:08:24+0200").setCreatedBefore("2013-04-17T09:08:24+0200").setRules(asList(rule1.getKey().toString(), rule2.getKey().toString())).setSort("CREATION_DATE").setAsc(true);
    IssueQuery query = underTest.create(request);
    assertThat(query.issueKeys()).containsOnly("anIssueKey");
    assertThat(query.severities()).containsOnly("MAJOR", "MINOR");
    assertThat(query.statuses()).containsOnly("CLOSED");
    assertThat(query.resolutions()).containsOnly("FALSE-POSITIVE");
    assertThat(query.resolved()).isTrue();
    assertThat(query.projectUuids()).containsOnly(project.uuid());
    assertThat(query.files()).containsOnly(file.uuid());
    assertThat(query.assignees()).containsOnly(user.getUuid());
    assertThat(query.scopes()).containsOnly("TEST", "MAIN");
    assertThat(query.languages()).containsOnly("xoo");
    assertThat(query.tags()).containsOnly("tag1", "tag2");
    assertThat(query.onComponentOnly()).isFalse();
    assertThat(query.assigned()).isTrue();
    assertThat(query.rules()).hasSize(2);
    assertThat(query.ruleUuids()).hasSize(2);
    assertThat(query.directories()).containsOnly("aDirPath");
    assertThat(query.createdAfter().date()).isEqualTo(parseDateTime("2013-04-16T09:08:24+0200"));
    assertThat(query.createdAfter().inclusive()).isTrue();
    assertThat(query.createdBefore()).isEqualTo(parseDateTime("2013-04-17T09:08:24+0200"));
    assertThat(query.sort()).isEqualTo(IssueQuery.SORT_BY_CREATION_DATE);
    assertThat(query.asc()).isTrue();
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 33 with SearchRequest

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

the class IssueQueryFactoryTest method return_empty_results_if_not_allowed_to_search_for_subview.

@Test
public void return_empty_results_if_not_allowed_to_search_for_subview() {
    ComponentDto view = db.components().insertPrivatePortfolio();
    ComponentDto subView = db.components().insertComponent(newSubPortfolio(view));
    SearchRequest request = new SearchRequest().setComponentUuids(singletonList(subView.uuid()));
    IssueQuery query = underTest.create(request);
    assertThat(query.viewUuids()).containsOnly("<UNKNOWN>");
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 34 with SearchRequest

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

the class IssueQueryFactoryTest method search_file_issue_from_branch.

@Test
public void search_file_issue_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()))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.componentUuids()), IssueQuery::isMainBranch).containsOnly(branch.uuid(), singletonList(file.uuid()), false);
    assertThat(underTest.create(new SearchRequest().setComponents(singletonList(branch.getKey())).setFiles(singletonList(file.path())).setBranch(branch.getBranch()))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.files()), IssueQuery::isMainBranch).containsOnly(branch.uuid(), singletonList(file.path()), false);
    assertThat(underTest.create(new SearchRequest().setProjects(singletonList(branch.getKey())).setFiles(singletonList(file.path())).setBranch(branch.getBranch()))).extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.files()), IssueQuery::isMainBranch).containsOnly(branch.uuid(), singletonList(file.path()), 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 35 with SearchRequest

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

the class IssueQueryFactoryTest method param_componentUuids_enables_search_by_file.

@Test
public void param_componentUuids_enables_search_by_file() {
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    SearchRequest request = new SearchRequest().setComponentUuids(asList(file.uuid()));
    IssueQuery query = underTest.create(request);
    assertThat(query.componentUuids()).containsExactly(file.uuid());
}
Also used : SearchRequest(org.sonar.server.issue.SearchRequest) ComponentDto(org.sonar.db.component.ComponentDto) 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