Skip to content

Commit

Permalink
SONAR-7688 table PROJECT_MEASURES should use component UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof committed Jun 14, 2016
1 parent f16a04f commit a115682
Show file tree
Hide file tree
Showing 52 changed files with 1,216 additions and 182 deletions.
Expand Up @@ -39,7 +39,7 @@ public MeasureToMeasureDto(DbIdsRepository dbIdsRepository) {
public MeasureDto toMeasureDto(Measure measure, Metric metric, Component component) { public MeasureDto toMeasureDto(Measure measure, Metric metric, Component component) {
MeasureDto out = new MeasureDto(); MeasureDto out = new MeasureDto();
out.setMetricId(metric.getId()); out.setMetricId(metric.getId());
out.setComponentId(dbIdsRepository.getComponentId(component)); out.setComponentUuid(component.getUuid());
out.setSnapshotId(dbIdsRepository.getSnapshotId(component)); out.setSnapshotId(dbIdsRepository.getSnapshotId(component));
if (measure.hasVariations()) { if (measure.hasVariations()) {
setVariations(out, measure.getVariations()); setVariations(out, measure.getVariations());
Expand Down
Expand Up @@ -34,13 +34,11 @@
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.System2; import org.sonar.api.utils.System2;
import org.sonar.db.DbClient; import org.sonar.db.DbClient;
import org.sonar.db.DbSession; import org.sonar.db.DbSession;
import org.sonar.db.DbTester; import org.sonar.db.DbTester;
import org.sonar.db.measure.MeasureDto; import org.sonar.db.measure.MeasureDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue; import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue;
import org.sonar.server.computation.batch.BatchReportReader; import org.sonar.server.computation.batch.BatchReportReader;
Expand Down Expand Up @@ -84,10 +82,9 @@ public class MeasureRepositoryImplTest {
private final Metric metric2 = mock(Metric.class); private final Metric metric2 = mock(Metric.class);
private static final long LAST_SNAPSHOT_ID = 123; private static final long LAST_SNAPSHOT_ID = 123;
private static final long OTHER_SNAPSHOT_ID = 369; private static final long OTHER_SNAPSHOT_ID = 369;
private static final long COMPONENT_ID = 567; private static final String COMPONENT_UUID = "UUID1";
private static final Measure SOME_MEASURE = Measure.newMeasureBuilder().create("some value"); private static final Measure SOME_MEASURE = Measure.newMeasureBuilder().create("some value");
private static final String SOME_DATA = "some data"; private static final String SOME_DATA = "some data";
private static final RuleDto SOME_RULE = RuleDto.createFor(RuleKey.of("A", "1")).setId(963);


private ReportMetricValidator reportMetricValidator = mock(ReportMetricValidator.class); private ReportMetricValidator reportMetricValidator = mock(ReportMetricValidator.class);


Expand Down Expand Up @@ -143,8 +140,8 @@ public void getBaseMeasure_returns_absent_if_measure_does_not_exist_in_DB() {
@Test @Test
public void getBaseMeasure_returns_Measure_if_measure_of_last_snapshot_only_in_DB() { public void getBaseMeasure_returns_Measure_if_measure_of_last_snapshot_only_in_DB() {
dbTester.prepareDbUnit(getClass(), "shared.xml"); dbTester.prepareDbUnit(getClass(), "shared.xml");
dbClient.measureDao().insert(dbSession, createMeasureDto(METRIC_ID_1, LAST_SNAPSHOT_ID)); dbClient.measureDao().insert(dbSession, createMeasureDto(METRIC_ID_1, FILE_COMPONENT.getUuid(), LAST_SNAPSHOT_ID));
dbClient.measureDao().insert(dbSession, createMeasureDto(METRIC_ID_2, OTHER_SNAPSHOT_ID)); dbClient.measureDao().insert(dbSession, createMeasureDto(METRIC_ID_2, FILE_COMPONENT.getUuid(), OTHER_SNAPSHOT_ID));
dbSession.commit(); dbSession.commit();


// metric 1 is associated to snapshot with "last=true" // metric 1 is associated to snapshot with "last=true"
Expand Down Expand Up @@ -419,9 +416,9 @@ public void getRawMeasures_returns_added_measures_over_batch_measures() {
assertThat(rawMeasures.get(METRIC_KEY_2)).containsOnly(Measure.newMeasureBuilder().create("some value")); assertThat(rawMeasures.get(METRIC_KEY_2)).containsOnly(Measure.newMeasureBuilder().create("some value"));
} }


private static MeasureDto createMeasureDto(int metricId, long snapshotId) { private static MeasureDto createMeasureDto(int metricId, String componentUuid, long snapshotId) {
return new MeasureDto() return new MeasureDto()
.setComponentId(COMPONENT_ID) .setComponentUuid(componentUuid)
.setSnapshotId(snapshotId) .setSnapshotId(snapshotId)
.setData(SOME_DATA) .setData(SOME_DATA)
.setMetricId(metricId); .setMetricId(metricId);
Expand Down
Expand Up @@ -134,7 +134,7 @@ public void toMeasureDto_returns_Dto_with_alertStatus_and_alertText_if_Measure_h
public void toMeasureDto_set_componentId_and_snapshotId_from_method_arguments(Measure measure, Metric metric) { public void toMeasureDto_set_componentId_and_snapshotId_from_method_arguments(Measure measure, Metric metric) {
MeasureDto measureDto = underTest.toMeasureDto(measure, metric, SOME_COMPONENT); MeasureDto measureDto = underTest.toMeasureDto(measure, metric, SOME_COMPONENT);


assertThat(measureDto.getComponentId()).isEqualTo(SOME_COMPONENT_ID); assertThat(measureDto.getComponentUuid()).isEqualTo(SOME_COMPONENT.getUuid());
assertThat(measureDto.getSnapshotId()).isEqualTo(SOME_SNAPSHOT_ID); assertThat(measureDto.getSnapshotId()).isEqualTo(SOME_SNAPSHOT_ID);
} }


Expand Down
Expand Up @@ -26,7 +26,6 @@
import org.junit.Test; import org.junit.Test;
import org.sonar.api.measures.Metric; import org.sonar.api.measures.Metric;
import org.sonar.api.utils.System2; import org.sonar.api.utils.System2;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient; import org.sonar.db.DbClient;
import org.sonar.db.DbTester; import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentDto;
Expand Down Expand Up @@ -108,13 +107,13 @@ public void setUp() {
} }


private void setupReportComponents() { private void setupReportComponents() {
Component project = ReportComponent.builder(PROJECT, ROOT_REF) Component project = ReportComponent.builder(PROJECT, ROOT_REF).setUuid("root-uuid")
.addChildren( .addChildren(
ReportComponent.builder(MODULE, INTERMEDIATE_1_REF) ReportComponent.builder(MODULE, INTERMEDIATE_1_REF).setUuid("intermediate1-uuid")
.addChildren( .addChildren(
ReportComponent.builder(DIRECTORY, INTERMEDIATE_2_REF) ReportComponent.builder(DIRECTORY, INTERMEDIATE_2_REF).setUuid("intermediate2-uuid")
.addChildren( .addChildren(
ReportComponent.builder(FILE, LEAF_REF) ReportComponent.builder(FILE, LEAF_REF).setUuid("leaf-uuid")
.build()) .build())
.build()) .build())
.build()) .build())
Expand All @@ -125,13 +124,13 @@ private void setupReportComponents() {
} }


private void setupViewsComponents() { private void setupViewsComponents() {
Component view = ViewsComponent.builder(VIEW, ROOT_REF) Component view = ViewsComponent.builder(VIEW, ROOT_REF).setUuid("root-uuid")
.addChildren( .addChildren(
ViewsComponent.builder(SUBVIEW, INTERMEDIATE_1_REF) ViewsComponent.builder(SUBVIEW, INTERMEDIATE_1_REF).setUuid("intermediate1-uuid")
.addChildren( .addChildren(
ViewsComponent.builder(SUBVIEW, INTERMEDIATE_2_REF) ViewsComponent.builder(SUBVIEW, INTERMEDIATE_2_REF).setUuid("intermediate2-uuid")
.addChildren( .addChildren(
ViewsComponent.builder(PROJECT_VIEW, LEAF_REF) ViewsComponent.builder(PROJECT_VIEW, LEAF_REF).setUuid("leaf-uuid")
.build()) .build())
.build()) .build())
.build()) .build())
Expand All @@ -142,10 +141,10 @@ private void setupViewsComponents() {
} }


private void setupDbIds() { private void setupDbIds() {
rootDto = addComponent("root-key"); rootDto = addComponent("root-key", "root-uuid");
intermediate1Dto = addComponent("intermediate1-key"); intermediate1Dto = addComponent("intermediate1-key", "intermediate1-uuid");
intermediate2Dto = addComponent("intermediate2-key"); intermediate2Dto = addComponent("intermediate2-key", "intermediate2-uuid");
leafDto = addComponent("leaf-key"); leafDto = addComponent("leaf-key", "leaf-uuid");


setDbIds(ROOT_REF, rootDto.getId(), ROOT_SNAPSHOT_ID); setDbIds(ROOT_REF, rootDto.getId(), ROOT_SNAPSHOT_ID);
setDbIds(INTERMEDIATE_1_REF, intermediate1Dto.getId(), INTERMEDIATE_1_SNAPSHOT_ID); setDbIds(INTERMEDIATE_1_REF, intermediate1Dto.getId(), INTERMEDIATE_1_SNAPSHOT_ID);
Expand Down Expand Up @@ -195,31 +194,31 @@ private void insertMeasures() {


Map<String, Object> dto = dtos.get(0); Map<String, Object> dto = dtos.get(0);
assertThat(dto.get("snapshotId")).isEqualTo(ROOT_SNAPSHOT_ID); assertThat(dto.get("snapshotId")).isEqualTo(ROOT_SNAPSHOT_ID);
assertThat(dto.get("componentId")).isEqualTo(rootDto.getId()); assertThat(dto.get("componentUuid")).isEqualTo(rootDto.uuid());
assertThat(dto.get("metricId")).isEqualTo((long) stringMetricId); assertThat(dto.get("metricId")).isEqualTo((long) stringMetricId);
assertThat(dto.get("value")).isNull(); assertThat(dto.get("value")).isNull();
assertThat(dto.get("textValue")).isEqualTo("measure-data"); assertThat(dto.get("textValue")).isEqualTo("measure-data");
assertThat(dto.get("severity")).isNull(); assertThat(dto.get("severity")).isNull();


dto = dtos.get(1); dto = dtos.get(1);
assertThat(dto.get("snapshotId")).isEqualTo(INTERMEDIATE_1_SNAPSHOT_ID); assertThat(dto.get("snapshotId")).isEqualTo(INTERMEDIATE_1_SNAPSHOT_ID);
assertThat(dto.get("componentId")).isEqualTo(intermediate1Dto.getId()); assertThat(dto.get("componentUuid")).isEqualTo(intermediate1Dto.uuid());
assertThat(dto.get("metricId")).isEqualTo((long) intMetricId); assertThat(dto.get("metricId")).isEqualTo((long) intMetricId);
assertValue(dto, 12d); assertValue(dto, 12d);
assertThat(dto.get("textValue")).isNull(); assertThat(dto.get("textValue")).isNull();
assertThat(dto.get("severity")).isNull(); assertThat(dto.get("severity")).isNull();


dto = dtos.get(2); dto = dtos.get(2);
assertThat(dto.get("snapshotId")).isEqualTo(INTERMEDIATE_2_SNAPSHOT_ID); assertThat(dto.get("snapshotId")).isEqualTo(INTERMEDIATE_2_SNAPSHOT_ID);
assertThat(dto.get("componentId")).isEqualTo(intermediate2Dto.getId()); assertThat(dto.get("componentUuid")).isEqualTo(intermediate2Dto.uuid());
assertThat(dto.get("metricId")).isEqualTo((long) longMetricId); assertThat(dto.get("metricId")).isEqualTo((long) longMetricId);
assertValue(dto, 9635d); assertValue(dto, 9635d);
assertThat(dto.get("textValue")).isNull(); assertThat(dto.get("textValue")).isNull();
assertThat(dto.get("severity")).isNull(); assertThat(dto.get("severity")).isNull();


dto = dtos.get(3); dto = dtos.get(3);
assertThat(dto.get("snapshotId")).isEqualTo(LEAF_SNAPSHOT_ID); assertThat(dto.get("snapshotId")).isEqualTo(LEAF_SNAPSHOT_ID);
assertThat(dto.get("componentId")).isEqualTo(leafDto.getId()); assertThat(dto.get("componentUuid")).isEqualTo(leafDto.uuid());
assertThat(dto.get("metricId")).isEqualTo((long) doubleMetricId); assertThat(dto.get("metricId")).isEqualTo((long) doubleMetricId);
assertValue(dto, 123.1d); assertValue(dto, 123.1d);
assertThat(dto.get("textValue")).isNull(); assertThat(dto.get("textValue")).isNull();
Expand Down Expand Up @@ -325,7 +324,7 @@ public void do_not_insert_file_complexity_distribution_metric_on_files() {


Map<String, Object> dto = dtos.get(0); Map<String, Object> dto = dtos.get(0);
assertThat(dto.get("snapshotId")).isEqualTo(ROOT_SNAPSHOT_ID); assertThat(dto.get("snapshotId")).isEqualTo(ROOT_SNAPSHOT_ID);
assertThat(dto.get("componentId")).isEqualTo(rootDto.getId()); assertThat(dto.get("componentUuid")).isEqualTo(rootDto.uuid());
assertThat(dto.get("textValue")).isEqualTo("0=1;2=10"); assertThat(dto.get("textValue")).isEqualTo("0=1;2=10");
} }


Expand All @@ -346,7 +345,7 @@ public void do_not_insert_function_complexity_distribution_metric_on_files() {


Map<String, Object> dto = dtos.get(0); Map<String, Object> dto = dtos.get(0);
assertThat(dto.get("snapshotId")).isEqualTo(ROOT_SNAPSHOT_ID); assertThat(dto.get("snapshotId")).isEqualTo(ROOT_SNAPSHOT_ID);
assertThat(dto.get("componentId")).isEqualTo(rootDto.getId()); assertThat(dto.get("componentUuid")).isEqualTo(rootDto.uuid());
assertThat(dto.get("textValue")).isEqualTo("0=1;2=10"); assertThat(dto.get("textValue")).isEqualTo("0=1;2=10");
} }


Expand All @@ -367,7 +366,7 @@ public void do_not_insert_class_complexity_distribution_metric_on_files() {


Map<String, Object> dto = dtos.get(0); Map<String, Object> dto = dtos.get(0);
assertThat(dto.get("snapshotId")).isEqualTo(ROOT_SNAPSHOT_ID); assertThat(dto.get("snapshotId")).isEqualTo(ROOT_SNAPSHOT_ID);
assertThat(dto.get("componentId")).isEqualTo(rootDto.getId()); assertThat(dto.get("componentUuid")).isEqualTo(rootDto.uuid());
assertThat(dto.get("textValue")).isEqualTo("0=1;2=10"); assertThat(dto.get("textValue")).isEqualTo("0=1;2=10");
} }


Expand All @@ -391,8 +390,8 @@ public void insert_developer_measure_from_report() {
assertThat(dto.get("developerId")).isEqualTo(10L); assertThat(dto.get("developerId")).isEqualTo(10L);
} }


private ComponentDto addComponent(String key) { private ComponentDto addComponent(String key, String uuid) {
ComponentDto componentDto = new ComponentDto().setKey(key).setUuid(Uuids.create()); ComponentDto componentDto = new ComponentDto().setKey(key).setUuid(uuid);
dbClient.componentDao().insert(dbTester.getSession(), componentDto); dbClient.componentDao().insert(dbTester.getSession(), componentDto);
return componentDto; return componentDto;
} }
Expand All @@ -404,16 +403,16 @@ private static Period createPeriod(Integer index) {
private List<Map<String, Object>> selectSnapshots() { private List<Map<String, Object>> selectSnapshots() {
return dbTester return dbTester
.select( .select(
"SELECT snapshot_id as \"snapshotId\", project_id as \"componentId\", metric_id as \"metricId\", person_id as \"developerId\", " "SELECT snapshot_id as \"snapshotId\", component_uuid as \"componentUuid\", metric_id as \"metricId\", person_id as \"developerId\", "
+ +
"value as \"value\", text_value as \"textValue\", " + "value as \"value\", text_value as \"textValue\", " +
"variation_value_1 as \"variation_value_1\", " + "variation_value_1 as \"variation_value_1\", " +
"variation_value_2 as \"variation_value_2\", " + "variation_value_2 as \"variation_value_2\", " +
"variation_value_3 as \"variation_value_3\", " + "variation_value_3 as \"variation_value_3\", " +
"variation_value_4 as \"variation_value_4\", " + "variation_value_4 as \"variation_value_4\", " +
"variation_value_5 as \"variation_value_5\"" + "variation_value_5 as \"variation_value_5\"" +
"FROM project_measures " + "FROM project_measures " +
"ORDER by snapshot_id asc"); "ORDER by snapshot_id asc");
} }


@Override @Override
Expand Down
Expand Up @@ -98,7 +98,7 @@ public void setUp() {
public void do_nothing_when_no_raw_measure() { public void do_nothing_when_no_raw_measure() {
SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO); SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 60d)); dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 60d));
session.commit(); session.commit();


periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
Expand Down Expand Up @@ -126,14 +126,14 @@ public void set_variation() {
// Project // Project
SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO); SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 60d)); dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 60d));


// Directory // Directory
ComponentDto directoryDto = ComponentTesting.newDirectory(PROJECT_DTO, "dir"); ComponentDto directoryDto = ComponentTesting.newDirectory(PROJECT_DTO, "dir");
dbClient.componentDao().insert(session, directoryDto); dbClient.componentDao().insert(session, directoryDto);
SnapshotDto period1DirectorySnapshot = createForComponent(directoryDto, period1ProjectSnapshot); SnapshotDto period1DirectorySnapshot = createForComponent(directoryDto, period1ProjectSnapshot);
dbClient.snapshotDao().insert(session, period1DirectorySnapshot); dbClient.snapshotDao().insert(session, period1DirectorySnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.getId(), period1DirectorySnapshot.getId(), 10d)); dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1DirectorySnapshot.getId(), 10d));
session.commit(); session.commit();


periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
Expand All @@ -156,14 +156,14 @@ public void set_zero_variation_when_no_change() {
// Project // Project
SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO); SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 60d)); dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 60d));


