aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-27 17:38:00 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-10-28 14:53:22 +0200
commitf0e3b2f62a070961ba3fa053d42f006a8f8e1571 (patch)
tree30b5ce171d501e544e595bafba02695555384494
parentaeb728e615ba8cd6890be294028dfae22552df0f (diff)
downloadsonarqube-f0e3b2f62a070961ba3fa053d42f006a8f8e1571.tar.gz
sonarqube-f0e3b2f62a070961ba3fa053d42f006a8f8e1571.zip
SONAR-8089 SONAR-8325 Add missing join on projects in MeasureMapper#selectByQuery
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java3
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepositoryImplTest/shared.xml1
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/measure/MeasureMapper.xml5
-rw-r--r--sonar-db/src/test/java/org/sonar/db/measure/MeasureDaoTest.java36
4 files changed, 31 insertions, 14 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java
index 250ab99b1ff..a8fe1467e4d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/AppActionTest.java
@@ -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);
}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepositoryImplTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepositoryImplTest/shared.xml
index b0fc7ba9fa9..736834a2356 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepositoryImplTest/shared.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/task/projectanalysis/measure/MeasureRepositoryImplTest/shared.xml
@@ -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"/>
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 9ddc76522fd..ab9bbcc31c5 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
@@ -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>
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 ad66b20e05d..d60413394e5 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
@@ -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));
}