Search in sources :

Example 6 with ApiQualityMetricsEntity

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()));
}
Also used : Function(java.util.function.Function) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ApiQualityMetricsEntity(io.gravitee.rest.api.model.ApiQualityMetricsEntity) Collections.singletonList(java.util.Collections.singletonList) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Test(org.junit.Test)

Example 7 with ApiQualityMetricsEntity

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());
}
Also used : Function(java.util.function.Function) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ApiQualityMetricsEntity(io.gravitee.rest.api.model.ApiQualityMetricsEntity) Test(org.junit.Test)

Aggregations

ApiQualityMetricsEntity (io.gravitee.rest.api.model.ApiQualityMetricsEntity)7 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)7 ParameterReferenceType (io.gravitee.rest.api.model.parameters.ParameterReferenceType)7 Function (java.util.function.Function)6 Test (org.junit.Test)6 Collections.singletonList (java.util.Collections.singletonList)5 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)5 ApiQualityRuleEntity (io.gravitee.rest.api.model.quality.ApiQualityRuleEntity)3 QualityRuleEntity (io.gravitee.rest.api.model.quality.QualityRuleEntity)3 Key (io.gravitee.rest.api.model.parameters.Key)1 ApiQualityRuleService (io.gravitee.rest.api.service.ApiQualityRuleService)1 ParameterService (io.gravitee.rest.api.service.ParameterService)1 QualityMetricsService (io.gravitee.rest.api.service.QualityMetricsService)1 QualityRuleService (io.gravitee.rest.api.service.QualityRuleService)1 ApiQualityMetricsDisableException (io.gravitee.rest.api.service.exceptions.ApiQualityMetricsDisableException)1 ApiQualityMetric (io.gravitee.rest.api.service.quality.ApiQualityMetric)1 ApiQualityMetricLoader (io.gravitee.rest.api.service.quality.ApiQualityMetricLoader)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1