// Directory // Directory
ComponentDto directoryDto = ComponentTesting.newDirectory(PROJECT_DTO, "dir"); ComponentDto directoryDto = ComponentTesting.newDirectory(PROJECT_DTO, "dir");
dbClient.componentDao().insert(session, directoryDto); dbClient.componentDao().insert(session, directoryDto);
SnapshotDto period1DirectorySnapshot = createForComponent(directoryDto, period1ProjectSnapshot); SnapshotDto period1DirectorySnapshot = createForComponent(directoryDto, period1ProjectSnapshot);
dbClient.snapshotDao().insert(session, period1DirectorySnapshot); dbClient.snapshotDao().insert(session, period1DirectorySnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.getId(), period1DirectorySnapshot.getId(), 10d)); dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1DirectorySnapshot.getId(), 10d));
session.commit(); session.commit();


periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
Expand All @@ -188,8 +188,8 @@ public void set_variation_to_raw_value_on_new_component() throws Exception {
SnapshotDto currentProjectSnapshot = newSnapshotForProject(PROJECT_DTO).setCreatedAt(2000_000_000L); SnapshotDto currentProjectSnapshot = newSnapshotForProject(PROJECT_DTO).setCreatedAt(2000_000_000L);
dbClient.snapshotDao().insert(session, past1ProjectSnapshot); dbClient.snapshotDao().insert(session, past1ProjectSnapshot);
dbClient.snapshotDao().insert(session, currentProjectSnapshot); dbClient.snapshotDao().insert(session, currentProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), past1ProjectSnapshot.getId(), 60d)); dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), past1ProjectSnapshot.getId(), 60d));
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), currentProjectSnapshot.getId(), 60d)); dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), currentProjectSnapshot.getId(), 60d));
session.commit(); session.commit();


