use of io.gravitee.repository.management.model.ApiQualityRule in project gravitee-management-rest-api by gravitee-io.
the class ApiQualityRuleServiceTest method shouldFindByApi.
@Test
public void shouldFindByApi() throws TechnicalException {
final ApiQualityRule aqr = mock(ApiQualityRule.class);
when(aqr.getApi()).thenReturn(API_ID);
when(aqr.getQualityRule()).thenReturn(QUALITY_RULE_ID);
when(aqr.isChecked()).thenReturn(true);
when(aqr.getCreatedAt()).thenReturn(new Date(1));
when(aqr.getUpdatedAt()).thenReturn(new Date(2));
when(apiQualityRuleRepository.findByApi(API_ID)).thenReturn(singletonList(aqr));
final List<ApiQualityRuleEntity> apiQualityRules = apiQualityRuleService.findByApi(API_ID);
final ApiQualityRuleEntity apiQualityRuleEntity = apiQualityRules.iterator().next();
assertEquals(API_ID, apiQualityRuleEntity.getApi());
assertEquals(QUALITY_RULE_ID, apiQualityRuleEntity.getQualityRule());
assertTrue(apiQualityRuleEntity.isChecked());
assertEquals(new Date(1), apiQualityRuleEntity.getCreatedAt());
assertEquals(new Date(2), apiQualityRuleEntity.getUpdatedAt());
}
use of io.gravitee.repository.management.model.ApiQualityRule in project gravitee-management-rest-api by gravitee-io.
the class ApiQualityRuleServiceTest method shouldUpdate.
@Test
public void shouldUpdate() throws TechnicalException {
final UpdateApiQualityRuleEntity updateApiQualityRuleEntity = new UpdateApiQualityRuleEntity();
updateApiQualityRuleEntity.setApi(API_ID);
updateApiQualityRuleEntity.setQualityRule(QUALITY_RULE_ID);
updateApiQualityRuleEntity.setChecked(true);
final ApiQualityRule updatedApiQualityRule = new ApiQualityRule();
updatedApiQualityRule.setApi(API_ID);
updatedApiQualityRule.setQualityRule(QUALITY_RULE_ID);
updatedApiQualityRule.setChecked(true);
updatedApiQualityRule.setCreatedAt(new Date());
updatedApiQualityRule.setUpdatedAt(new Date());
when(apiQualityRuleRepository.update(any())).thenReturn(updatedApiQualityRule);
when(apiQualityRuleRepository.findById(API_ID, QUALITY_RULE_ID)).thenReturn(of(updatedApiQualityRule));
final ApiQualityRuleEntity apiQualityRuleEntity = apiQualityRuleService.update(updateApiQualityRuleEntity);
assertEquals(API_ID, apiQualityRuleEntity.getApi());
assertEquals(QUALITY_RULE_ID, apiQualityRuleEntity.getQualityRule());
assertTrue(apiQualityRuleEntity.isChecked());
assertNotNull(apiQualityRuleEntity.getCreatedAt());
assertNotNull(apiQualityRuleEntity.getUpdatedAt());
final ApiQualityRule apiQualityRule = new ApiQualityRule();
apiQualityRule.setApi(API_ID);
apiQualityRule.setQualityRule(QUALITY_RULE_ID);
apiQualityRule.setChecked(true);
verify(apiQualityRuleRepository, times(1)).update(argThat(argument -> API_ID.equals(argument.getApi()) && QUALITY_RULE_ID.equals(argument.getQualityRule()) && argument.isChecked() && argument.getCreatedAt() != null && argument.getUpdatedAt() != null));
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(API_QUALITY_RULE, API_ID)), eq(ApiQualityRule.AuditEvent.API_QUALITY_RULE_UPDATED), any(Date.class), any(), any());
}
Aggregations