use of io.gravitee.repository.management.model.ApiQualityRule in project gravitee-management-rest-api by gravitee-io.
the class ApiQualityRuleServiceTest method shouldCreate.
@Test
public void shouldCreate() throws TechnicalException {
final NewApiQualityRuleEntity newApiQualityRuleEntity = new NewApiQualityRuleEntity();
newApiQualityRuleEntity.setApi(API_ID);
newApiQualityRuleEntity.setQualityRule(QUALITY_RULE_ID);
newApiQualityRuleEntity.setChecked(true);
final ApiQualityRule createdApiQualityRule = new ApiQualityRule();
createdApiQualityRule.setApi(API_ID);
createdApiQualityRule.setQualityRule(QUALITY_RULE_ID);
createdApiQualityRule.setChecked(true);
createdApiQualityRule.setCreatedAt(new Date());
createdApiQualityRule.setUpdatedAt(new Date());
when(apiQualityRuleRepository.create(any())).thenReturn(createdApiQualityRule);
final ApiQualityRuleEntity apiQualityRuleEntity = apiQualityRuleService.create(newApiQualityRuleEntity);
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)).create(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_CREATED), any(Date.class), isNull(), any());
}
use of io.gravitee.repository.management.model.ApiQualityRule in project gravitee-management-rest-api by gravitee-io.
the class ApiQualityRuleServiceImpl method update.
@Override
public ApiQualityRuleEntity update(UpdateApiQualityRuleEntity updateEntity) {
try {
final Optional<ApiQualityRule> optionalApiQualityRule = apiQualityRuleRepository.findById(updateEntity.getApi(), updateEntity.getQualityRule());
if (!optionalApiQualityRule.isPresent()) {
throw new ApiQualityRuleNotFoundException(updateEntity.getApi(), updateEntity.getQualityRule());
}
final ApiQualityRule apiQualityRule = apiQualityRuleRepository.update(convert(updateEntity));
auditService.createEnvironmentAuditLog(singletonMap(API_QUALITY_RULE, apiQualityRule.getApi()), ApiQualityRule.AuditEvent.API_QUALITY_RULE_UPDATED, apiQualityRule.getUpdatedAt(), optionalApiQualityRule.get(), apiQualityRule);
return convert(apiQualityRule);
} catch (TechnicalException e) {
final String error = "An error occurs while trying to update API quality rule " + updateEntity;
LOGGER.error(error, e);
throw new TechnicalManagementException(error, e);
}
}
use of io.gravitee.repository.management.model.ApiQualityRule in project gravitee-management-rest-api by gravitee-io.
the class ApiQualityRuleServiceImpl method convert.
private ApiQualityRule convert(final NewApiQualityRuleEntity apiQualityRuleEntity) {
final ApiQualityRule apiQualityRule = new ApiQualityRule();
apiQualityRule.setApi(apiQualityRuleEntity.getApi());
apiQualityRule.setQualityRule(apiQualityRuleEntity.getQualityRule());
apiQualityRule.setChecked(apiQualityRuleEntity.isChecked());
final Date now = new Date();
apiQualityRule.setCreatedAt(now);
apiQualityRule.setUpdatedAt(now);
return apiQualityRule;
}
use of io.gravitee.repository.management.model.ApiQualityRule in project gravitee-management-rest-api by gravitee-io.
the class ApiQualityRuleServiceImpl method convert.
private ApiQualityRule convert(final UpdateApiQualityRuleEntity apiQualityRuleEntity) {
final ApiQualityRule apiQualityRule = new ApiQualityRule();
apiQualityRule.setApi(apiQualityRuleEntity.getApi());
apiQualityRule.setQualityRule(apiQualityRuleEntity.getQualityRule());
apiQualityRule.setChecked(apiQualityRuleEntity.isChecked());
final Date now = new Date();
apiQualityRule.setCreatedAt(now);
apiQualityRule.setUpdatedAt(now);
return apiQualityRule;
}
use of io.gravitee.repository.management.model.ApiQualityRule in project gravitee-management-rest-api by gravitee-io.
the class ApiQualityRuleServiceImpl method create.
@Override
public ApiQualityRuleEntity create(NewApiQualityRuleEntity newEntity) {
try {
final Optional<ApiQualityRule> optionalApiQualityRule = apiQualityRuleRepository.findById(newEntity.getApi(), newEntity.getQualityRule());
if (optionalApiQualityRule.isPresent()) {
throw new ApiQualityRuleAlreadyExistsException(newEntity.getApi(), newEntity.getQualityRule());
}
final ApiQualityRule apiQualityRule = convert(newEntity);
auditService.createEnvironmentAuditLog(Collections.singletonMap(API_QUALITY_RULE, apiQualityRule.getApi()), ApiQualityRule.AuditEvent.API_QUALITY_RULE_CREATED, apiQualityRule.getCreatedAt(), null, apiQualityRule);
return convert(apiQualityRuleRepository.create(apiQualityRule));
} catch (TechnicalException e) {
final String error = "An error occurs while trying to create an API quality rule " + newEntity;
LOGGER.error(error, e);
throw new TechnicalManagementException(error, e);
}
}
Aggregations