periodsHolder.setPeriods(newPeriod(1, past1ProjectSnapshot)); periodsHolder.setPeriods(newPeriod(1, past1ProjectSnapshot));
Expand Down Expand Up @@ -219,11 +219,11 @@ public void set_variations_on_all_periods() {
dbClient.snapshotDao().insert(session, period1ProjectSnapshot, period2ProjectSnapshot, period3ProjectSnapshot, period4ProjectSnapshot, period5ProjectSnapshot); dbClient.snapshotDao().insert(session, period1ProjectSnapshot, period2ProjectSnapshot, period3ProjectSnapshot, period4ProjectSnapshot, period5ProjectSnapshot);


dbClient.measureDao().insert(session, dbClient.measureDao().insert(session,
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 0d), newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 0d),
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period2ProjectSnapshot.getId(), 20d), newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period2ProjectSnapshot.getId(), 20d),
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period3ProjectSnapshot.getId(), 40d), newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period3ProjectSnapshot.getId(), 40d),
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period4ProjectSnapshot.getId(), 80d), newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period4ProjectSnapshot.getId(), 80d),
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period5ProjectSnapshot.getId(), 100d)); newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period5ProjectSnapshot.getId(), 100d));
session.commit(); session.commit();


periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot), periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot),
Expand Down Expand Up @@ -254,10 +254,10 @@ public void set_variation_on_all_numeric_metrics() {
SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO); SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, dbClient.measureDao().insert(session,
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 60d), newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 60d),
newMeasureDto(DEBT_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 10d), newMeasureDto(DEBT_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 10d),
newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 2d), newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 2d),
newMeasureDto(BUILD_BREAKER_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 1d)); newMeasureDto(BUILD_BREAKER_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 1d));
session.commit(); session.commit();


periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
Expand All @@ -284,7 +284,7 @@ public void do_not_set_variations_on_numeric_metric_for_developer() {
SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO); SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, dbClient.measureDao().insert(session,
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 60d)); newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 60d));
session.commit(); session.commit();


periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
Expand All @@ -305,7 +305,7 @@ public void do_not_set_variations_on_numeric_metric_for_developer() {
public void does_not_update_existing_variations() throws Exception { public void does_not_update_existing_variations() throws Exception {
SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO); SnapshotDto period1ProjectSnapshot = newSnapshotForProject(PROJECT_DTO);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(NEW_DEBT.getId(), PROJECT_DTO.getId(), period1ProjectSnapshot.getId(), 60d)); dbClient.measureDao().insert(session, newMeasureDto(NEW_DEBT.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getId(), 60d));
session.commit(); session.commit();
periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT); treeRootHolder.setRoot(PROJECT);
Expand All @@ -318,8 +318,8 @@ public void does_not_update_existing_variations() throws Exception {
assertThat(measureRepository.getRawMeasure(PROJECT, NEW_DEBT).get().getVariations().getVariation1()).isEqualTo(10d); assertThat(measureRepository.getRawMeasure(PROJECT, NEW_DEBT).get().getVariations().getVariation1()).isEqualTo(10d);
} }


private static MeasureDto newMeasureDto(int metricId, long projectId, long snapshotId, double value) { private static MeasureDto newMeasureDto(int metricId, String componentUuid, long snapshotId, double value) {
return new MeasureDto().setMetricId(metricId).setComponentId(projectId).setSnapshotId(snapshotId).setValue(value); return new MeasureDto().setMetricId(metricId).setComponentUuid(componentUuid).setSnapshotId(snapshotId).setValue(value);
} }


private static Period newPeriod(int index, SnapshotDto snapshotDto) { private static Period newPeriod(int index, SnapshotDto snapshotDto) {
Expand Down

0 comments on commit a115682

Please sign in to comment.