From: Teryk Bellahsene Date: Thu, 19 May 2016 12:41:30 +0000 (+0200) Subject: SONAR-7637 WS api/issues/search 'createdAt'facet with one bar when one day X-Git-Tag: 5.6-RC1~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc9b9edb7c887a74c47c59d615c48ae7024ab392;p=sonarqube.git SONAR-7637 WS api/issues/search 'createdAt'facet with one bar when one day --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java index e4308332dc1..6b77a9ce32c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -475,6 +475,7 @@ public class IssueIndex extends BaseIndex { bucketSize = DateHistogram.Interval.MONTH; } + // from GMT to server TZ int offsetInSeconds = -system.getDefaultTimeZone().getRawOffset() / 1_000; AggregationBuilder dateHistogram = AggregationBuilders.dateHistogram(CREATED_AT) @@ -484,7 +485,8 @@ public class IssueIndex extends BaseIndex { .format(DateUtils.DATETIME_FORMAT) .timeZone(TimeZone.getTimeZone("GMT").getID()) .offset(offsetInSeconds + "s") - .extendedBounds(startTime, endTime); + // ES dateHistogram bounds are inclusive while createdBefore parameter is exclusive + .extendedBounds(startTime, endTime - 1_000L); dateHistogram = addEffortAggregationIfNeeded(query, dateHistogram); return dateHistogram; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java index b684a2ec4a6..c27afc2ffe5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java @@ -71,7 +71,7 @@ public class IssueIndexTest { @Rule public UserSessionRule userSessionRule = UserSessionRule.standalone(); - IssueIndex index; + IssueIndex underTest; IssueIndexer issueIndexer; IssueAuthorizationIndexer issueAuthorizationIndexer; @@ -87,7 +87,7 @@ public class IssueIndexTest { when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("GMT-1:00")); when(system.now()).thenReturn(System.currentTimeMillis()); - index = new IssueIndex(tester.client(), system, userSessionRule); + underTest = new IssueIndex(tester.client(), system, userSessionRule); } @Test @@ -98,7 +98,7 @@ public class IssueIndexTest { .setEffort(100L); indexIssues(issue); - Issue loaded = index.getByKey(issue.key()); + Issue loaded = underTest.getByKey(issue.key()); assertThat(loaded).isNotNull(); assertThat(loaded.key()).isEqualTo("ISSUE1"); @@ -112,7 +112,7 @@ public class IssueIndexTest { IssueDoc issue = IssueTesting.newDoc("ISSUE1", file).setAttributes((KeyValueFormat.format(ImmutableMap.of("jira-issue-key", "SONAR-1234")))); indexIssues(issue); - Issue result = index.getByKey(issue.key()); + Issue result = underTest.getByKey(issue.key()); assertThat(result.attribute("jira-issue-key")).isEqualTo("SONAR-1234"); } @@ -123,7 +123,7 @@ public class IssueIndexTest { IssueDoc issue = IssueTesting.newDoc("ISSUE1", file); indexIssues(issue); - Issue result = index.getByKey(issue.key()); + Issue result = underTest.getByKey(issue.key()); result.comments(); } @@ -134,13 +134,13 @@ public class IssueIndexTest { IssueDoc issue = IssueTesting.newDoc("ISSUE1", file); indexIssues(issue); - Issue result = index.getByKey(issue.key()); + Issue result = underTest.getByKey(issue.key()); result.isNew(); } @Test(expected = NotFoundException.class) public void fail_to_get_unknown_key() { - index.getByKey("unknown"); + underTest.getByKey("unknown"); } @Test @@ -151,9 +151,9 @@ public class IssueIndexTest { IssueTesting.newDoc("1", ComponentTesting.newFileDto(project)), IssueTesting.newDoc("2", ComponentTesting.newFileDto(project))); - assertThat(index.search(IssueQuery.builder(userSessionRule).issueKeys(newArrayList("1", "2")).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).issueKeys(newArrayList("1")).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).issueKeys(newArrayList("3", "4")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).issueKeys(newArrayList("1", "2")).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).issueKeys(newArrayList("1")).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).issueKeys(newArrayList("3", "4")).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -170,8 +170,8 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE5", subModule), IssueTesting.newDoc("ISSUE6", ComponentTesting.newFileDto(subModule))); - assertThat(index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()).hasSize(6); - assertThat(index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()).hasSize(6); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -184,7 +184,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", ComponentTesting.newFileDto(project)), IssueTesting.newDoc("ISSUE3", ComponentTesting.newFileDto(project2))); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("projectUuids"))); + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("projectUuids"))); assertThat(result.getFacets().getNames()).containsOnly("projectUuids"); assertThat(result.getFacets().get("projectUuids")).containsOnly(entry("ABCD", 2L), entry("EFGH", 1L)); } @@ -202,20 +202,20 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file)); assertThat( - index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(file.uuid())).build(), new SearchOptions()).getDocs()) + underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(file.uuid())).build(), new SearchOptions()).getDocs()) .isEmpty(); assertThat( - index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(module.uuid())).build(), new SearchOptions()).getDocs()) + underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(module.uuid())).build(), new SearchOptions()).getDocs()) .hasSize(1); assertThat( - index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(subModule.uuid())).build(), new SearchOptions()) + underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(subModule.uuid())).build(), new SearchOptions()) .getDocs()) .hasSize(2); assertThat( - index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()) + underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()) .isEmpty(); assertThat( - index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()) + underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()) .isEmpty(); } @@ -238,19 +238,19 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE5", subModule), IssueTesting.newDoc("ISSUE6", file3)); - assertThat(index.search(IssueQuery.builder(userSessionRule).fileUuids(newArrayList(file1.uuid(), file2.uuid(), file3.uuid())).build(), new SearchOptions()) + assertThat(underTest.search(IssueQuery.builder(userSessionRule).fileUuids(newArrayList(file1.uuid(), file2.uuid(), file3.uuid())).build(), new SearchOptions()) .getDocs()).hasSize(3); - assertThat(index.search(IssueQuery.builder(userSessionRule).fileUuids(newArrayList(file1.uuid())).build(), new SearchOptions()) + assertThat(underTest.search(IssueQuery.builder(userSessionRule).fileUuids(newArrayList(file1.uuid())).build(), new SearchOptions()) .getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).moduleRootUuids(newArrayList(subModule.uuid())).build(), new SearchOptions()) + assertThat(underTest.search(IssueQuery.builder(userSessionRule).moduleRootUuids(newArrayList(subModule.uuid())).build(), new SearchOptions()) .getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).moduleRootUuids(newArrayList(module.uuid())).build(), new SearchOptions()) + assertThat(underTest.search(IssueQuery.builder(userSessionRule).moduleRootUuids(newArrayList(module.uuid())).build(), new SearchOptions()) .getDocs()).hasSize(4); - assertThat(index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()) + assertThat(underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()) .getDocs()).hasSize(6); - assertThat(index.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view)).build(), new SearchOptions()) + assertThat(underTest.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view)).build(), new SearchOptions()) .getDocs()).hasSize(6); - assertThat(index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList("unknown")).build(), new SearchOptions()) + assertThat(underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList("unknown")).build(), new SearchOptions()) .getDocs()).isEmpty(); } @@ -273,15 +273,15 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE5", subModule), IssueTesting.newDoc("ISSUE6", file3)); - assertThat(index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); - assertThat(index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()).hasSize(6); - assertThat(index.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view)).build(), new SearchOptions()).getDocs()).hasSize(6); - assertThat(index.search(IssueQuery.builder(userSessionRule).moduleUuids(newArrayList(module.uuid())).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).moduleUuids(newArrayList(subModule.uuid())).build(), new SearchOptions()).getDocs()).hasSize(2); // XXX + assertThat(underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()).hasSize(6); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view)).build(), new SearchOptions()).getDocs()).hasSize(6); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).moduleUuids(newArrayList(module.uuid())).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).moduleUuids(newArrayList(subModule.uuid())).build(), new SearchOptions()).getDocs()).hasSize(2); // XXX // Misleading // ! - assertThat(index.search(IssueQuery.builder(userSessionRule).fileUuids(newArrayList(file1.uuid())).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).fileUuids(newArrayList(file1.uuid(), file2.uuid(), file3.uuid())).build(), new SearchOptions()).getDocs()) + assertThat(underTest.search(IssueQuery.builder(userSessionRule).fileUuids(newArrayList(file1.uuid())).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).fileUuids(newArrayList(file1.uuid(), file2.uuid(), file3.uuid())).build(), new SearchOptions()).getDocs()) .hasSize(3); } @@ -299,7 +299,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE4", file2), IssueTesting.newDoc("ISSUE5", file3)); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("fileUuids"))); + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("fileUuids"))); assertThat(result.getFacets().getNames()).containsOnly("fileUuids"); assertThat(result.getFacets().get("fileUuids")) .containsOnly(entry("A", 1L), entry("ABCD", 1L), entry("BCDE", 2L), entry("CDEF", 1L)); @@ -315,9 +315,9 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE1", file1).setDirectoryPath("/src/main/xoo"), IssueTesting.newDoc("ISSUE2", file2).setDirectoryPath("/")); - assertThat(index.search(IssueQuery.builder(userSessionRule).directories(newArrayList("/src/main/xoo")).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).directories(newArrayList("/")).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).directories(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).directories(newArrayList("/src/main/xoo")).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).directories(newArrayList("/")).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).directories(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -330,7 +330,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE1", file1).setDirectoryPath("/src/main/xoo"), IssueTesting.newDoc("ISSUE2", file2).setDirectoryPath("/")); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("directories"))); + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("directories"))); assertThat(result.getFacets().getNames()).containsOnly("directories"); assertThat(result.getFacets().get("directories")).containsOnly(entry("/src/main/xoo", 1L), entry("/", 1L)); } @@ -355,10 +355,10 @@ public class IssueIndexTest { String view2 = "CDEF"; indexView(view2, newArrayList(project2.uuid())); - assertThat(index.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view1)).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view2)).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view1, view2)).build(), new SearchOptions()).getDocs()).hasSize(3); - assertThat(index.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view1)).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view2)).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList(view1, view2)).build(), new SearchOptions()).getDocs()).hasSize(3); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).viewUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -370,9 +370,9 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE1", file).setSeverity(Severity.INFO), IssueTesting.newDoc("ISSUE2", file).setSeverity(Severity.MAJOR)); - assertThat(index.search(IssueQuery.builder(userSessionRule).severities(newArrayList(Severity.INFO, Severity.MAJOR)).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).severities(newArrayList(Severity.INFO)).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).severities(newArrayList(Severity.BLOCKER)).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).severities(newArrayList(Severity.INFO, Severity.MAJOR)).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).severities(newArrayList(Severity.INFO)).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).severities(newArrayList(Severity.BLOCKER)).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -385,7 +385,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setSeverity(Severity.INFO), IssueTesting.newDoc("ISSUE3", file).setSeverity(Severity.MAJOR)); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("severities"))); + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("severities"))); assertThat(result.getFacets().getNames()).containsOnly("severities"); assertThat(result.getFacets().get("severities")).containsOnly(entry("INFO", 2L), entry("MAJOR", 1L)); } @@ -399,9 +399,9 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_CLOSED), IssueTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_OPEN)); - assertThat(index.search(IssueQuery.builder(userSessionRule).statuses(newArrayList(Issue.STATUS_CLOSED, Issue.STATUS_OPEN)).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).statuses(newArrayList(Issue.STATUS_CLOSED)).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).statuses(newArrayList(Issue.STATUS_CONFIRMED)).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).statuses(newArrayList(Issue.STATUS_CLOSED, Issue.STATUS_OPEN)).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).statuses(newArrayList(Issue.STATUS_CLOSED)).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).statuses(newArrayList(Issue.STATUS_CONFIRMED)).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -414,7 +414,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_CLOSED), IssueTesting.newDoc("ISSUE3", file).setStatus(Issue.STATUS_OPEN)); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("statuses"))); + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("statuses"))); assertThat(result.getFacets().getNames()).containsOnly("statuses"); assertThat(result.getFacets().get("statuses")).containsOnly(entry("CLOSED", 2L), entry("OPEN", 1L)); } @@ -429,10 +429,10 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setResolution(Issue.RESOLUTION_FIXED)); assertThat( - index.search(IssueQuery.builder(userSessionRule).resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE, Issue.RESOLUTION_FIXED)).build(), new SearchOptions()).getDocs()) + underTest.search(IssueQuery.builder(userSessionRule).resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE, Issue.RESOLUTION_FIXED)).build(), new SearchOptions()).getDocs()) .hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE)).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).resolutions(newArrayList(Issue.RESOLUTION_REMOVED)).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE)).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).resolutions(newArrayList(Issue.RESOLUTION_REMOVED)).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -445,7 +445,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE), IssueTesting.newDoc("ISSUE3", file).setResolution(Issue.RESOLUTION_FIXED)); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("resolutions"))); + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("resolutions"))); assertThat(result.getFacets().getNames()).containsOnly("resolutions"); assertThat(result.getFacets().get("resolutions")).containsOnly(entry("FALSE-POSITIVE", 2L), entry("FIXED", 1L)); } @@ -460,9 +460,9 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_OPEN).setResolution(null), IssueTesting.newDoc("ISSUE3", file).setStatus(Issue.STATUS_OPEN).setResolution(null)); - assertThat(index.search(IssueQuery.builder(userSessionRule).resolved(true).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).resolved(false).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).resolved(null).build(), new SearchOptions()).getDocs()).hasSize(3); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).resolved(true).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).resolved(false).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).resolved(null).build(), new SearchOptions()).getDocs()).hasSize(3); } @Test @@ -473,8 +473,8 @@ public class IssueIndexTest { indexIssues(IssueTesting.newDoc("ISSUE1", file).setRuleKey(ruleKey.toString())); - assertThat(index.search(IssueQuery.builder(userSessionRule).rules(newArrayList(ruleKey)).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).rules(newArrayList(RuleKey.of("rule", "without issue"))).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).rules(newArrayList(ruleKey)).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).rules(newArrayList(RuleKey.of("rule", "without issue"))).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -485,9 +485,9 @@ public class IssueIndexTest { indexIssues(IssueTesting.newDoc("ISSUE1", file).setRuleKey(ruleKey.toString()).setLanguage("xoo")); - assertThat(index.search(IssueQuery.builder(userSessionRule).languages(newArrayList("xoo")).build(), + assertThat(underTest.search(IssueQuery.builder(userSessionRule).languages(newArrayList("xoo")).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).languages(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).languages(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -498,7 +498,7 @@ public class IssueIndexTest { indexIssues(IssueTesting.newDoc("ISSUE1", file).setRuleKey(ruleKey.toString()).setLanguage("xoo")); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("languages"))); + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("languages"))); assertThat(result.getFacets().getNames()).containsOnly("languages"); assertThat(result.getFacets().get("languages")).containsOnly(entry("xoo", 1L)); } @@ -513,9 +513,9 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setAssignee("simon"), IssueTesting.newDoc("ISSUE3", file).setAssignee(null)); - assertThat(index.search(IssueQuery.builder(userSessionRule).assignees(newArrayList("steph")).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).assignees(newArrayList("steph", "simon")).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).assignees(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).assignees(newArrayList("steph")).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).assignees(newArrayList("steph", "simon")).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).assignees(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -529,7 +529,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE3", file).setAssignee("simon"), IssueTesting.newDoc("ISSUE4", file).setAssignee(null)); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("assignees"))); + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("assignees"))); assertThat(result.getFacets().getNames()).containsOnly("assignees"); assertThat(result.getFacets().get("assignees")).containsOnly(entry("steph", 1L), entry("simon", 2L), entry("", 1L)); } @@ -545,7 +545,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE3", file).setAssignee("simon"), IssueTesting.newDoc("ISSUE4", file).setAssignee(null)); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).assignees(Arrays.asList("j-b")).build(), + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).assignees(Arrays.asList("j-b")).build(), new SearchOptions().addFacets(newArrayList("assignees"))); assertThat(result.getFacets().getNames()).containsOnly("assignees"); assertThat(result.getFacets().get("assignees")).containsOnly(entry("j-b", 1L), entry("simon", 2L), entry("", 1L)); @@ -561,9 +561,9 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setAssignee(null), IssueTesting.newDoc("ISSUE3", file).setAssignee(null)); - assertThat(index.search(IssueQuery.builder(userSessionRule).assigned(true).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).assigned(false).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).assigned(null).build(), new SearchOptions()).getDocs()).hasSize(3); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).assigned(true).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).assigned(false).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).assigned(null).build(), new SearchOptions()).getDocs()).hasSize(3); } @Test @@ -576,9 +576,9 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setAuthorLogin("simon"), IssueTesting.newDoc("ISSUE3", file).setAssignee(null)); - assertThat(index.search(IssueQuery.builder(userSessionRule).authors(newArrayList("steph")).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).authors(newArrayList("steph", "simon")).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).authors(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).authors(newArrayList("steph")).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).authors(newArrayList("steph", "simon")).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).authors(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -592,7 +592,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE3", file).setAuthorLogin("simon"), IssueTesting.newDoc("ISSUE4", file).setAuthorLogin(null)); - SearchResult result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("authors"))); + SearchResult result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets(newArrayList("authors"))); assertThat(result.getFacets().getNames()).containsOnly("authors"); assertThat(result.getFacets().get("authors")).containsOnly(entry("steph", 1L), entry("simon", 2L)); } @@ -606,11 +606,11 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")), IssueTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23"))); - assertThat(index.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-19")).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-19")).build(), new SearchOptions()).getDocs()).hasSize(2); // Lower bound is included - assertThat(index.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-20")).build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-21")).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-25")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-20")).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-21")).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-25")).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -622,11 +622,11 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")), IssueTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23"))); - assertThat(index.search(IssueQuery.builder(userSessionRule).createdBefore(parseDate("2014-09-19")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdBefore(parseDate("2014-09-19")).build(), new SearchOptions()).getDocs()).isEmpty(); // Upper bound is excluded - assertThat(index.search(IssueQuery.builder(userSessionRule).createdBefore(parseDate("2014-09-20")).build(), new SearchOptions()).getDocs()).isEmpty(); - assertThat(index.search(IssueQuery.builder(userSessionRule).createdBefore(parseDate("2014-09-21")).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).createdBefore(parseDate("2014-09-25")).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdBefore(parseDate("2014-09-20")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdBefore(parseDate("2014-09-21")).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdBefore(parseDate("2014-09-25")).build(), new SearchOptions()).getDocs()).hasSize(2); } @Test @@ -639,37 +639,37 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23"))); // 19 < createdAt < 25 - assertThat(index.search(IssueQuery.builder(userSessionRule) + assertThat(underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDate("2014-09-19")).createdBefore(parseDate("2014-09-25")) .build(), new SearchOptions()).getDocs()).hasSize(2); // 20 < createdAt < 25: excludes first issue - assertThat(index.search(IssueQuery.builder(userSessionRule) + assertThat(underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-25")) .build(), new SearchOptions()).getDocs()).hasSize(2); // 21 < createdAt < 25 - assertThat(index.search(IssueQuery.builder(userSessionRule) + assertThat(underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDate("2014-09-21")).createdBefore(parseDate("2014-09-25")) .build(), new SearchOptions()).getDocs()).hasSize(1); // 21 < createdAt < 24 - assertThat(index.search(IssueQuery.builder(userSessionRule) + assertThat(underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDate("2014-09-21")).createdBefore(parseDate("2014-09-24")) .build(), new SearchOptions()).getDocs()).hasSize(1); // 21 < createdAt < 23: excludes second issue - assertThat(index.search(IssueQuery.builder(userSessionRule) + assertThat(underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDate("2014-09-21")).createdBefore(parseDate("2014-09-23")) .build(), new SearchOptions()).getDocs()).isEmpty(); // 19 < createdAt < 21: only first issue - assertThat(index.search(IssueQuery.builder(userSessionRule) + assertThat(underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDate("2014-09-19")).createdBefore(parseDate("2014-09-21")) .build(), new SearchOptions()).getDocs()).hasSize(1); // 20 < createdAt < 20: nothing - assertThat(index.search(IssueQuery.builder(userSessionRule) + assertThat(underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-20")) .build(), new SearchOptions()).getDocs()).isEmpty(); } @@ -683,11 +683,11 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDateTime("2014-09-20T00:00:00+0100")), IssueTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100"))); - assertThat(index.search(IssueQuery.builder(userSessionRule) + assertThat(underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDateTime("2014-09-19T23:00:00+0000")).createdBefore(parseDateTime("2014-09-22T23:00:01+0000")) .build(), new SearchOptions()).getDocs()).hasSize(2); - assertThat(index.search(IssueQuery.builder(userSessionRule) + assertThat(underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDateTime("2014-09-19T23:00:01+0000")).createdBefore(parseDateTime("2014-09-22T23:00:00+0000")) .build(), new SearchOptions()).getDocs()).hasSize(0); } @@ -695,7 +695,7 @@ public class IssueIndexTest { @Test public void filter_by_created_before_must_be_lower_than_after() { try { - index.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-19")).build(), + underTest.search(IssueQuery.builder(userSessionRule).createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-19")).build(), new SearchOptions()); Fail.failBecauseExceptionWasNotThrown(IllegalArgumentException.class); } catch (IllegalArgumentException exception) { @@ -706,7 +706,7 @@ public class IssueIndexTest { @Test public void filter_by_created_after_must_not_be_in_future() { try { - index.search(IssueQuery.builder(userSessionRule).createdAfter(new Date(Long.MAX_VALUE)).build(), new SearchOptions()); + underTest.search(IssueQuery.builder(userSessionRule).createdAfter(new Date(Long.MAX_VALUE)).build(), new SearchOptions()); Fail.failBecauseExceptionWasNotThrown(IllegalArgumentException.class); } catch (IllegalArgumentException exception) { assertThat(exception.getMessage()).isEqualTo("Start bound cannot be in the future"); @@ -720,8 +720,8 @@ public class IssueIndexTest { indexIssues(IssueTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20"))); - assertThat(index.search(IssueQuery.builder(userSessionRule).createdAt(parseDate("2014-09-20")).build(), new SearchOptions()).getDocs()).hasSize(1); - assertThat(index.search(IssueQuery.builder(userSessionRule).createdAt(parseDate("2014-09-21")).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdAt(parseDate("2014-09-20")).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).createdAt(parseDate("2014-09-21")).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -734,7 +734,7 @@ public class IssueIndexTest { .createdBefore(parseDateTime("2014-09-08T00:00:00+0100")) .checkAuthorization(false) .build(); - SearchResult result = index.search(query, options); + SearchResult result = underTest.search(query, options); Map buckets = result.getFacets().get("createdAt"); assertThat(buckets).containsOnly( entry("2014-08-31T01:00:00+0000", 0L), @@ -752,7 +752,7 @@ public class IssueIndexTest { SearchOptions SearchOptions = fixtureForCreatedAtFacet(); - Map createdAt = index.search(IssueQuery.builder(userSessionRule) + Map createdAt = underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDateTime("2014-09-01T00:00:00+0100")) .createdBefore(parseDateTime("2014-09-21T00:00:00+0100")).build(), SearchOptions).getFacets().get("createdAt"); @@ -768,7 +768,7 @@ public class IssueIndexTest { SearchOptions SearchOptions = fixtureForCreatedAtFacet(); - Map createdAt = index.search(IssueQuery.builder(userSessionRule) + Map createdAt = underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDateTime("2014-09-01T00:00:00+0100")) .createdBefore(parseDateTime("2015-01-19T00:00:00+0100")).build(), SearchOptions).getFacets().get("createdAt"); @@ -785,7 +785,7 @@ public class IssueIndexTest { public void facet_on_created_at_with_more_than_20_months() { SearchOptions SearchOptions = fixtureForCreatedAtFacet(); - Map createdAt = index.search(IssueQuery.builder(userSessionRule) + Map createdAt = underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDateTime("2011-01-01T00:00:00+0100")) .createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(), SearchOptions).getFacets().get("createdAt"); @@ -799,11 +799,23 @@ public class IssueIndexTest { } + @Test + public void facet_on_created_at_with_one_day() { + SearchOptions SearchOptions = fixtureForCreatedAtFacet(); + + Map createdAt = underTest.search(IssueQuery.builder(userSessionRule) + .createdAfter(parseDateTime("2014-09-01T00:00:00-0100")) + .createdBefore(parseDateTime("2014-09-02T00:00:00-0100")).build(), + SearchOptions).getFacets().get("createdAt"); + assertThat(createdAt).containsOnly( + entry("2014-09-01T01:00:00+0000", 2L)); + } + @Test public void facet_on_created_at_with_bounds_outside_of_data() { SearchOptions options = fixtureForCreatedAtFacet(); - Map createdAt = index.search(IssueQuery.builder(userSessionRule) + Map createdAt = underTest.search(IssueQuery.builder(userSessionRule) .createdAfter(parseDateTime("2009-01-01T00:00:00+0100")) .createdBefore(parseDateTime("2016-01-01T00:00:00+0100")) .build(), options).getFacets().get("createdAt"); @@ -822,7 +834,7 @@ public class IssueIndexTest { public void facet_on_created_at_without_start_bound() { SearchOptions SearchOptions = fixtureForCreatedAtFacet(); - Map createdAt = index.search(IssueQuery.builder(userSessionRule) + Map createdAt = underTest.search(IssueQuery.builder(userSessionRule) .createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(), SearchOptions).getFacets().get("createdAt"); assertThat(createdAt).containsOnly( @@ -837,7 +849,7 @@ public class IssueIndexTest { public void facet_on_created_at_without_issues() { SearchOptions SearchOptions = new SearchOptions().addFacets("createdAt"); - Map createdAt = index.search(IssueQuery.builder(userSessionRule).build(), + Map createdAt = underTest.search(IssueQuery.builder(userSessionRule).build(), SearchOptions).getFacets().get("createdAt"); assertThat(createdAt).isEmpty(); } @@ -869,15 +881,15 @@ public class IssueIndexTest { IssueQuery.Builder query = IssueQuery.builder(userSessionRule); // There are 12 issues in total, with 10 issues per page, the page 2 should only contain 2 elements - SearchResult result = index.search(query.build(), new SearchOptions().setPage(2, 10)); + SearchResult result = underTest.search(query.build(), new SearchOptions().setPage(2, 10)); assertThat(result.getDocs()).hasSize(2); assertThat(result.getTotal()).isEqualTo(12); - result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().setOffset(0).setLimit(5)); + result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().setOffset(0).setLimit(5)); assertThat(result.getDocs()).hasSize(5); assertThat(result.getTotal()).isEqualTo(12); - result = index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().setOffset(2).setLimit(0)); + result = underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().setOffset(2).setLimit(0)); assertThat(result.getDocs()).hasSize(10); assertThat(result.getTotal()).isEqualTo(12); } @@ -894,7 +906,7 @@ public class IssueIndexTest { indexIssues(issues.toArray(new IssueDoc[] {})); IssueQuery.Builder query = IssueQuery.builder(userSessionRule); - SearchResult result = index.search(query.build(), new SearchOptions().setLimit(Integer.MAX_VALUE)); + SearchResult result = underTest.search(query.build(), new SearchOptions().setLimit(Integer.MAX_VALUE)); assertThat(result.getDocs()).hasSize(SearchOptions.MAX_LIMIT); } @@ -909,13 +921,13 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE3", file).setStatus(Issue.STATUS_REOPENED)); IssueQuery.Builder query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_STATUS).asc(true); - SearchResult result = index.search(query.build(), new SearchOptions()); + SearchResult result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs().get(0).status()).isEqualTo(Issue.STATUS_CLOSED); assertThat(result.getDocs().get(1).status()).isEqualTo(Issue.STATUS_OPEN); assertThat(result.getDocs().get(2).status()).isEqualTo(Issue.STATUS_REOPENED); query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_STATUS).asc(false); - result = index.search(query.build(), new SearchOptions()); + result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs().get(0).status()).isEqualTo(Issue.STATUS_REOPENED); assertThat(result.getDocs().get(1).status()).isEqualTo(Issue.STATUS_OPEN); assertThat(result.getDocs().get(2).status()).isEqualTo(Issue.STATUS_CLOSED); @@ -934,7 +946,7 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE5", file).setSeverity(Severity.MAJOR)); IssueQuery.Builder query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_SEVERITY).asc(true); - SearchResult result = index.search(query.build(), new SearchOptions()); + SearchResult result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs().get(0).severity()).isEqualTo(Severity.INFO); assertThat(result.getDocs().get(1).severity()).isEqualTo(Severity.MINOR); assertThat(result.getDocs().get(2).severity()).isEqualTo(Severity.MAJOR); @@ -942,7 +954,7 @@ public class IssueIndexTest { assertThat(result.getDocs().get(4).severity()).isEqualTo(Severity.BLOCKER); query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_SEVERITY).asc(false); - result = index.search(query.build(), new SearchOptions()); + result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs().get(0).severity()).isEqualTo(Severity.BLOCKER); assertThat(result.getDocs().get(1).severity()).isEqualTo(Severity.CRITICAL); assertThat(result.getDocs().get(2).severity()).isEqualTo(Severity.MAJOR); @@ -960,13 +972,13 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setAssignee("simon")); IssueQuery.Builder query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_ASSIGNEE).asc(true); - SearchResult result = index.search(query.build(), new SearchOptions()); + SearchResult result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(2); assertThat(result.getDocs().get(0).assignee()).isEqualTo("simon"); assertThat(result.getDocs().get(1).assignee()).isEqualTo("steph"); query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_ASSIGNEE).asc(false); - result = index.search(query.build(), new SearchOptions()); + result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(2); assertThat(result.getDocs().get(0).assignee()).isEqualTo("steph"); assertThat(result.getDocs().get(1).assignee()).isEqualTo("simon"); @@ -982,13 +994,13 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100"))); IssueQuery.Builder query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_CREATION_DATE).asc(true); - SearchResult result = index.search(query.build(), new SearchOptions()); + SearchResult result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(2); assertThat(result.getDocs().get(0).creationDate()).isEqualTo(parseDateTime("2014-09-23T00:00:00+0100")); assertThat(result.getDocs().get(1).creationDate()).isEqualTo(parseDateTime("2014-09-24T00:00:00+0100")); query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_CREATION_DATE).asc(false); - result = index.search(query.build(), new SearchOptions()); + result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(2); assertThat(result.getDocs().get(0).creationDate()).isEqualTo(parseDateTime("2014-09-24T00:00:00+0100")); assertThat(result.getDocs().get(1).creationDate()).isEqualTo(parseDateTime("2014-09-23T00:00:00+0100")); @@ -1004,13 +1016,13 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE2", file).setFuncUpdateDate(parseDateTime("2014-09-24T00:00:00+0100"))); IssueQuery.Builder query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_UPDATE_DATE).asc(true); - SearchResult result = index.search(query.build(), new SearchOptions()); + SearchResult result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(2); assertThat(result.getDocs().get(0).updateDate()).isEqualTo(parseDateTime("2014-09-23T00:00:00+0100")); assertThat(result.getDocs().get(1).updateDate()).isEqualTo(parseDateTime("2014-09-24T00:00:00+0100")); query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_UPDATE_DATE).asc(false); - result = index.search(query.build(), new SearchOptions()); + result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(2); assertThat(result.getDocs().get(0).updateDate()).isEqualTo(parseDateTime("2014-09-24T00:00:00+0100")); assertThat(result.getDocs().get(1).updateDate()).isEqualTo(parseDateTime("2014-09-23T00:00:00+0100")); @@ -1027,14 +1039,14 @@ public class IssueIndexTest { IssueTesting.newDoc("ISSUE3", file).setFuncCloseDate(null)); IssueQuery.Builder query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_CLOSE_DATE).asc(true); - SearchResult result = index.search(query.build(), new SearchOptions()); + SearchResult result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(3); assertThat(result.getDocs().get(0).closeDate()).isNull(); assertThat(result.getDocs().get(1).closeDate()).isEqualTo(parseDateTime("2014-09-23T00:00:00+0100")); assertThat(result.getDocs().get(2).closeDate()).isEqualTo(parseDateTime("2014-09-24T00:00:00+0100")); query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_CLOSE_DATE).asc(false); - result = index.search(query.build(), new SearchOptions()); + result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(3); assertThat(result.getDocs().get(0).closeDate()).isEqualTo(parseDateTime("2014-09-24T00:00:00+0100")); assertThat(result.getDocs().get(1).closeDate()).isEqualTo(parseDateTime("2014-09-23T00:00:00+0100")); @@ -1061,7 +1073,7 @@ public class IssueIndexTest { // ascending sort -> F1 then F2. Line "0" first. IssueQuery.Builder query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_FILE_LINE).asc(true); - SearchResult result = index.search(query.build(), new SearchOptions()); + SearchResult result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(6); assertThat(result.getDocs().get(0).key()).isEqualTo("F1_1"); assertThat(result.getDocs().get(1).key()).isEqualTo("F1_2"); @@ -1072,7 +1084,7 @@ public class IssueIndexTest { // descending sort -> F2 then F1 query = IssueQuery.builder(userSessionRule).sort(IssueQuery.SORT_BY_FILE_LINE).asc(false); - result = index.search(query.build(), new SearchOptions()); + result = underTest.search(query.build(), new SearchOptions()); assertThat(result.getDocs()).hasSize(6); assertThat(result.getDocs().get(0).key()).isEqualTo("F2_3"); assertThat(result.getDocs().get(1).key()).isEqualTo("F2_2"); @@ -1100,19 +1112,19 @@ public class IssueIndexTest { indexIssue(IssueTesting.newDoc("ISSUE3", file3), null, null); userSessionRule.login().setUserGroups("sonar-users"); - assertThat(index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); userSessionRule.login().setUserGroups("sonar-admins"); - assertThat(index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); userSessionRule.login().setUserGroups("sonar-users", "sonar-admins"); - assertThat(index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(2); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(2); userSessionRule.login().setUserGroups("another group"); - assertThat(index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).isEmpty(); userSessionRule.login().setUserGroups("sonar-users", "sonar-admins"); - assertThat(index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project3.uuid())).build(), new SearchOptions()).getDocs()).isEmpty(); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project3.uuid())).build(), new SearchOptions()).getDocs()).isEmpty(); } @Test @@ -1132,16 +1144,16 @@ public class IssueIndexTest { userSessionRule.login("john"); - assertThat(index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); userSessionRule.login("max"); - assertThat(index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); userSessionRule.login("another guy"); - assertThat(index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(0); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(0); userSessionRule.login("john"); - assertThat(index.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project3.key())).build(), new SearchOptions()).getDocs()).hasSize(0); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).projectUuids(newArrayList(project3.key())).build(), new SearchOptions()).getDocs()).hasSize(0); } @Test @@ -1157,7 +1169,7 @@ public class IssueIndexTest { indexIssue(IssueTesting.newDoc("ISSUE2", file2), null, "max"); userSessionRule.login("john").setUserGroups("sonar-users"); - assertThat(index.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); + assertThat(underTest.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions()).getDocs()).hasSize(1); } @Test @@ -1178,7 +1190,7 @@ public class IssueIndexTest { .setFuncCreationDate(new Date()); indexIssues(issue); - List issues = Lists.newArrayList(index.selectIssuesForBatch(file)); + List issues = Lists.newArrayList(underTest.selectIssuesForBatch(file)); assertThat(issues).hasSize(1); IssueDoc result = issues.get(0); assertThat(result.key()).isEqualTo("ISSUE"); @@ -1210,17 +1222,17 @@ public class IssueIndexTest { // Close Issue, should never be returned IssueTesting.newDoc("CLOSE_ISSUE", file).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED)); - assertThat(Lists.newArrayList(index.selectIssuesForBatch(project))).hasSize(3); - assertThat(Lists.newArrayList(index.selectIssuesForBatch(module))).hasSize(3); - assertThat(Lists.newArrayList(index.selectIssuesForBatch(subModule))).hasSize(2); - assertThat(Lists.newArrayList(index.selectIssuesForBatch(file))).hasSize(1); - assertThat(Lists.newArrayList(index.selectIssuesForBatch(ComponentTesting.newProjectDto()))).isEmpty(); + assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(project))).hasSize(3); + assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(module))).hasSize(3); + assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(subModule))).hasSize(2); + assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(file))).hasSize(1); + assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(ComponentTesting.newProjectDto()))).isEmpty(); } @Test public void fail_to_search_issues_for_batch_on_not_allowed_scope() { try { - index.selectIssuesForBatch(new ComponentDto().setScope(Scopes.DIRECTORY)); + underTest.selectIssuesForBatch(new ComponentDto().setScope(Scopes.DIRECTORY)); failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException e) { assertThat(e).hasMessage("Component of scope 'DIR' is not allowed"); @@ -1241,10 +1253,10 @@ public class IssueIndexTest { indexIssue(IssueTesting.newDoc("ISSUE3", file2), null, null); userSessionRule.setUserGroups("sonar-users"); - assertThat(Lists.newArrayList(index.selectIssuesForBatch(project1))).hasSize(1); + assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(project1))).hasSize(1); userSessionRule.setUserGroups("another group"); - assertThat(Lists.newArrayList(index.selectIssuesForBatch(project2))).isEmpty(); + assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(project2))).isEmpty(); } private void indexIssues(IssueDoc... issues) {