use of io.gravitee.rest.api.model.ApiQualityMetricsEntity in project gravitee-management-rest-api by gravitee-io.
the class QualityMetricsServiceTest method shouldScore33Percent.
@Test
public void shouldScore33Percent() {
when(parameterService.findAsBoolean(Key.API_QUALITY_METRICS_ENABLED, ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
Map<String, List<Object>> map = new HashMap<>();
map.put(Key.API_QUALITY_METRICS_LOGO_WEIGHT.key(), singletonList(1));
map.put(Key.API_QUALITY_METRICS_CATEGORIES_WEIGHT.key(), singletonList(2));
when(parameterService.findAll(anyList(), any(Function.class), any(ParameterReferenceType.class))).thenReturn(map);
ApiEntity api = mock(ApiEntity.class);
when(apiQualityMetricLogo.isValid(any())).thenReturn(Boolean.TRUE);
when(apiQualityMetricCategories.isValid(any())).thenReturn(Boolean.FALSE);
ApiQualityMetricsEntity metrics = srv.getMetrics(api);
assertEquals(0.33, metrics.getScore(), 0);
assertFalse(metrics.getMetricsPassed().isEmpty());
assertTrue(metrics.getMetricsPassed().get(Key.API_QUALITY_METRICS_LOGO_WEIGHT.key()));
assertFalse(metrics.getMetricsPassed().get(Key.API_QUALITY_METRICS_CATEGORIES_WEIGHT.key()));
}
use of io.gravitee.rest.api.model.ApiQualityMetricsEntity in project gravitee-management-rest-api by gravitee-io.
the class QualityMetricsServiceTest method shouldReturnEmptyEntityWithoutConfiguration.
@Test
public void shouldReturnEmptyEntityWithoutConfiguration() {
when(parameterService.findAsBoolean(Key.API_QUALITY_METRICS_ENABLED, ParameterReferenceType.ENVIRONMENT)).thenReturn(Boolean.TRUE);
when(parameterService.findAll(anyList(), any(Function.class), any(ParameterReferenceType.class))).thenReturn(Collections.emptyMap());
ApiEntity api = mock(ApiEntity.class);
ApiQualityMetricsEntity metrics = srv.getMetrics(api);
assertEquals(1, metrics.getScore(), 0);
assertTrue(metrics.getMetricsPassed().isEmpty());
}
Aggregations