]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5718 fix sorting when multiple issues on the same line
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 31 Oct 2014 12:51:56 +0000 (13:51 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 31 Oct 2014 12:53:00 +0000 (13:53 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java

index fcb869847f4bc0b75e1a5c5ce3ce342223d2f9e7..69cfdeae4c943e52fbca90eeea85001368f4845a 100644 (file)
@@ -70,6 +70,7 @@ public class IssueIndex extends BaseIndex<Issue, IssueDto, String> {
     sortColumns.put(IssueQuery.SORT_BY_FILE_LINE, IssueNormalizer.IssueField.PROJECT);
     sortColumns.put(IssueQuery.SORT_BY_FILE_LINE, IssueNormalizer.IssueField.FILE_PATH);
     sortColumns.put(IssueQuery.SORT_BY_FILE_LINE, IssueNormalizer.IssueField.LINE);
+    sortColumns.put(IssueQuery.SORT_BY_FILE_LINE, IssueNormalizer.IssueField.KEY);
   }
 
   @Override
index 9e1e78551d2800b716c00b9c1b94c720b4396372..8d0dd92d7ba0451a87a31ef9659da20e4320c82b 100644 (file)
@@ -551,35 +551,40 @@ public class IssueIndexMediumTest {
   public void sort_by_file_and_line() throws Exception {
     db.issueDao().insert(session,
       // file Foo.java
-      IssueTesting.newDto(rule, file, project).setLine(20).setFilePath("src/Foo.java"),
-      IssueTesting.newDto(rule, file, project).setLine(null).setFilePath("src/Foo.java"),
-      IssueTesting.newDto(rule, file, project).setLine(25).setFilePath("src/Foo.java"),
+      IssueTesting.newDto(rule, file, project).setLine(20).setFilePath("src/Foo.java").setKee("FOO1"),
+      IssueTesting.newDto(rule, file, project).setLine(null).setFilePath("src/Foo.java").setKee("FOO3"),
+      IssueTesting.newDto(rule, file, project).setLine(25).setFilePath("src/Foo.java").setKee("FOO2"),
 
       // file Bar.java
-      IssueTesting.newDto(rule, file, project).setLine(9).setFilePath("src/Bar.java"),
-      IssueTesting.newDto(rule, file, project).setLine(109).setFilePath("src/Bar.java")
+      IssueTesting.newDto(rule, file, project).setLine(9).setFilePath("src/Bar.java").setKee("BAR1"),
+      IssueTesting.newDto(rule, file, project).setLine(109).setFilePath("src/Bar.java").setKee("BAR2"),
+      // two issues on the same line -> sort by key
+      IssueTesting.newDto(rule, file, project).setLine(109).setFilePath("src/Bar.java").setKee("BAR3")
       );
     session.commit();
 
     // ascending sort -> Bar then Foo
     IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_FILE_LINE).asc(true);
     Result<Issue> result = index.search(query.build(), new QueryContext());
-    assertThat(result.getHits()).hasSize(5);
-    assertThat(result.getHits().get(0).line()).isEqualTo(9);
-    assertThat(result.getHits().get(1).line()).isEqualTo(109);
-    assertThat(result.getHits().get(2).line()).isEqualTo(20);
-    assertThat(result.getHits().get(3).line()).isEqualTo(25);
-    assertThat(result.getHits().get(4).line()).isEqualTo(null);
+    assertThat(result.getHits()).hasSize(6);
+    assertThat(result.getHits().get(0).key()).isEqualTo("BAR1");
+    assertThat(result.getHits().get(1).key()).isEqualTo("BAR2");
+    assertThat(result.getHits().get(2).key()).isEqualTo("BAR3");
+    assertThat(result.getHits().get(3).key()).isEqualTo("FOO1");
+    assertThat(result.getHits().get(4).key()).isEqualTo("FOO2");
+    assertThat(result.getHits().get(5).key()).isEqualTo("FOO3");
 
     // descending sort -> Foo then Bar
     query = IssueQuery.builder().sort(IssueQuery.SORT_BY_FILE_LINE).asc(false);
     result = index.search(query.build(), new QueryContext());
-    assertThat(result.getHits()).hasSize(5);
-    assertThat(result.getHits().get(0).line()).isEqualTo(25);
-    assertThat(result.getHits().get(1).line()).isEqualTo(20);
-    assertThat(result.getHits().get(2).line()).isEqualTo(null);
-    assertThat(result.getHits().get(3).line()).isEqualTo(109);
-    assertThat(result.getHits().get(4).line()).isEqualTo(9);
+    assertThat(result.getHits()).hasSize(6);
+    assertThat(result.getHits().get(0).key()).isEqualTo("FOO2");
+    assertThat(result.getHits().get(1).key()).isEqualTo("FOO1");
+    // nul line is on last. Could be improved.
+    assertThat(result.getHits().get(2).key()).isEqualTo("FOO3");
+    assertThat(result.getHits().get(3).key()).isEqualTo("BAR3");
+    assertThat(result.getHits().get(4).key()).isEqualTo("BAR2");
+    assertThat(result.getHits().get(5).key()).isEqualTo("BAR1");
   }
 
   @Test