use of org.sonar.api.batch.sensor.measure.internal.DefaultMeasure in project sonarqube by SonarSource.
the class MeasuresPublisher method updateTestExecutionFromTestPlan.
private void updateTestExecutionFromTestPlan(final InputFile inputFile) {
final MutableTestPlan testPlan = testPlanBuilder.getTestPlanByFile(inputFile);
if (testPlan == null || Iterables.isEmpty(testPlan.testCases())) {
return;
}
long nonSkippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() != Status.SKIPPED).count();
measureCache.put(inputFile.key(), TESTS_KEY, new DefaultMeasure<Integer>().forMetric(TESTS).withValue((int) nonSkippedTests));
long executionTime = StreamSupport.stream(testPlan.testCases().spliterator(), false).mapToLong(t -> t.durationInMs() != null ? t.durationInMs().longValue() : 0L).sum();
measureCache.put(inputFile.key(), TEST_EXECUTION_TIME_KEY, new DefaultMeasure<Long>().forMetric(TEST_EXECUTION_TIME).withValue(executionTime));
long errorTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.ERROR).count();
measureCache.put(inputFile.key(), TEST_ERRORS_KEY, new DefaultMeasure<Integer>().forMetric(TEST_ERRORS).withValue((int) errorTests));
long skippedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.SKIPPED).count();
measureCache.put(inputFile.key(), SKIPPED_TESTS_KEY, new DefaultMeasure<Integer>().forMetric(SKIPPED_TESTS).withValue((int) skippedTests));
long failedTests = StreamSupport.stream(testPlan.testCases().spliterator(), false).filter(t -> t.status() == Status.FAILURE).count();
measureCache.put(inputFile.key(), TEST_FAILURES_KEY, new DefaultMeasure<Integer>().forMetric(TEST_FAILURES).withValue((int) failedTests));
}
use of org.sonar.api.batch.sensor.measure.internal.DefaultMeasure in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method shouldSaveProjectMeasureToSensorContext.
@Test
public void shouldSaveProjectMeasureToSensorContext() {
String projectKey = "myProject";
DefaultInputModule module = new DefaultInputModule(projectKey);
ArgumentCaptor<DefaultMeasure> argumentCaptor = ArgumentCaptor.forClass(DefaultMeasure.class);
when(measureCache.put(eq(module.key()), eq(CoreMetrics.NCLOC_KEY), argumentCaptor.capture())).thenReturn(null);
underTest.store(new DefaultMeasure().on(module).forMetric(CoreMetrics.NCLOC).withValue(10));
DefaultMeasure m = argumentCaptor.getValue();
assertThat(m.value()).isEqualTo(10);
assertThat(m.metric()).isEqualTo(CoreMetrics.NCLOC);
}
use of org.sonar.api.batch.sensor.measure.internal.DefaultMeasure in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method shouldSaveFileMeasureToSensorContext.
@Test
public void shouldSaveFileMeasureToSensorContext() {
InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build();
ArgumentCaptor<DefaultMeasure> argumentCaptor = ArgumentCaptor.forClass(DefaultMeasure.class);
when(measureCache.put(eq(file.key()), eq(CoreMetrics.NCLOC_KEY), argumentCaptor.capture())).thenReturn(null);
underTest.store(new DefaultMeasure().on(file).forMetric(CoreMetrics.NCLOC).withValue(10));
DefaultMeasure m = argumentCaptor.getValue();
assertThat(m.value()).isEqualTo(10);
assertThat(m.metric()).isEqualTo(CoreMetrics.NCLOC);
}
use of org.sonar.api.batch.sensor.measure.internal.DefaultMeasure in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method shouldFailIfUnknownMetric.
@Test
public void shouldFailIfUnknownMetric() {
InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build();
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("Unknown metric: lines");
underTest.store(new DefaultMeasure().on(file).forMetric(CoreMetrics.LINES).withValue(10));
}
Aggregations