]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4301 Sort issues by id desc on selectByIds and selectIssues
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 30 May 2013 14:12:35 +0000 (16:12 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 30 May 2013 14:12:35 +0000 (16:12 +0200)
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java

index 09c2ab1fb1433bbd393ab4ee5e0b87abeeda9d04..463e7f0fd36330b5c1760f60e7a61dc377d463e0 100644 (file)
       and p.id=i.component_id
       and i.root_component_id=root.id
     </where>
+    order by i.id desc
   </select>
 
   <select id="selectIssues" parameterType="map" resultType="Issue" fetchSize="100000">
         and i.issue_creation_date &lt; #{query.createdBefore}
       </if>
     </where>
+    order by i.id desc
   </sql>
 
 </mapper>
index 51002a5ed45cc28bcf7a4c22130172c2ed3ae24e..ec9f735b8cba93ae63095cba539851ca3654071f 100644 (file)
@@ -89,6 +89,18 @@ public class IssueDaoTest extends AbstractDaoTestCase {
     assertThat(issue.getId()).isNotNull();
   }
 
+  @Test
+  public void should_select_issues_sort_results_by_id_desc() {
+    setupData("shared", "should_select_all");
+
+    IssueQuery query = IssueQuery.builder().requiredRole("user").build();
+
+    List<IssueDto> results = dao.selectIssues(query);
+    assertThat(results.get(0).getId()).isEqualTo(102);
+    assertThat(results.get(1).getId()).isEqualTo(101);
+    assertThat(results.get(2).getId()).isEqualTo(100);
+  }
+
   @Test
   public void should_select_by_rules() {
     setupData("shared", "should_select_by_rules");
@@ -297,6 +309,17 @@ public class IssueDaoTest extends AbstractDaoTestCase {
     assertThat(results).hasSize(3);
   }
 
+  @Test
+  public void should_select_by_ids_sort_results_by_id_desc() {
+    setupData("shared", "should_select_by_ids");
+
+    List<IssueDto> results = newArrayList(dao.selectByIds(newArrayList(100l, 101l, 102l)));
+
+    assertThat(results.get(0).getId()).isEqualTo(102);
+    assertThat(results.get(1).getId()).isEqualTo(101);
+    assertThat(results.get(2).getId()).isEqualTo(100);
+  }
+
 
   private List<Long> getIssueIds(List<IssueDto> issues){
     return newArrayList(Iterables.transform(issues, new Function<IssueDto, Long>() {