use of io.gravitee.repository.management.model.Audit.AuditProperties.API_QUALITY_RULE 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.Audit.AuditProperties.API_QUALITY_RULE 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