use of org.sonar.api.measures.Metric in project sonarqube by SonarSource.
the class CoreMetricsTest method get_metric_by_key.
@Test
public void get_metric_by_key() throws Exception {
Metric metric = getMetric("ncloc");
assertThat(metric.getKey()).isEqualTo("ncloc");
}
use of org.sonar.api.measures.Metric in project sonarqube by SonarSource.
the class DefaultMetricsRepositoryLoader method loadFromPaginatedWs.
private void loadFromPaginatedWs(List<Metric> metrics) throws IOException {
int page = 1;
WsMetricsResponse response;
do {
GetRequest getRequest = new GetRequest(METRICS_SEARCH_URL + page);
try (Reader reader = wsClient.call(getRequest).contentReader()) {
response = GsonHelper.create().fromJson(reader, WsMetricsResponse.class);
for (WsMetric metric : response.metrics) {
metrics.add(new Metric.Builder(metric.getKey(), metric.getName(), ValueType.valueOf(metric.getType())).create().setDirection(metric.getDirection()).setQualitative(metric.isQualitative()).setUserManaged(metric.isCustom()).setDescription(metric.getDescription()).setId(metric.getId()));
}
}
page++;
} while (response.getP() < (response.getTotal() / response.getPs() + 1));
}
use of org.sonar.api.measures.Metric in project sonarqube by SonarSource.
the class MetricProviderTest method should_provide_at_least_core_metrics.
@Test
public void should_provide_at_least_core_metrics() {
MetricProvider provider = new MetricProvider();
List<Metric> metrics = provider.provide();
assertThat(metrics).hasSize(CoreMetrics.getMetrics().size());
assertThat(metrics).extracting("key").contains("ncloc");
}
use of org.sonar.api.measures.Metric in project sonarqube by SonarSource.
the class MetricProviderTest method should_provide_plugin_metrics.
@Test
public void should_provide_plugin_metrics() {
Metrics factory = new Metrics() {
public List<Metric> getMetrics() {
return Arrays.<Metric>asList(new Metric.Builder("custom", "Custom", Metric.ValueType.FLOAT).create());
}
};
MetricProvider provider = new MetricProvider(new Metrics[] { factory });
List<Metric> metrics = provider.provide();
assertThat(metrics.size()).isEqualTo(1 + CoreMetrics.getMetrics().size());
assertThat(metrics).extracting("key").contains("custom");
}
use of org.sonar.api.measures.Metric in project sonarqube by SonarSource.
the class MeasureSensorTest method testExecution.
@Test
public void testExecution() throws IOException {
File measures = new File(baseDir, "src/foo.xoo.measures");
FileUtils.write(measures, "ncloc:12\nbranch_coverage:5.3\nsqale_index:300\nbool:true\n\n#comment");
InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build();
context.fileSystem().add(inputFile);
Metric<Boolean> booleanMetric = new Metric.Builder("bool", "Bool", Metric.ValueType.BOOL).create();
when(metricFinder.<Integer>findByKey("ncloc")).thenReturn(CoreMetrics.NCLOC);
when(metricFinder.<Double>findByKey("branch_coverage")).thenReturn(CoreMetrics.BRANCH_COVERAGE);
when(metricFinder.<Long>findByKey("sqale_index")).thenReturn(CoreMetrics.TECHNICAL_DEBT);
when(metricFinder.<Boolean>findByKey("bool")).thenReturn(booleanMetric);
sensor.execute(context);
assertThat(context.measure("foo:src/foo.xoo", CoreMetrics.NCLOC).value()).isEqualTo(12);
assertThat(context.measure("foo:src/foo.xoo", CoreMetrics.BRANCH_COVERAGE).value()).isEqualTo(5.3);
assertThat(context.measure("foo:src/foo.xoo", CoreMetrics.TECHNICAL_DEBT).value()).isEqualTo(300L);
assertThat(context.measure("foo:src/foo.xoo", booleanMetric).value()).isTrue();
}
Aggregations