]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8089 Add missing condition on snapshots.islast=true 1412/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 25 Nov 2016 16:02:08 +0000 (17:02 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 28 Nov 2016 15:02:04 +0000 (16:02 +0100)
sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java

index 61b1268b21968a658bd3b87e726dfb3a03ce8f13..9b5900bba353f83fcc21ef9044ec962434ee04e3 100644 (file)
   </select>
 
   <sql id="selectTreeByQueryFilters">
+    and analysis.islast=${_true}
     <if test="query.getMetricIds() != null">
       and pm.metric_id in
       <foreach item="metricId" collection="query.getMetricIds()" open="(" separator="," close=")">#{metricId}</foreach>
index beddaf6c737367515ba8cbb8fcb90bac0cf2cd8a..9878b64a49fd69f645b255d03e4931ac5e85a38c 100644 (file)
@@ -413,6 +413,40 @@ public class MeasureDaoTest {
     verifyMeasures(project, MeasureTreeQuery.builder().setQualifiers(asList(FILE, UNIT_TEST_FILE)).setStrategy(LEAVES), "M2", "M3", "M6");
   }
 
+  @Test
+  public void select_tree_by_query_use_only_latest_analysis() {
+    ComponentDto project = db.components().insertProject();
+    ComponentDto file1 = db.components().insertComponent(newFileDto(project).setUuid("C1").setName("File One"));
+    db.components().insertComponent(newFileDto(project).setUuid("C2").setName("File Two").setQualifier(UNIT_TEST_FILE));
+    insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
+    insertAnalysis(OTHER_ANALYSIS_UUID, project.uuid(), false);
+    db.components().indexAllComponents();
+
+    // project
+    insertMeasure("PROJECT_M1", LAST_ANALYSIS_UUID, project.uuid(), NCLOC_METRIC_ID);
+    insertMeasure("PROJECT_M2", OTHER_ANALYSIS_UUID, project.uuid(), NCLOC_METRIC_ID);
+    // component C1
+    insertMeasure("M2", LAST_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID);
+    insertMeasure("M3", LAST_ANALYSIS_UUID, "C1", COVERAGE_METRIC_ID);
+    insertMeasure("M4", OTHER_ANALYSIS_UUID, "C1", COVERAGE_METRIC_ID);
+    // component C2
+    insertMeasure("M5", LAST_ANALYSIS_UUID, "C2", NCLOC_METRIC_ID);
+    insertMeasure("M6", OTHER_ANALYSIS_UUID, "C2", NCLOC_METRIC_ID);
+    db.commit();
+
+    // Children measures of project
+    verifyMeasures(project, MeasureTreeQuery.builder().setStrategy(CHILDREN), "PROJECT_M1", "M2", "M3", "M5");
+
+    // Children measure on file => only measures from itself
+    verifyMeasures(file1, MeasureTreeQuery.builder().setStrategy(CHILDREN), "M2", "M3");
+
+    // Leaves measures of project
+    verifyMeasures(project, MeasureTreeQuery.builder().setStrategy(LEAVES), "PROJECT_M1", "M2", "M3", "M5");
+
+    // Leaves measure on file
+    verifyMeasures(file1, MeasureTreeQuery.builder().setStrategy(LEAVES), "M2", "M3");
+  }
+
   private Optional<MeasureDto> selectSingle(MeasureQuery.Builder query) {
     return underTest.selectSingle(db.getSession(), query.build());
   }