diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-11-25 17:02:08 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-11-28 16:02:04 +0100 |
commit | 8578fb03dc34d704b2cb2b361f55b3d472d40d87 (patch) | |
tree | b85be3e0504b7e5518a39f65038fd05885d0efc5 | |
parent | d1a7a0173da71f1ee40e2b3cc74396fe7747b4c8 (diff) | |
download | sonarqube-8578fb03dc34d704b2cb2b361f55b3d472d40d87.tar.gz sonarqube-8578fb03dc34d704b2cb2b361f55b3d472d40d87.zip |
SONAR-8089 Add missing condition on snapshots.islast=true
-rw-r--r-- | sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml | 1 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java | 34 |
2 files changed, 35 insertions, 0 deletions
diff --git a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml index 61b1268b219..9b5900bba35 100644 --- a/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml @@ -112,6 +112,7 @@ </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> diff --git a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java index beddaf6c737..9878b64a49f 100644 --- a/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java @@ -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()); } |