@SafeVarargs public final MeasureDto insertMeasure(ComponentDto component, SnapshotDto analysis, MetricDto metricDto, Consumer<MeasureDto>... consumers) { MeasureDto measureDto = newMeasureDto(metricDto, component, analysis); Arrays.stream(consumers).forEach(c -> c.accept(measureDto)); dbClient.measureDao().insert(dbSession, measureDto); dbSession.commit(); return measureDto; }
@Test public void return_metrics() { dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, analysis).setValue(42.0d)); db.commit(); SearchHistoryResponse result = call(); assertThat(result.getMeasuresList()).hasSize(3) .extracting(HistoryMeasure::getMetric) .containsExactly(complexityMetric.getKey(), nclocMetric.getKey(), newViolationMetric.getKey()); }
@Test public void test_selectLastMeasure() { MetricDto metric = db.measures().insertMetric(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); SnapshotDto lastAnalysis = insertAnalysis(project.uuid(), true); SnapshotDto pastAnalysis = insertAnalysis(project.uuid(), false); MeasureDto pastMeasure = MeasureTesting.newMeasureDto(metric, file, pastAnalysis); MeasureDto lastMeasure = MeasureTesting.newMeasureDto(metric, file, lastAnalysis); underTest.insert(db.getSession(), pastMeasure); underTest.insert(db.getSession(), lastMeasure); MeasureDto selected = underTest.selectLastMeasure(db.getSession(), file.uuid(), metric.getKey()).get(); assertThat(selected).isEqualToComparingFieldByField(lastMeasure); assertThat(underTest.selectLastMeasure(dbSession, "_missing_", metric.getKey())).isEmpty(); assertThat(underTest.selectLastMeasure(dbSession, file.uuid(), "_missing_")).isEmpty(); assertThat(underTest.selectLastMeasure(dbSession, "_missing_", "_missing_")).isEmpty(); }
@Test public void test_json_example() throws IOException { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organization); userSession.addProjectPermission(UserRole.USER, project); MetricDto gateDetailsMetric = insertGateDetailMetric(); SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project) .setPeriodMode("last_version") .setPeriodParam("2015-12-07") .setPeriodDate(956789123987L)); dbClient.measureDao().insert(dbSession, newMeasureDto(gateDetailsMetric, project, snapshot) .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json")))); dbSession.commit(); String response = ws.newRequest() .setParam("analysisId", snapshot.getUuid()) .execute().getInput(); assertJson(response).isSimilarTo(getClass().getResource("project_status-example.json")); }
@Test public void test_selectMeasure() { MetricDto metric = db.measures().insertMetric(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); SnapshotDto lastAnalysis = insertAnalysis(project.uuid(), true); SnapshotDto pastAnalysis = insertAnalysis(project.uuid(), false); MeasureDto pastMeasure = MeasureTesting.newMeasureDto(metric, file, pastAnalysis); MeasureDto lastMeasure = MeasureTesting.newMeasureDto(metric, file, lastAnalysis); underTest.insert(db.getSession(), pastMeasure); underTest.insert(db.getSession(), lastMeasure); assertThat(underTest.selectMeasure(db.getSession(), lastAnalysis.getUuid(), file.uuid(), metric.getKey()).get()) .isEqualToComparingFieldByField(lastMeasure); assertThat(underTest.selectMeasure(db.getSession(), pastAnalysis.getUuid(), file.uuid(), metric.getKey()).get()) .isEqualToComparingFieldByField(pastMeasure); assertThat(underTest.selectMeasure(db.getSession(), "_missing_", file.uuid(), metric.getKey())).isEmpty(); assertThat(underTest.selectMeasure(db.getSession(), pastAnalysis.getUuid(), "_missing_", metric.getKey())).isEmpty(); assertThat(underTest.selectMeasure(db.getSession(), pastAnalysis.getUuid(), file.uuid(), "_missing_")).isEmpty(); }