aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ce-task-projectanalysis
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2020-04-27 12:42:10 -0500
committersonartech <sonartech@sonarsource.com>2020-05-25 20:05:20 +0000
commit6b41a01454b98c413889dc2400a9cddb3b390847 (patch)
tree6ccca99e10d77b453abc252835d6c70cfdb41d6c /server/sonar-ce-task-projectanalysis
parent65e12a8ca01341c1ad00809d807bb8db0f5bf4b2 (diff)
downloadsonarqube-6b41a01454b98c413889dc2400a9cddb3b390847.tar.gz
sonarqube-6b41a01454b98c413889dc2400a9cddb3b390847.zip
SONAR-13221 Metrics
Diffstat (limited to 'server/sonar-ce-task-projectanalysis')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java10
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java16
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java14
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java36
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java30
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java24
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java28
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java12
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java6
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java32
35 files changed, 176 insertions, 180 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java
index 03b53f9b63d..d729a7257ff 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDto.java
@@ -39,7 +39,7 @@ public class MeasureToMeasureDto {
public MeasureDto toMeasureDto(Measure measure, Metric metric, Component component) {
MeasureDto out = new MeasureDto();
- out.setMetricId(metric.getId());
+ out.setMetricUuid(metric.getUuid());
out.setComponentUuid(component.getUuid());
out.setAnalysisUuid(analysisMetadataHolder.getUuid());
if (measure.hasVariation()) {
@@ -55,7 +55,7 @@ public class MeasureToMeasureDto {
public LiveMeasureDto toLiveMeasureDto(Measure measure, Metric metric, Component component) {
LiveMeasureDto out = new LiveMeasureDto();
- out.setMetricId(metric.getId());
+ out.setMetricUuid(metric.getUuid());
out.setComponentUuid(component.getUuid());
out.setProjectUuid(treeRootHolder.getRoot().getUuid());
if (measure.hasVariation()) {
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java
index 4b9602c8abd..1f7d985d7d1 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/Metric.java
@@ -24,9 +24,9 @@ import org.sonar.ce.task.projectanalysis.measure.Measure;
public interface Metric {
/**
- * The metric's id (ie. its database identifier)
+ * The metric's uuid (ie. its database identifier)
*/
- int getId();
+ String getUuid();
/**
* The Metric's key is its domain identifier.
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java
index b1591256b53..d1699ff5118 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetric.java
@@ -42,7 +42,7 @@ public enum MetricDtoToMetric implements Function<MetricDto, Metric> {
}
return new MetricImpl(
- metricDto.getId(), metricDto.getKey(), metricDto.getShortName(), metricType,
+ metricDto.getUuid(), metricDto.getKey(), metricDto.getShortName(), metricType,
decimalScale,
DoubleCache.intern(metricDto.getBestValue()), metricDto.isOptimizedBestValue(),
metricDto.isDeleteHistoricalData());
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java
index 4d88d3491b3..b0ec7f39517 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricImpl.java
@@ -34,7 +34,7 @@ import static com.google.common.base.Preconditions.checkState;
@Immutable
public final class MetricImpl implements Metric {
- private final int id;
+ private final String uuid;
private final String key;
private final String name;
private final MetricType type;
@@ -43,14 +43,14 @@ public final class MetricImpl implements Metric {
private final boolean bestValueOptimized;
private boolean deleteHistoricalData;
- public MetricImpl(int id, String key, String name, MetricType type) {
- this(id, key, name, type, null, null, false, false);
+ public MetricImpl(String uuid, String key, String name, MetricType type) {
+ this(uuid, key, name, type, null, null, false, false);
}
- public MetricImpl(int id, String key, String name, MetricType type, @Nullable Integer decimalScale,
+ public MetricImpl(String uuid, String key, String name, MetricType type, @Nullable Integer decimalScale,
@Nullable Double bestValue, boolean bestValueOptimized, boolean deleteHistoricalData) {
checkArgument(!bestValueOptimized || bestValue != null, "A BestValue must be specified if Metric is bestValueOptimized");
- this.id = id;
+ this.uuid = uuid;
this.key = checkNotNull(key);
this.name = checkNotNull(name);
this.type = checkNotNull(type);
@@ -65,8 +65,8 @@ public final class MetricImpl implements Metric {
}
@Override
- public int getId() {
- return id;
+ public String getUuid() {
+ return uuid;
}
@Override
@@ -126,7 +126,7 @@ public final class MetricImpl implements Metric {
@Override
public String toString() {
return toStringHelper(this)
- .add("id", id)
+ .add("uuid", uuid)
.add("key", key)
.add("name", name)
.add("type", type)
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java
index c5772764981..ac10fc234d1 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepository.java
@@ -35,16 +35,16 @@ public interface MetricRepository {
Metric getByKey(String key);
/**
- * Gets the {@link Metric} with the specific id.
+ * Gets the {@link Metric} with the specific uuid.
*
- * @throws IllegalStateException if no Metric with the specified id is found
+ * @throws IllegalStateException if no Metric with the specified uuid is found
*/
- Metric getById(long id);
+ Metric getByUuid(String uuid);
/**
- * Gets the {@link Metric} with the specific id if it exists in the repository.
+ * Gets the {@link Metric} with the specific uuid if it exists in the repository.
*/
- Optional<Metric> getOptionalById(long id);
+ Optional<Metric> getOptionalByUuid(String uuid);
/**
* Get iterable of all {@link Metric}.
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java
index adc72db9031..2330182024d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImpl.java
@@ -37,7 +37,7 @@ public class MetricRepositoryImpl implements MetricRepository, Startable {
@CheckForNull
private Map<String, Metric> metricsByKey;
@CheckForNull
- private Map<Long, Metric> metricsById;
+ private Map<String, Metric> metricsByUuid;
public MetricRepositoryImpl(DbClient dbClient) {
this.dbClient = dbClient;
@@ -48,7 +48,7 @@ public class MetricRepositoryImpl implements MetricRepository, Startable {
try (DbSession dbSession = dbClient.openSession(false)) {
List<MetricDto> metricList = dbClient.metricDao().selectEnabled(dbSession);
this.metricsByKey = metricList.stream().map(MetricDtoToMetric.INSTANCE).collect(Collectors.toMap(Metric::getKey, x -> x));
- this.metricsById = metricList.stream().map(MetricDtoToMetric.INSTANCE).collect(Collectors.toMap(m -> (long) m.getId(), x -> x));
+ this.metricsByUuid = metricList.stream().map(MetricDtoToMetric.INSTANCE).collect(Collectors.toMap(Metric::getUuid, x -> x));
}
}
@@ -70,16 +70,16 @@ public class MetricRepositoryImpl implements MetricRepository, Startable {
}
@Override
- public Metric getById(long id) {
- return getOptionalById(id)
- .orElseThrow(() -> new IllegalStateException(String.format("Metric with id '%s' does not exist", id)));
+ public Metric getByUuid(String uuid) {
+ return getOptionalByUuid(uuid)
+ .orElseThrow(() -> new IllegalStateException(String.format("Metric with uuid '%s' does not exist", uuid)));
}
@Override
- public Optional<Metric> getOptionalById(long id) {
+ public Optional<Metric> getOptionalByUuid(String uuid) {
verifyMetricsInitialized();
- return Optional.ofNullable(this.metricsById.get(id));
+ return Optional.ofNullable(this.metricsByUuid.get(uuid));
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java
index d7e9b084775..ca7f2753dfb 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/organization/package-info.java
@@ -18,6 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
-package org.sonar.ce.task.organization;
+package org.sonar.ce.task.projectanalysis.organization;
import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java
index 4ba6e4242bf..3643f501c5a 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/ProjectCleaner.java
@@ -20,13 +20,9 @@
package org.sonar.ce.task.projectanalysis.purge;
import java.util.Set;
-import org.sonar.api.CoreProperties;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.config.Configuration;
import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.TimeUtils;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
import org.sonar.db.DbSession;
import org.sonar.db.purge.PurgeConfiguration;
import org.sonar.db.purge.PurgeDao;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java
index 83a3efb902a..e7ac5540212 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/purge/package-info.java
@@ -18,6 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
-package org.sonar.ce.task.dbcleaner;
+package org.sonar.ce.task.projectanalysis.purge;
import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java
index e9bb1337d5a..51135a6ec7f 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java
@@ -79,7 +79,7 @@ public class QualityGateServiceImpl implements QualityGateService {
Collection<QualityGateConditionDto> dtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId());
Iterable<Condition> conditions = dtos.stream()
- .map(input -> metricRepository.getOptionalById(input.getMetricId())
+ .map(input -> metricRepository.getOptionalByUuid(input.getMetricUuid())
.map(metric -> new Condition(metric, input.getOperator(), input.getErrorThreshold()))
.orElse(null))
.filter(Objects::nonNull)
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java
index ac0962fd017..1b48554601d 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStep.java
@@ -69,7 +69,7 @@ public class CustomMeasuresCopyStep implements ComputationStep {
private void copy(Component component, DbSession session) {
for (CustomMeasureDto dto : loadCustomMeasures(component, session)) {
- Metric metric = metricRepository.getById(dto.getMetricId());
+ Metric metric = metricRepository.getByUuid(dto.getMetricUuid());
// else metric is not found and an exception is raised
Measure measure = dtoToMeasure(dto, metric);
measureRepository.add(component, metric, measure);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java
index 277fb40f9d4..c7f8f410784 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStep.java
@@ -103,7 +103,7 @@ public class PersistLiveMeasuresStep implements ComputationStep {
@Override
public void visitAny(Component component) {
- List<Integer> metricIds = new ArrayList<>();
+ List<String> metricUuids = new ArrayList<>();
Map<String, Measure> measures = measureRepository.getRawMeasures(component);
List<LiveMeasureDto> dtos = new ArrayList<>();
for (Map.Entry<String, Measure> measuresByMetricKey : measures.entrySet()) {
@@ -120,7 +120,7 @@ public class PersistLiveMeasuresStep implements ComputationStep {
LiveMeasureDto lm = measureToMeasureDto.toLiveMeasureDto(m, metric, component);
dtos.add(lm);
- metricIds.add(metric.getId());
+ metricUuids.add(metric.getUuid());
}
if (supportUpsert) {
@@ -130,7 +130,7 @@ public class PersistLiveMeasuresStep implements ComputationStep {
// The measures that no longer exist on the component must be deleted, for example
// when the coverage on a file goes to the "best value" 100%.
// The measures on deleted components are deleted by the step PurgeDatastoresStep
- dbClient.liveMeasureDao().deleteByComponentUuidExcludingMetricIds(dbSession, component.getUuid(), metricIds);
+ dbClient.liveMeasureDao().deleteByComponentUuidExcludingMetricUuids(dbSession, component.getUuid(), metricUuids);
} else {
dbClient.liveMeasureDao().deleteByComponent(dbSession, component.getUuid());
dtos.forEach(dto -> dbClient.liveMeasureDao().insert(dbSession, dto));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
index 885d68fcc84..391581f1267 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImplTest.java
@@ -81,12 +81,12 @@ public class MeasureComputerContextImplTest {
@Rule
public MetricRepositoryRule metricRepository = new MetricRepositoryRule()
- .add(1, CoreMetrics.NCLOC)
- .add(new MetricImpl(2, INT_METRIC_KEY, "int metric", Metric.MetricType.INT))
- .add(new MetricImpl(3, DOUBLE_METRIC_KEY, "double metric", Metric.MetricType.FLOAT))
- .add(new MetricImpl(4, LONG_METRIC_KEY, "long metric", Metric.MetricType.MILLISEC))
- .add(new MetricImpl(5, STRING_METRIC_KEY, "string metric", Metric.MetricType.STRING))
- .add(new MetricImpl(6, BOOLEAN_METRIC_KEY, "boolean metric", Metric.MetricType.BOOL));
+ .add("1", CoreMetrics.NCLOC)
+ .add(new MetricImpl("2", INT_METRIC_KEY, "int metric", Metric.MetricType.INT))
+ .add(new MetricImpl("3", DOUBLE_METRIC_KEY, "double metric", Metric.MetricType.FLOAT))
+ .add(new MetricImpl("4", LONG_METRIC_KEY, "long metric", Metric.MetricType.MILLISEC))
+ .add(new MetricImpl("5", STRING_METRIC_KEY, "string metric", Metric.MetricType.STRING))
+ .add(new MetricImpl("6", BOOLEAN_METRIC_KEY, "boolean metric", Metric.MetricType.BOOL));
@Rule
public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java
index 490784f2252..12f2854179d 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BatchMeasureToMeasureTest.java
@@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class BatchMeasureToMeasureTest {
- private static final Metric SOME_INT_METRIC = new MetricImpl(42, "int", "name", Metric.MetricType.INT);
- private static final Metric SOME_LONG_METRIC = new MetricImpl(42, "long", "name", Metric.MetricType.WORK_DUR);
- private static final Metric SOME_DOUBLE_METRIC = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT);
- private static final Metric SOME_STRING_METRIC = new MetricImpl(42, "string", "name", Metric.MetricType.STRING);
- private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl(42, "boolean", "name", Metric.MetricType.BOOL);
- private static final Metric SOME_LEVEL_METRIC = new MetricImpl(42, "level", "name", Metric.MetricType.LEVEL);
+ private static final Metric SOME_INT_METRIC = new MetricImpl("42", "int", "name", Metric.MetricType.INT);
+ private static final Metric SOME_LONG_METRIC = new MetricImpl("42", "long", "name", Metric.MetricType.WORK_DUR);
+ private static final Metric SOME_DOUBLE_METRIC = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT);
+ private static final Metric SOME_STRING_METRIC = new MetricImpl("42", "string", "name", Metric.MetricType.STRING);
+ private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl("42", "boolean", "name", Metric.MetricType.BOOL);
+ private static final Metric SOME_LEVEL_METRIC = new MetricImpl("42", "level", "name", Metric.MetricType.LEVEL);
private static final String SOME_DATA = "some_data man!";
private static final ScannerReport.Measure EMPTY_BATCH_MEASURE = ScannerReport.Measure.newBuilder().build();
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java
index eddc5f2bebf..b89fe5d4be5 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/BestValueOptimizationTest.java
@@ -175,7 +175,7 @@ public class BestValueOptimizationTest {
}
private static MetricImpl createMetric(Metric.MetricType metricType, double bestValue) {
- return new MetricImpl(metricType.hashCode() + (int) bestValue, "key" + metricType + bestValue, "name" + metricType + bestValue, metricType, null,
+ return new MetricImpl(metricType.name() + bestValue, "key" + metricType + bestValue, "name" + metricType + bestValue, metricType, null,
bestValue, true, false);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
index d58da081c93..03597999c70 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/LiveMeasureDtoToMeasureTest.java
@@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class LiveMeasureDtoToMeasureTest {
- private static final Metric SOME_INT_METRIC = new MetricImpl(42, "int", "name", Metric.MetricType.INT);
- private static final Metric SOME_LONG_METRIC = new MetricImpl(42, "long", "name", Metric.MetricType.WORK_DUR);
- private static final Metric SOME_DOUBLE_METRIC = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT);
- private static final Metric SOME_STRING_METRIC = new MetricImpl(42, "string", "name", Metric.MetricType.STRING);
- private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl(42, "boolean", "name", Metric.MetricType.BOOL);
- private static final Metric SOME_LEVEL_METRIC = new MetricImpl(42, "level", "name", Metric.MetricType.LEVEL);
+ private static final Metric SOME_INT_METRIC = new MetricImpl("42", "int", "name", Metric.MetricType.INT);
+ private static final Metric SOME_LONG_METRIC = new MetricImpl("42", "long", "name", Metric.MetricType.WORK_DUR);
+ private static final Metric SOME_DOUBLE_METRIC = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT);
+ private static final Metric SOME_STRING_METRIC = new MetricImpl("42", "string", "name", Metric.MetricType.STRING);
+ private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl("42", "boolean", "name", Metric.MetricType.BOOL);
+ private static final Metric SOME_LEVEL_METRIC = new MetricImpl("42", "level", "name", Metric.MetricType.LEVEL);
private static final String SOME_DATA = "some_data man!";
private static final String SOME_ALERT_TEXT = "some alert text_be_careFul!";
@@ -228,7 +228,7 @@ public class LiveMeasureDtoToMeasureTest {
@Test
public void toMeasure_should_not_loose_decimals_of_float_values() {
- MetricImpl metric = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
+ MetricImpl metric = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
LiveMeasureDto LiveMeasureDto = new LiveMeasureDto()
.setValue(0.12345);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
index 4b5b4ca3ef4..ab8b04dd67d 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepositoryTest.java
@@ -157,7 +157,7 @@ public class MapBasedRawMeasureRepositoryTest {
@Test
public void add_accepts_NO_VALUE_as_measure_arg() {
for (Metric.MetricType metricType : Metric.MetricType.values()) {
- underTest.add(FILE_COMPONENT, new MetricImpl(1, "key" + metricType, "name" + metricType, metricType), Measure.newMeasureBuilder().createNoValue());
+ underTest.add(FILE_COMPONENT, new MetricImpl("1", "key" + metricType, "name" + metricType, metricType), Measure.newMeasureBuilder().createNoValue());
}
}
@@ -170,7 +170,7 @@ public class MapBasedRawMeasureRepositoryTest {
}
try {
- final MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
+ final MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
underTest.update(FILE_COMPONENT, metric, measure);
fail("An IllegalArgumentException should have been raised");
@@ -185,7 +185,7 @@ public class MapBasedRawMeasureRepositoryTest {
@Test
public void update_accepts_NO_VALUE_as_measure_arg() {
for (Metric.MetricType metricType : Metric.MetricType.values()) {
- MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
+ MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
underTest.update(FILE_COMPONENT, metric, Measure.newMeasureBuilder().createNoValue());
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
index 56df4a21555..6410bda72ec 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureDtoToMeasureTest.java
@@ -37,12 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class MeasureDtoToMeasureTest {
- private static final Metric SOME_INT_METRIC = new MetricImpl(42, "int", "name", Metric.MetricType.INT);
- private static final Metric SOME_LONG_METRIC = new MetricImpl(42, "long", "name", Metric.MetricType.WORK_DUR);
- private static final Metric SOME_DOUBLE_METRIC = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT);
- private static final Metric SOME_STRING_METRIC = new MetricImpl(42, "string", "name", Metric.MetricType.STRING);
- private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl(42, "boolean", "name", Metric.MetricType.BOOL);
- private static final Metric SOME_LEVEL_METRIC = new MetricImpl(42, "level", "name", Metric.MetricType.LEVEL);
+ private static final Metric SOME_INT_METRIC = new MetricImpl("42", "int", "name", Metric.MetricType.INT);
+ private static final Metric SOME_LONG_METRIC = new MetricImpl("42", "long", "name", Metric.MetricType.WORK_DUR);
+ private static final Metric SOME_DOUBLE_METRIC = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT);
+ private static final Metric SOME_STRING_METRIC = new MetricImpl("42", "string", "name", Metric.MetricType.STRING);
+ private static final Metric SOME_BOOLEAN_METRIC = new MetricImpl("42", "boolean", "name", Metric.MetricType.BOOL);
+ private static final Metric SOME_LEVEL_METRIC = new MetricImpl("42", "level", "name", Metric.MetricType.LEVEL);
private static final String SOME_DATA = "some_data man!";
private static final String SOME_ALERT_TEXT = "some alert text_be_careFul!";
@@ -321,7 +321,7 @@ public class MeasureDtoToMeasureTest {
@Test
public void toMeasure_should_not_loose_decimals_of_float_values() {
- MetricImpl metric = new MetricImpl(42, "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
+ MetricImpl metric = new MetricImpl("42", "double", "name", Metric.MetricType.FLOAT, 5, null, false, false);
MeasureDto measureDto = new MeasureDto()
.setValue(0.12345);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java
index de490d77095..a43a7a4b006 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryImplTest.java
@@ -148,8 +148,8 @@ public class MeasureRepositoryImplTest {
SnapshotDto oldAnalysis = dbTester.components().insertSnapshot(project, t -> t.setLast(false));
MetricDto metric1 = dbTester.measures().insertMetric(t -> t.setValueType(org.sonar.api.measures.Metric.ValueType.STRING.name()));
MetricDto metric2 = dbTester.measures().insertMetric(t -> t.setValueType(org.sonar.api.measures.Metric.ValueType.STRING.name()));
- dbClient.measureDao().insert(dbSession, createMeasureDto(metric1.getId(), FILE_COMPONENT.getUuid(), lastAnalysis.getUuid()));
- dbClient.measureDao().insert(dbSession, createMeasureDto(metric1.getId(), FILE_COMPONENT.getUuid(), oldAnalysis.getUuid()));
+ dbClient.measureDao().insert(dbSession, createMeasureDto(metric1.getUuid(), FILE_COMPONENT.getUuid(), lastAnalysis.getUuid()));
+ dbClient.measureDao().insert(dbSession, createMeasureDto(metric1.getUuid(), FILE_COMPONENT.getUuid(), oldAnalysis.getUuid()));
dbSession.commit();
// metric 1 is associated to snapshot with "last=true"
@@ -162,7 +162,7 @@ public class MeasureRepositoryImplTest {
private Metric metricOf(MetricDto metricDto) {
Metric res = mock(Metric.class);
when(res.getKey()).thenReturn(metricDto.getKey());
- when(res.getId()).thenReturn(metricDto.getId());
+ when(res.getUuid()).thenReturn(metricDto.getUuid());
when(res.getType()).thenReturn(Metric.MetricType.valueOf(metricDto.getValueType()));
return res;
}
@@ -241,7 +241,7 @@ public class MeasureRepositoryImplTest {
@Test
public void add_accepts_NO_VALUE_as_measure_arg() {
for (Metric.MetricType metricType : Metric.MetricType.values()) {
- underTest.add(FILE_COMPONENT, new MetricImpl(1, "key" + metricType, "name" + metricType, metricType), Measure.newMeasureBuilder().createNoValue());
+ underTest.add(FILE_COMPONENT, new MetricImpl("1", "key" + metricType, "name" + metricType, metricType), Measure.newMeasureBuilder().createNoValue());
}
}
@@ -254,7 +254,7 @@ public class MeasureRepositoryImplTest {
}
try {
- final MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
+ final MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
underTest.update(FILE_COMPONENT, metric, measure);
fail("An IllegalArgumentException should have been raised");
@@ -269,7 +269,7 @@ public class MeasureRepositoryImplTest {
@Test
public void update_accepts_NO_VALUE_as_measure_arg() {
for (Metric.MetricType metricType : Metric.MetricType.values()) {
- MetricImpl metric = new MetricImpl(1, "key" + metricType, "name" + metricType, metricType);
+ MetricImpl metric = new MetricImpl("1", "key" + metricType, "name" + metricType, metricType);
underTest.add(FILE_COMPONENT, metric, getSomeMeasureByValueType(metricType));
underTest.update(FILE_COMPONENT, metric, Measure.newMeasureBuilder().createNoValue());
}
@@ -405,11 +405,11 @@ public class MeasureRepositoryImplTest {
assertThat(rawMeasures.get(METRIC_KEY_2)).extracting(Measure::getStringValue).isEqualTo("some value");
}
- private static MeasureDto createMeasureDto(int metricId, String componentUuid, String analysisUuid) {
+ private static MeasureDto createMeasureDto(String metricUuid, String componentUuid, String analysisUuid) {
return new MeasureDto()
.setComponentUuid(componentUuid)
.setAnalysisUuid(analysisUuid)
.setData(SOME_DATA)
- .setMetricId(metricId);
+ .setMetricUuid(metricUuid);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java
index 0d371c70921..e843a3b8b56 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureToMeasureDtoTest.java
@@ -39,16 +39,16 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(DataProviderRunner.class)
public class MeasureToMeasureDtoTest {
- private static final MetricImpl SOME_METRIC = new MetricImpl(42, "metric_key", "metric_name", Metric.MetricType.STRING);
+ private static final MetricImpl SOME_METRIC = new MetricImpl("42", "metric_key", "metric_name", Metric.MetricType.STRING);
private static final String SOME_DATA = "some_data";
private static final String SOME_STRING = "some_string";
private static final double SOME_VARIATIONS = 1d;
- private static final MetricImpl SOME_BOOLEAN_METRIC = new MetricImpl(1, "1", "1", Metric.MetricType.BOOL);
- private static final MetricImpl SOME_INT_METRIC = new MetricImpl(2, "2", "2", Metric.MetricType.INT);
- private static final MetricImpl SOME_LONG_METRIC = new MetricImpl(3, "3", "3", Metric.MetricType.DISTRIB);
- private static final MetricImpl SOME_DOUBLE_METRIC = new MetricImpl(4, "4", "4", Metric.MetricType.FLOAT);
- private static final MetricImpl SOME_STRING_METRIC = new MetricImpl(5, "5", "5", Metric.MetricType.STRING);
- private static final MetricImpl SOME_LEVEL_METRIC = new MetricImpl(6, "6", "6", Metric.MetricType.LEVEL);
+ private static final MetricImpl SOME_BOOLEAN_METRIC = new MetricImpl("1", "1", "1", Metric.MetricType.BOOL);
+ private static final MetricImpl SOME_INT_METRIC = new MetricImpl("2", "2", "2", Metric.MetricType.INT);
+ private static final MetricImpl SOME_LONG_METRIC = new MetricImpl("3", "3", "3", Metric.MetricType.DISTRIB);
+ private static final MetricImpl SOME_DOUBLE_METRIC = new MetricImpl("4", "4", "4", Metric.MetricType.FLOAT);
+ private static final MetricImpl SOME_STRING_METRIC = new MetricImpl("5", "5", "5", Metric.MetricType.STRING);
+ private static final MetricImpl SOME_LEVEL_METRIC = new MetricImpl("6", "6", "6", Metric.MetricType.LEVEL);
private static final String ANALYSIS_UUID = "a1";
private static final Component SOME_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("uuid_1").build();
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java
index 8beec66f3f4..508dff3a3cc 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/qualitygatedetails/QualityGateDetailsDataTest.java
@@ -52,7 +52,7 @@ public class QualityGateDetailsDataTest {
@Test
public void verify_json_for_each_type_of_condition() {
String value = "actualValue";
- Condition condition = new Condition(new MetricImpl(1, "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
+ Condition condition = new Condition(new MetricImpl("1", "key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(
new EvaluatedCondition(condition, Measure.Level.OK, value),
new EvaluatedCondition(condition, Measure.Level.ERROR, value));
@@ -82,7 +82,7 @@ public class QualityGateDetailsDataTest {
@Test
public void verify_json_for_condition_on_leak_metric() {
String value = "actualValue";
- Condition condition = new Condition(new MetricImpl(1, "new_key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
+ Condition condition = new Condition(new MetricImpl("1", "new_key1", "name1", Metric.MetricType.STRING), Condition.Operator.GREATER_THAN.getDbValue(), "errorTh");
ImmutableList<EvaluatedCondition> evaluatedConditions = ImmutableList.of(
new EvaluatedCondition(condition, Measure.Level.OK, value),
new EvaluatedCondition(condition, Measure.Level.ERROR, value));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java
index 91148afc82e..a92e99a9582 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricDtoToMetricTest.java
@@ -41,7 +41,7 @@ public class MetricDtoToMetricTest {
MetricDto metricDto = createMetricDto(metricType);
Metric metric = underTest.apply(metricDto);
- assertThat(metric.getId()).isEqualTo(metricDto.getId());
+ assertThat(metric.getUuid()).isEqualTo(metricDto.getUuid());
assertThat(metric.getKey()).isEqualTo(metricDto.getKey());
assertThat(metric.getName()).isEqualTo(metricDto.getShortName());
assertThat(metric.getType()).isEqualTo(metricType);
@@ -59,12 +59,12 @@ public class MetricDtoToMetricTest {
@Test(expected = IllegalArgumentException.class)
public void apply_throws_IAE_if_valueType_can_not_be_parsed() {
- underTest.apply(new MetricDto().setId(1).setKey("key").setValueType("trololo"));
+ underTest.apply(new MetricDto().setUuid("1").setKey("key").setValueType("trololo"));
}
private static MetricDto createMetricDto(Metric.MetricType metricType) {
return new MetricDto()
- .setId(metricType.name().hashCode())
+ .setUuid(metricType.name())
.setKey(metricType.name() + "_key")
.setShortName(metricType.name() + "_name")
.setValueType(metricType.name())
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java
index b04dbf15400..9fbc02a32cd 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricImplTest.java
@@ -29,23 +29,23 @@ public class MetricImplTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private static final int SOME_ID = 42;
+ private static final String SOME_UUID = "uuid";
private static final String SOME_KEY = "key";
private static final String SOME_NAME = "name";
@Test(expected = NullPointerException.class)
public void constructor_throws_NPE_if_key_arg_is_null() {
- new MetricImpl(SOME_ID, null, SOME_NAME, Metric.MetricType.BOOL);
+ new MetricImpl(SOME_UUID, null, SOME_NAME, Metric.MetricType.BOOL);
}
@Test(expected = NullPointerException.class)
public void constructor_throws_NPE_if_name_arg_is_null() {
- new MetricImpl(SOME_ID, SOME_KEY, null, Metric.MetricType.BOOL);
+ new MetricImpl(SOME_UUID, SOME_KEY, null, Metric.MetricType.BOOL);
}
@Test(expected = NullPointerException.class)
public void constructor_throws_NPE_if_valueType_arg_is_null() {
- new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, null);
+ new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, null);
}
@Test
@@ -53,14 +53,14 @@ public class MetricImplTest {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("A BestValue must be specified if Metric is bestValueOptimized");
- new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.INT, 1, null, true, false);
+ new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.INT, 1, null, true, false);
}
@Test
public void verify_getters() {
- MetricImpl metric = new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT);
+ MetricImpl metric = new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT);
- assertThat(metric.getId()).isEqualTo(SOME_ID);
+ assertThat(metric.getUuid()).isEqualTo(SOME_UUID);
assertThat(metric.getKey()).isEqualTo(SOME_KEY);
assertThat(metric.getName()).isEqualTo(SOME_NAME);
assertThat(metric.getType()).isEqualTo(Metric.MetricType.FLOAT);
@@ -68,27 +68,27 @@ public class MetricImplTest {
@Test
public void equals_uses_only_key() {
- MetricImpl expected = new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT);
+ MetricImpl expected = new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT)).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING)).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING, null, 0d, true, true)).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING, null, null, false, false)).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, "some other key", SOME_NAME, Metric.MetricType.FLOAT)).isNotEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT)).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING)).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING, null, 0d, true, true)).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.STRING, null, null, false, false)).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, "some other key", SOME_NAME, Metric.MetricType.FLOAT)).isNotEqualTo(expected);
}
@Test
public void hashcode_uses_only_key() {
- int expected = new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT).hashCode();
+ int expected = new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT).hashCode();
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, "some other name", Metric.MetricType.FLOAT).hashCode()).isEqualTo(expected);
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, "some other name", Metric.MetricType.BOOL).hashCode()).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, "some other name", Metric.MetricType.FLOAT).hashCode()).isEqualTo(expected);
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, "some other name", Metric.MetricType.BOOL).hashCode()).isEqualTo(expected);
}
@Test
public void all_fields_are_displayed_in_toString() {
- assertThat(new MetricImpl(SOME_ID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT, 1, 951d, true, false).toString())
- .isEqualTo("MetricImpl{id=42, key=key, name=name, type=FLOAT, bestValue=951.0, bestValueOptimized=true, deleteHistoricalData=false}");
+ assertThat(new MetricImpl(SOME_UUID, SOME_KEY, SOME_NAME, Metric.MetricType.FLOAT, 1, 951d, true, false).toString())
+ .isEqualTo("MetricImpl{uuid=uuid, key=key, name=name, type=FLOAT, bestValue=951.0, bestValueOptimized=true, deleteHistoricalData=false}");
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java
index d2558965afe..2664e20d12d 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryImplTest.java
@@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class MetricRepositoryImplTest {
private static final String SOME_KEY = "some_key";
- private static final long SOME_ID = 156;
+ private static final String SOME_UUID = "uuid";
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -87,8 +87,8 @@ public class MetricRepositoryImplTest {
underTest.start();
- assertThat(underTest.getByKey("ncloc").getId()).isEqualTo(ncloc.getId());
- assertThat(underTest.getByKey("coverage").getId()).isEqualTo(coverage.getId());
+ assertThat(underTest.getByKey("ncloc").getUuid()).isEqualTo(ncloc.getUuid());
+ assertThat(underTest.getByKey("coverage").getUuid()).isEqualTo(coverage.getUuid());
}
@Test
@@ -96,7 +96,7 @@ public class MetricRepositoryImplTest {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Metric cache has not been initialized");
- underTest.getById(SOME_ID);
+ underTest.getByUuid(SOME_UUID);
}
@Test
@@ -104,9 +104,9 @@ public class MetricRepositoryImplTest {
underTest.start();
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(String.format("Metric with id '%s' does not exist", SOME_ID));
+ expectedException.expectMessage(String.format("Metric with uuid '%s' does not exist", SOME_UUID));
- underTest.getById(SOME_ID);
+ underTest.getByUuid(SOME_UUID);
}
@Test
@@ -116,9 +116,9 @@ public class MetricRepositoryImplTest {
underTest.start();
expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(String.format("Metric with id '%s' does not exist", SOME_ID));
+ expectedException.expectMessage(String.format("Metric with uuid '%s' does not exist", SOME_UUID));
- underTest.getById(SOME_ID);
+ underTest.getByUuid(SOME_UUID);
}
@Test
@@ -128,8 +128,8 @@ public class MetricRepositoryImplTest {
underTest.start();
- assertThat(underTest.getById(ncloc.getId()).getKey()).isEqualTo("ncloc");
- assertThat(underTest.getById(coverage.getId()).getKey()).isEqualTo("coverage");
+ assertThat(underTest.getByUuid(ncloc.getUuid()).getKey()).isEqualTo("ncloc");
+ assertThat(underTest.getByUuid(coverage.getUuid()).getKey()).isEqualTo("coverage");
}
@Test
@@ -137,14 +137,14 @@ public class MetricRepositoryImplTest {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Metric cache has not been initialized");
- underTest.getOptionalById(SOME_ID);
+ underTest.getOptionalByUuid(SOME_UUID);
}
@Test
public void getOptionalById_returns_empty_of_Metric_does_not_exist() {
underTest.start();
- assertThat(underTest.getOptionalById(SOME_ID)).isEmpty();
+ assertThat(underTest.getOptionalByUuid(SOME_UUID)).isEmpty();
}
@Test
@@ -153,7 +153,7 @@ public class MetricRepositoryImplTest {
underTest.start();
- assertThat(underTest.getOptionalById(SOME_ID)).isEmpty();
+ assertThat(underTest.getOptionalByUuid(SOME_UUID)).isEmpty();
}
@Test
@@ -163,8 +163,8 @@ public class MetricRepositoryImplTest {
underTest.start();
- assertThat(underTest.getOptionalById(ncloc.getId()).get().getKey()).isEqualTo("ncloc");
- assertThat(underTest.getOptionalById(coverage.getId()).get().getKey()).isEqualTo("coverage");
+ assertThat(underTest.getOptionalByUuid(ncloc.getUuid()).get().getKey()).isEqualTo("ncloc");
+ assertThat(underTest.getOptionalByUuid(coverage.getUuid()).get().getKey()).isEqualTo("coverage");
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
index 84f358b9c58..c3d542a2efa 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/ConditionEvaluatorTest.java
@@ -216,10 +216,10 @@ public class ConditionEvaluatorTest {
}
private static MetricImpl createMetric(MetricType metricType) {
- return new MetricImpl(1, "key", "name", metricType);
+ return new MetricImpl("1", "key", "name", metricType);
}
private static MetricImpl createNewMetric(MetricType metricType) {
- return new MetricImpl(1, "new_key", "name", metricType);
+ return new MetricImpl("1", "new_key", "name", metricType);
}
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java
index fa22401668e..1c9fdb11e6e 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/EvaluationResultTextConverterTest.java
@@ -40,8 +40,8 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
@RunWith(DataProviderRunner.class)
public class EvaluationResultTextConverterTest {
- private static final Metric INT_METRIC = new MetricImpl(1, "key", "int_metric_name", Metric.MetricType.INT);
- private static final Metric SOME_VARIATION_METRIC = new MetricImpl(2, "new_variation_of_trololo", "variation_of_trololo_name", Metric.MetricType.INT);
+ private static final Metric INT_METRIC = new MetricImpl("1", "key", "int_metric_name", Metric.MetricType.INT);
+ private static final Metric SOME_VARIATION_METRIC = new MetricImpl("2", "new_variation_of_trololo", "variation_of_trololo_name", Metric.MetricType.INT);
private static final Condition LT_10_CONDITION = new Condition(INT_METRIC, Condition.Operator.LESS_THAN.getDbValue(), "10");
private static final EvaluationResult OK_EVALUATION_RESULT = new EvaluationResult(Measure.Level.OK, null);
private static final String ERROR_THRESHOLD = "error_threshold";
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java
index 29e1fff586c..2e559ec8d95 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java
@@ -45,13 +45,13 @@ public class QualityGateServiceImplTest {
private static final long SOME_ID = 123;
private static final String SOME_NAME = "some name";
private static final QualityGateDto QUALITY_GATE_DTO = new QualityGateDto().setId(SOME_ID).setName(SOME_NAME);
- private static final long METRIC_ID_1 = 951;
- private static final long METRIC_ID_2 = 753;
+ private static final String METRIC_UUID_1 = "uuid1";
+ private static final String METRIC_UUID_2 = "uuid2";
private static final Metric METRIC_1 = mock(Metric.class);
private static final Metric METRIC_2 = mock(Metric.class);
- private static final QualityGateConditionDto CONDITION_1 = new QualityGateConditionDto().setUuid("321").setMetricId(METRIC_ID_1).setOperator("LT")
+ private static final QualityGateConditionDto CONDITION_1 = new QualityGateConditionDto().setUuid("321").setMetricUuid(METRIC_UUID_1).setOperator("LT")
.setErrorThreshold("error_th");
- private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setUuid("456").setMetricId(METRIC_ID_2).setOperator("GT")
+ private static final QualityGateConditionDto CONDITION_2 = new QualityGateConditionDto().setUuid("456").setMetricUuid(METRIC_UUID_2).setOperator("GT")
.setErrorThreshold("error_th");
private QualityGateDao qualityGateDao = mock(QualityGateDao.class);
@@ -92,8 +92,8 @@ public class QualityGateServiceImplTest {
when(qualityGateDao.selectById(any(), eq(SOME_ID))).thenReturn(QUALITY_GATE_DTO);
when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
// metrics are always supposed to be there
- when(metricRepository.getOptionalById(METRIC_ID_1)).thenReturn(Optional.of(METRIC_1));
- when(metricRepository.getOptionalById(METRIC_ID_2)).thenReturn(Optional.of(METRIC_2));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.of(METRIC_1));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
Optional<QualityGate> res = underTest.findById(SOME_ID);
@@ -110,8 +110,8 @@ public class QualityGateServiceImplTest {
when(qualityGateDao.selectById(any(), eq(SOME_ID))).thenReturn(QUALITY_GATE_DTO);
when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
// metrics are always supposed to be there
- when(metricRepository.getOptionalById(METRIC_ID_1)).thenReturn(Optional.empty());
- when(metricRepository.getOptionalById(METRIC_ID_2)).thenReturn(Optional.of(METRIC_2));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty());
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
Optional<QualityGate> res = underTest.findById(SOME_ID);
@@ -136,8 +136,8 @@ public class QualityGateServiceImplTest {
qGateWithOrgDto.setName(QUALITY_GATE_DTO.getName());
when(qualityGateDao.selectByOrganizationAndUuid(any(), any(), any())).thenReturn(qGateWithOrgDto);
when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
- when(metricRepository.getOptionalById(METRIC_ID_1)).thenReturn(Optional.empty());
- when(metricRepository.getOptionalById(METRIC_ID_2)).thenReturn(Optional.of(METRIC_2));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty());
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
QualityGate result = underTest.findDefaultQualityGate(mock(Organization.class));
@@ -161,8 +161,8 @@ public class QualityGateServiceImplTest {
qGateWithOrgDto.setName(QUALITY_GATE_DTO.getName());
when(qualityGateDao.selectByProjectUuid(any(), any())).thenReturn(qGateWithOrgDto);
when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2));
- when(metricRepository.getOptionalById(METRIC_ID_1)).thenReturn(Optional.empty());
- when(metricRepository.getOptionalById(METRIC_ID_2)).thenReturn(Optional.of(METRIC_2));
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty());
+ when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2));
Optional<QualityGate> result = underTest.findQualityGate(mock(Project.class));
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java
index da468a57707..2945418a715 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/CustomMeasuresCopyStepTest.java
@@ -70,8 +70,8 @@ public class CustomMeasuresCopyStepTest {
private static final int SUBVIEW_REF = 101;
private static final int PROJECT_VIEW_REF = 1011;
- private static final Metric FLOAT_METRIC = new MetricImpl(10, "float_metric", "Float Metric", Metric.MetricType.FLOAT);
- private static final Metric STRING_METRIC = new MetricImpl(11, "string_metric", "String Metric", Metric.MetricType.STRING);
+ private static final Metric FLOAT_METRIC = new MetricImpl("10", "float_metric", "Float Metric", Metric.MetricType.FLOAT);
+ private static final Metric STRING_METRIC = new MetricImpl("11", "string_metric", "String Metric", Metric.MetricType.STRING);
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@@ -144,35 +144,35 @@ public class CustomMeasuresCopyStepTest {
public void test_float_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setValue(10.0);
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.FLOAT)).getDoubleValue()).isEqualTo(10.0);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.FLOAT)).getDoubleValue()).isEqualTo(10.0);
}
@Test
public void test_int_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setValue(10.0);
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.INT)).getIntValue()).isEqualTo(10);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.INT)).getIntValue()).isEqualTo(10);
}
@Test
public void test_long_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setValue(10.0);
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.WORK_DUR)).getLongValue()).isEqualTo(10);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.WORK_DUR)).getLongValue()).isEqualTo(10);
}
@Test
public void test_percent_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setValue(10.0);
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.PERCENT)).getDoubleValue()).isEqualTo(10);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.PERCENT)).getDoubleValue()).isEqualTo(10);
}
@Test
public void test_string_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue("foo");
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.STRING)).getStringValue()).isEqualTo("foo");
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.STRING)).getStringValue()).isEqualTo("foo");
}
@Test
@@ -180,7 +180,7 @@ public class CustomMeasuresCopyStepTest {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue(null);
- Measure measure = dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.STRING));
+ Measure measure = dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.STRING));
assertThat(measure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
}
@@ -189,7 +189,7 @@ public class CustomMeasuresCopyStepTest {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue(null);
- Measure measure = dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.DATA));
+ Measure measure = dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.DATA));
assertThat(measure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
}
@@ -198,7 +198,7 @@ public class CustomMeasuresCopyStepTest {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue(null);
- Measure measure = dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.DISTRIB));
+ Measure measure = dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.DISTRIB));
assertThat(measure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
}
@@ -206,12 +206,12 @@ public class CustomMeasuresCopyStepTest {
public void test_LEVEL_metric_type() {
CustomMeasureDto dto = new CustomMeasureDto();
dto.setTextValue("OK");
- assertThat(dtoToMeasure(dto, new MetricImpl(1, "m", "M", Metric.MetricType.LEVEL)).getLevelValue()).isEqualTo(Measure.Level.OK);
+ assertThat(dtoToMeasure(dto, new MetricImpl("1", "m", "M", Metric.MetricType.LEVEL)).getLevelValue()).isEqualTo(Measure.Level.OK);
}
@Test
public void test_boolean_metric_type() {
- MetricImpl booleanMetric = new MetricImpl(1, "m", "M", Metric.MetricType.BOOL);
+ MetricImpl booleanMetric = new MetricImpl("1", "m", "M", Metric.MetricType.BOOL);
CustomMeasureDto dto = new CustomMeasureDto();
assertThat(dtoToMeasure(dto.setValue(1.0), booleanMetric).getBooleanValue()).isTrue();
assertThat(dtoToMeasure(dto.setValue(0.0), booleanMetric).getBooleanValue()).isFalse();
@@ -232,7 +232,7 @@ public class CustomMeasuresCopyStepTest {
private void insertCustomMeasure(String componentUuid, Metric metric, double value) {
dbTester.getDbClient().customMeasureDao().insert(dbTester.getSession(), CustomMeasureTesting.newCustomMeasureDto()
.setComponentUuid(componentUuid)
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setValue(value));
dbTester.getSession().commit();
}
@@ -240,7 +240,7 @@ public class CustomMeasuresCopyStepTest {
private void insertCustomMeasure(String componentUuid, Metric metric, String value) {
dbTester.getDbClient().customMeasureDao().insert(dbTester.getSession(), CustomMeasureTesting.newCustomMeasureDto()
.setComponentUuid(componentUuid)
- .setMetricId(metric.getId())
+ .setMetricUuid(metric.getUuid())
.setTextValue(value));
dbTester.getSession().commit();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java
index f4affe8eaf0..343008874ad 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ExecuteVisitorsStepTest.java
@@ -62,8 +62,8 @@ public class ExecuteVisitorsStepTest {
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Rule
public MetricRepositoryRule metricRepository = new MetricRepositoryRule()
- .add(1, NCLOC)
- .add(new MetricImpl(2, TEST_METRIC_KEY, "name", Metric.MetricType.INT));
+ .add("1", NCLOC)
+ .add(new MetricImpl("2", TEST_METRIC_KEY, "name", Metric.MetricType.INT));
@Rule
public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
@Rule
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java
index 8e1723ca81f..56ccfae2e96 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java
@@ -61,8 +61,8 @@ public class LoadQualityGateStepTest {
@Test
public void filter_conditions_on_pull_request() {
- Metric newMetric = new MetricImpl(1, "new_key", "name", Metric.MetricType.INT);
- Metric metric = new MetricImpl(2, "key", "name", Metric.MetricType.INT);
+ Metric newMetric = new MetricImpl("1", "new_key", "name", Metric.MetricType.INT);
+ Metric metric = new MetricImpl("2", "key", "name", Metric.MetricType.INT);
Condition variation = new Condition(newMetric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
Condition condition = new Condition(metric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0");
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java
index 6beeacc4581..a5c16b02745 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStepTest.java
@@ -85,7 +85,7 @@ public class PersistDuplicationDataStepTest extends BaseStepTest {
insertComponent(FILE_1_KEY, FILE_1_UUID);
insertComponent(FILE_2_KEY, FILE_2_UUID);
db.commit();
- metricRepository.add(metric.getId(), new Metric.Builder(DUPLICATIONS_DATA_KEY, DUPLICATIONS_DATA_KEY, Metric.ValueType.STRING).create());
+ metricRepository.add(metric.getUuid(), new Metric.Builder(DUPLICATIONS_DATA_KEY, DUPLICATIONS_DATA_KEY, Metric.ValueType.STRING).create());
}
@Override
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
index 9a6c5d8bca7..1a4d2716938 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
@@ -86,9 +86,9 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest {
MetricDto intMetricDto = db.measures().insertMetric(m -> m.setKey(INT_METRIC.getKey()).setValueType(Metric.ValueType.INT.name()));
MetricDto bestValueMMetricDto = db.measures()
.insertMetric(m -> m.setKey(METRIC_WITH_BEST_VALUE.getKey()).setValueType(Metric.ValueType.INT.name()).setOptimizedBestValue(true).setBestValue(0.0));
- metricRepository.add(stringMetricDto.getId(), STRING_METRIC);
- metricRepository.add(intMetricDto.getId(), INT_METRIC);
- metricRepository.add(bestValueMMetricDto.getId(), METRIC_WITH_BEST_VALUE);
+ metricRepository.add(stringMetricDto.getUuid(), STRING_METRIC);
+ metricRepository.add(intMetricDto.getUuid(), INT_METRIC);
+ metricRepository.add(bestValueMMetricDto.getUuid(), METRIC_WITH_BEST_VALUE);
}
@Test
@@ -204,14 +204,14 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest {
LiveMeasureDto measure = newLiveMeasure()
.setComponentUuid(componentUuid)
.setProjectUuid(projectUuid)
- .setMetricId(metricRepository.getByKey(metric.getKey()).getId());
+ .setMetricUuid(metricRepository.getByKey(metric.getKey()).getUuid());
dbClient.liveMeasureDao().insertOrUpdate(db.getSession(), measure);
return measure;
}
private void assertThatMeasureHasValue(LiveMeasureDto template, int expectedValue) {
Optional<LiveMeasureDto> persisted = dbClient.liveMeasureDao().selectMeasure(db.getSession(),
- template.getComponentUuid(), metricRepository.getById(template.getMetricId()).getKey());
+ template.getComponentUuid(), metricRepository.getByUuid(template.getMetricUuid()).getKey());
assertThat(persisted).isPresent();
assertThat(persisted.get().getValue()).isEqualTo((double) expectedValue);
}
@@ -225,7 +225,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest {
private void assertThatMeasureDoesNotExist(LiveMeasureDto template) {
assertThat(dbClient.liveMeasureDao().selectMeasure(db.getSession(),
- template.getComponentUuid(), metricRepository.getById(template.getMetricId()).getKey()))
+ template.getComponentUuid(), metricRepository.getByUuid(template.getMetricUuid()).getKey()))
.isEmpty();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java
index 58a9f094078..9ffa01abcad 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistMeasuresStepTest.java
@@ -82,9 +82,9 @@ public class PersistMeasuresStepTest extends BaseStepTest {
MetricDto stringMetricDto = db.measures().insertMetric(m -> m.setKey(STRING_METRIC.getKey()).setValueType(Metric.ValueType.STRING.name()));
MetricDto intMetricDto = db.measures().insertMetric(m -> m.setKey(INT_METRIC.getKey()).setValueType(Metric.ValueType.INT.name()));
MetricDto nhMetricDto = db.measures().insertMetric(m -> m.setKey(NON_HISTORICAL_METRIC.getKey()).setValueType(Metric.ValueType.INT.name()));
- metricRepository.add(stringMetricDto.getId(), STRING_METRIC);
- metricRepository.add(intMetricDto.getId(), INT_METRIC);
- metricRepository.add(nhMetricDto.getId(), NON_HISTORICAL_METRIC);
+ metricRepository.add(stringMetricDto.getUuid(), STRING_METRIC);
+ metricRepository.add(intMetricDto.getUuid(), INT_METRIC);
+ metricRepository.add(nhMetricDto.getUuid(), NON_HISTORICAL_METRIC);
}
@Test
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
index 8657135ce4c..2a4f77aec44 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java
@@ -286,7 +286,7 @@ public class QualityGateMeasuresStepTest {
}
private static MetricImpl createIntMetric(int index) {
- return new MetricImpl(index, "metricKey" + index, "metricName" + index, Metric.MetricType.INT);
+ return new MetricImpl("uuid" + index, "metricKey" + index, "metricName" + index, Metric.MetricType.INT);
}
private static class QualityGateStatusHolderAssertions extends AbstractAssert<QualityGateStatusHolderAssertions, QualityGateStatusHolder> {
diff --git a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java
index 151eb479c8f..6fa8c22b912 100644
--- a/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java
+++ b/server/sonar-ce-task-projectanalysis/src/testFixtures/java/org/sonar/ce/task/projectanalysis/metric/MetricRepositoryRule.java
@@ -30,14 +30,14 @@ import static java.util.Objects.requireNonNull;
public class MetricRepositoryRule extends ExternalResource implements MetricRepository {
private final Map<String, Metric> metricsByKey = new HashMap<>();
- private final Map<Long, Metric> metricsById = new HashMap<>();
+ private final Map<String, Metric> metricsByUuid = new HashMap<>();
/**
* Convenience method to add a {@link Metric} to the repository created from a {@link org.sonar.api.measures.Metric},
* most of the time it will be a constant of the {@link org.sonar.api.measures.CoreMetrics} class.
* <p>
* For the id of the created metric, this method uses the hashCode of the metric's key. If you want to specify
- * the id of the create {@link Metric}, use {@link #add(int, org.sonar.api.measures.Metric)}
+ * the id of the create {@link Metric}, use {@link #add(String, org.sonar.api.measures.Metric)}
* </p>
*/
public MetricRepositoryRule add(org.sonar.api.measures.Metric<?> coreMetric) {
@@ -50,18 +50,18 @@ public class MetricRepositoryRule extends ExternalResource implements MetricRepo
* and with the specified id, most of the time it will be a constant of the {@link org.sonar.api.measures.CoreMetrics}
* class.
*/
- public MetricRepositoryRule add(int id, org.sonar.api.measures.Metric<?> coreMetric) {
- add(from(id, coreMetric));
+ public MetricRepositoryRule add(String uuid, org.sonar.api.measures.Metric<?> coreMetric) {
+ add(from(uuid, coreMetric));
return this;
}
private static Metric from(org.sonar.api.measures.Metric<?> coreMetric) {
- return from(coreMetric.getKey().hashCode(), coreMetric);
+ return from(Long.toString(coreMetric.getKey().hashCode()), coreMetric);
}
- private static Metric from(int id, org.sonar.api.measures.Metric<?> coreMetric) {
+ private static Metric from(String uuid, org.sonar.api.measures.Metric<?> coreMetric) {
return new MetricImpl(
- id, coreMetric.getKey(), coreMetric.getName(),
+ uuid, coreMetric.getKey(), coreMetric.getName(),
convert(coreMetric.getType()),
coreMetric.getDecimalScale(),
coreMetric.getBestValue(), coreMetric.isOptimizedBestValue(), coreMetric.getDeleteHistoricalData());
@@ -75,18 +75,18 @@ public class MetricRepositoryRule extends ExternalResource implements MetricRepo
requireNonNull(metric.getKey(), "key can not be null");
checkState(!metricsByKey.containsKey(metric.getKey()), format("Repository already contains a metric for key %s", metric.getKey()));
- checkState(!metricsById.containsKey((long) metric.getId()), format("Repository already contains a metric for id %s", metric.getId()));
+ checkState(!metricsByUuid.containsKey(metric.getUuid()), format("Repository already contains a metric for id %s", metric.getUuid()));
metricsByKey.put(metric.getKey(), metric);
- metricsById.put((long) metric.getId(), metric);
+ metricsByUuid.put(metric.getUuid(), metric);
return this;
}
@Override
protected void after() {
- this.metricsById.clear();
- this.metricsById.clear();
+ this.metricsByUuid.clear();
+ this.metricsByUuid.clear();
}
@Override
@@ -97,15 +97,15 @@ public class MetricRepositoryRule extends ExternalResource implements MetricRepo
}
@Override
- public Metric getById(long id) {
- Metric res = metricsById.get(id);
- checkState(res != null, format("No Metric can be found for id %s", id));
+ public Metric getByUuid(String uuid) {
+ Metric res = metricsByUuid.get(uuid);
+ checkState(res != null, format("No Metric can be found for uuid %s", uuid));
return res;
}
@Override
- public Optional<Metric> getOptionalById(long id) {
- return Optional.of(metricsById.get(id));
+ public Optional<Metric> getOptionalByUuid(String uuid) {
+ return Optional.of(metricsByUuid.get(uuid));
}
@Override