aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-06-01 11:22:34 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-06-01 11:22:34 +0200
commit481216a731cb25a7d1619c30dd173f12e1625e28 (patch)
treee5e1c541d237c45fa31f84ae19e67dc50355af6d
parentdf0e388a524ebf11978e9961e9b6f25a184d9dba (diff)
downloadsonarqube-481216a731cb25a7d1619c30dd173f12e1625e28.tar.gz
sonarqube-481216a731cb25a7d1619c30dd173f12e1625e28.zip
Fix a test isolation and replace field MeasureDto.projectId by componentId
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java45
-rw-r--r--sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDto.java12
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml2
3 files changed, 34 insertions, 25 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
index cc0acaff668..bd845ac6ffd 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
@@ -20,6 +20,11 @@
package org.sonar.server.computation.step;
+import java.io.File;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -59,12 +64,6 @@ import org.sonar.server.rule.RuleTesting;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.test.DbTests;
-import java.io.File;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -211,7 +210,7 @@ public class PersistMeasuresStepTest extends BaseStepTest {
@Test
public void map_full_batch_measure() {
BatchReport.Component component = defaultComponent().build();
- addComponent(component.getRef(), "component-key");
+ ComponentDto componentDto = addComponent(component.getRef(), "component-key");
BatchReport.Measure batchMeasure = BatchReport.Measure.newBuilder()
.setValueType(MeasureValueType.DOUBLE)
@@ -233,13 +232,29 @@ public class PersistMeasuresStepTest extends BaseStepTest {
MeasureDto measure = sut.toMeasureDto(batchMeasure, component);
- assertThat(measure).isEqualToComparingFieldByField(expectedFullMeasure());
+ assertThat(measure).isEqualToComparingFieldByField(new MeasureDto()
+ .setComponentId(componentDto.getId())
+ .setSnapshotId(3L)
+ .setCharacteristicId(123456)
+ .setPersonId(5432)
+ .setValue(123.123d)
+ .setVariation(1, 1.1d)
+ .setVariation(2, 2.2d)
+ .setVariation(3, 3.3d)
+ .setVariation(4, 4.4d)
+ .setVariation(5, 5.5d)
+ .setAlertStatus("WARN")
+ .setAlertText("Open issues > 0")
+ .setDescription("measure-description")
+ .setSeverity(Severity.CRITICAL)
+ .setMetricId(metric.getId())
+ .setRuleId(rule.getId()));
}
@Test
public void map_minimal_batch_measure() {
BatchReport.Component component = defaultComponent().build();
- addComponent(component.getRef(), "component-key");
+ ComponentDto componentDto = addComponent(component.getRef(), "component-key");
BatchReport.Measure batchMeasure = BatchReport.Measure.newBuilder()
.setValueType(MeasureValueType.INT)
@@ -248,7 +263,10 @@ public class PersistMeasuresStepTest extends BaseStepTest {
MeasureDto measure = sut.toMeasureDto(batchMeasure, component);
- assertThat(measure).isEqualToComparingFieldByField(expectedMinimalistMeasure());
+ assertThat(measure).isEqualToComparingFieldByField(new MeasureDto()
+ .setComponentId(componentDto.getId())
+ .setSnapshotId(3L)
+ .setMetricId(metric.getId()));
}
@Test
@@ -415,13 +433,6 @@ public class PersistMeasuresStepTest extends BaseStepTest {
.setRuleId(rule.getId());
}
- private MeasureDto expectedMinimalistMeasure() {
- return new MeasureDto()
- .setComponentId(2L)
- .setSnapshotId(3L)
- .setMetricId(metric.getId());
- }
-
private BatchReport.Component.Builder defaultComponent() {
return BatchReport.Component.newBuilder()
.setRef(1)
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDto.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDto.java
index 7b4e45e2cdc..6eaa2665bdc 100644
--- a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDto.java
@@ -20,12 +20,10 @@
package org.sonar.core.measure.db;
-import org.sonar.api.rule.Severity;
-
+import java.nio.charset.StandardCharsets;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
-import java.nio.charset.StandardCharsets;
+import org.sonar.api.rule.Severity;
import static com.google.common.base.Preconditions.checkArgument;
@@ -43,7 +41,7 @@ public class MeasureDto {
private String description;
private Integer severityIndex;
- private Long projectId;
+ private Long componentId;
private Long snapshotId;
private Integer metricId;
private Integer ruleId;
@@ -168,11 +166,11 @@ public class MeasureDto {
}
public Long getComponentId() {
- return projectId;
+ return componentId;
}
public MeasureDto setComponentId(Long componentId) {
- this.projectId = componentId;
+ this.componentId = componentId;
return this;
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml
index a1a0276bfc6..d366300906b 100644
--- a/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml
@@ -76,7 +76,7 @@
VALUES (
#{value, jdbcType=DOUBLE}, #{metricId, jdbcType=INTEGER}, #{snapshotId, jdbcType=INTEGER},
#{ruleId, jdbcType=INTEGER}, #{textValue, jdbcType=VARCHAR},
- #{projectId, jdbcType=INTEGER}, #{alertStatus, jdbcType=VARCHAR}, #{alertText, jdbcType=VARCHAR},
+ #{componentId, jdbcType=INTEGER}, #{alertStatus, jdbcType=VARCHAR}, #{alertText, jdbcType=VARCHAR},
#{description, jdbcType=VARCHAR}, #{severityIndex, jdbcType=INTEGER}, #{characteristicId, jdbcType=INTEGER},
#{personId, jdbcType=INTEGER}, #{variation1, jdbcType=DOUBLE}, #{variation2, jdbcType=DOUBLE}, #{variation3, jdbcType=DOUBLE},
#{variation4, jdbcType=DOUBLE}, #{variation5, jdbcType=DOUBLE}, #{dataValue, jdbcType=BINARY}