]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8089 SONAR-8325 Add missing join on projects in MeasureMapper#selectByQuery
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 27 Oct 2016 15:38:00 +0000 (17:38 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 28 Oct 2016 12:53:22 +0000 (14:53 +0200)
server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepositoryImplTest/shared.xml
sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml
sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java

index 250ab99b1ff9f4c9eca6268053474dfbf38f64dd..a8fe1467e4dc3e28c130ef9597985c8be034b379 100644 (file)
@@ -134,8 +134,7 @@ public class AppActionTest {
       .setLongName("src/main/java/org/sonar/api/Plugin.java")
       .setPath("src/main/java/org/sonar/api/Plugin.java");
     dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project, module, file);
-    SnapshotDto analysis = SnapshotTesting.newAnalysis(project)
-      .setUuid(ANALYSIS_UUID);
+    SnapshotDto analysis = SnapshotTesting.newAnalysis(project).setUuid(ANALYSIS_UUID);
     dbTester.getDbClient().snapshotDao().insert(dbTester.getSession(), analysis);
   }
 
index b0fc7ba9fa93c5fa99d9f8716b8236b2b99478ac..736834a2356f941fc7bcc61fe4ccaaf12b0ca009 100644 (file)
@@ -2,6 +2,7 @@
   <projects uuid="uuid_1"
             uuid_path="NOT_USED"
             root_uuid="uuid_1"
+            project_uuid="uuid_1"
             kee="file cpt key"
             enabled="[true]"
             id="567"/>
index 9ddc76522fd5881d924692bf3c3ed60f457b188c..ab9bbcc31c522c31d782f17a259e907d09800817 100644 (file)
@@ -30,7 +30,8 @@
     <include refid="measureColumns"/>
     from
       project_measures pm
-      inner join snapshots analysis on analysis.uuid = pm.analysis_uuid
+      inner join projects p on p.uuid=pm.component_uuid
+      inner join snapshots analysis on analysis.component_uuid = p.project_uuid and analysis.uuid = pm.analysis_uuid
       <if test="query.getMetricKeys() != null">
         inner join metrics m on m.id = pm.metric_id
       </if>
@@ -41,7 +42,7 @@
       <if test="query.getAnalysisUuid() != null">
         analysis.uuid = #{query.analysisUuid}
       </if>
-      and pm.component_uuid in
+      and p.uuid in
       <foreach item="componentUuid" collection="query.getComponentUuids()" open="(" separator="," close=")">
         #{componentUuid}
       </foreach>
index ad66b20e05d7789ce74461d6a215df8c8362a54a..d60413394e5bdfe90fa449b14143954eac8eeb44 100644 (file)
@@ -33,12 +33,15 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.util.UuidFactoryImpl;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.component.SnapshotTesting;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.emptyList;
 import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.component.ComponentTesting.newDeveloper;
+import static org.sonar.db.component.ComponentTesting.newFileDto;
 
 public class MeasureDaoTest {
 
@@ -59,7 +62,9 @@ public class MeasureDaoTest {
 
   @Test
   public void test_inserted_and_selected_columns() {
-    insertAnalysis(LAST_ANALYSIS_UUID, true);
+    ComponentDto project = db.components().insertProject();
+    insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
+    db.components().insertComponent(newFileDto(project).setUuid("C4"));
 
     MeasureDto inserted = new MeasureDto()
       .setAnalysisUuid(LAST_ANALYSIS_UUID)
@@ -100,8 +105,12 @@ public class MeasureDaoTest {
 
   @Test
   public void selectByQuery() {
-    insertAnalysis(LAST_ANALYSIS_UUID, true);
-    insertAnalysis(OTHER_ANALYSIS_UUID, false);
+    ComponentDto project = db.components().insertProject();
+    ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project));
+    db.components().insertComponent(newFileDto(module).setUuid("C1"));
+    db.components().insertComponent(newFileDto(module).setUuid("C2"));
+    insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
+    insertAnalysis(OTHER_ANALYSIS_UUID, project.uuid(), false);
     // component C1
     insertMeasure("M1", OTHER_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID);
     insertMeasure("M2", LAST_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID);
@@ -167,8 +176,11 @@ public class MeasureDaoTest {
 
   @Test
   public void selectByQuery_with_handler() {
-    insertAnalysis(LAST_ANALYSIS_UUID, true);
-    insertAnalysis(OTHER_ANALYSIS_UUID, false);
+    ComponentDto project = db.components().insertProject();
+    db.components().insertComponent(newFileDto(project).setUuid("C1"));
+    db.components().insertComponent(newFileDto(project).setUuid("C2"));
+    insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
+    insertAnalysis(OTHER_ANALYSIS_UUID, project.uuid(), false);
     // component C1
     insertMeasure("M1", OTHER_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID);
     insertMeasure("M2", LAST_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID);
@@ -235,7 +247,9 @@ public class MeasureDaoTest {
 
   @Test
   public void selectSingle() {
-    insertAnalysis(LAST_ANALYSIS_UUID, true);
+    ComponentDto project = db.components().insertProject();
+    db.components().insertComponent(newFileDto(project).setUuid("C1"));
+    insertAnalysis(LAST_ANALYSIS_UUID, project.uuid(), true);
     insertMeasure("M1", LAST_ANALYSIS_UUID, "C1", NCLOC_METRIC_ID);
     insertMeasure("M2", LAST_ANALYSIS_UUID, "C1", COMPLEXITY_METRIC_ID);
     db.commit();
@@ -254,10 +268,11 @@ public class MeasureDaoTest {
 
   @Test
   public void selectProjectMeasuresOfDeveloper() {
-    insertAnalysis(LAST_ANALYSIS_UUID, true);
-    insertAnalysis(PREVIOUS_ANALYSIS_UUID, false);
+    ComponentDto dev = db.components().insertComponent(newDeveloper("DEV"));
+    insertAnalysis(LAST_ANALYSIS_UUID, dev.uuid(), true);
+    insertAnalysis(PREVIOUS_ANALYSIS_UUID, dev.uuid(), false);
     List<Integer> allMetricIds = Arrays.asList(NCLOC_METRIC_ID, COMPLEXITY_METRIC_ID, COVERAGE_METRIC_ID);
-    long developerId = 123L;
+    long developerId = dev.getId();
     assertThat(underTest.selectProjectMeasuresOfDeveloper(db.getSession(), developerId, allMetricIds)).isEmpty();
 
     String projectUuid = insertComponent(Scopes.PROJECT, Qualifiers.PROJECT, true);
@@ -362,9 +377,10 @@ public class MeasureDaoTest {
     db.getDbClient().measureDao().insert(db.getSession(), measure);
   }
 
-  private void insertAnalysis(String uuid, boolean isLast) {
+  private void insertAnalysis(String uuid, String projectUuid, boolean isLast) {
     db.getDbClient().snapshotDao().insert(db.getSession(), SnapshotTesting.newSnapshot()
       .setUuid(uuid)
+      .setComponentUuid(projectUuid)
       .setLast(isLast));
   }