use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceTest method shouldFindAll.
@Test
public void shouldFindAll() throws TechnicalException {
final QualityRule qualityRule = mock(QualityRule.class);
when(qualityRule.getId()).thenReturn(QUALITY_RULE_ID);
when(qualityRule.getName()).thenReturn("NAME");
when(qualityRule.getDescription()).thenReturn("DESC");
when(qualityRule.getWeight()).thenReturn(1);
when(qualityRule.getCreatedAt()).thenReturn(new Date(1));
when(qualityRule.getUpdatedAt()).thenReturn(new Date(2));
when(qualityRuleRepository.findAll()).thenReturn(singleton(qualityRule));
final List<QualityRuleEntity> qualityRules = qualityRuleService.findAll();
final QualityRuleEntity qualityRuleEntity = qualityRules.iterator().next();
assertEquals(QUALITY_RULE_ID, qualityRuleEntity.getId());
assertEquals("NAME", qualityRuleEntity.getName());
assertEquals("DESC", qualityRuleEntity.getDescription());
assertEquals(1, qualityRuleEntity.getWeight());
assertEquals(new Date(1), qualityRuleEntity.getCreatedAt());
assertEquals(new Date(2), qualityRuleEntity.getUpdatedAt());
}
use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceTest method shouldCreate.
@Test
public void shouldCreate() throws TechnicalException {
final NewQualityRuleEntity newQualityRuleEntity = new NewQualityRuleEntity();
newQualityRuleEntity.setName("NAME");
newQualityRuleEntity.setDescription("DESC");
newQualityRuleEntity.setWeight(1);
final QualityRule createdQualityRule = new QualityRule();
createdQualityRule.setId(QUALITY_RULE_ID);
createdQualityRule.setName("NAME");
createdQualityRule.setDescription("DESC");
createdQualityRule.setWeight(1);
createdQualityRule.setCreatedAt(new Date());
createdQualityRule.setUpdatedAt(new Date());
when(qualityRuleRepository.create(any())).thenReturn(createdQualityRule);
final QualityRuleEntity qualityRuleEntity = qualityRuleService.create(newQualityRuleEntity);
assertNotNull(qualityRuleEntity.getId());
assertEquals("NAME", qualityRuleEntity.getName());
assertEquals("DESC", qualityRuleEntity.getDescription());
assertEquals(1, qualityRuleEntity.getWeight());
assertNotNull(qualityRuleEntity.getCreatedAt());
assertNotNull(qualityRuleEntity.getUpdatedAt());
final QualityRule qualityRule = new QualityRule();
qualityRule.setName("NAME");
qualityRule.setDescription("DESC");
qualityRule.setWeight(1);
verify(qualityRuleRepository, times(1)).create(argThat(argument -> "NAME".equals(argument.getName()) && "DESC".equals(argument.getDescription()) && Integer.valueOf(1).equals(argument.getWeight()) && !argument.getId().isEmpty() && argument.getCreatedAt() != null && argument.getUpdatedAt() != null));
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(QUALITY_RULE, QUALITY_RULE_ID)), eq(QualityRule.AuditEvent.QUALITY_RULE_CREATED), any(Date.class), isNull(), any());
}
use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceTest method shouldUpdate.
@Test
public void shouldUpdate() throws TechnicalException {
final UpdateQualityRuleEntity updateQualityRuleEntity = new UpdateQualityRuleEntity();
updateQualityRuleEntity.setId(QUALITY_RULE_ID);
updateQualityRuleEntity.setName("NAME");
updateQualityRuleEntity.setDescription("DESC");
updateQualityRuleEntity.setWeight(1);
final QualityRule updatedQualityRule = new QualityRule();
updatedQualityRule.setId(QUALITY_RULE_ID);
updatedQualityRule.setName("NAME");
updatedQualityRule.setDescription("DESC");
updatedQualityRule.setWeight(1);
updatedQualityRule.setCreatedAt(new Date());
updatedQualityRule.setUpdatedAt(new Date());
when(qualityRuleRepository.update(any())).thenReturn(updatedQualityRule);
when(qualityRuleRepository.findById(QUALITY_RULE_ID)).thenReturn(of(updatedQualityRule));
final QualityRuleEntity qualityRuleEntity = qualityRuleService.update(updateQualityRuleEntity);
assertNotNull(qualityRuleEntity.getId());
assertEquals("NAME", qualityRuleEntity.getName());
assertEquals("DESC", qualityRuleEntity.getDescription());
assertEquals(1, qualityRuleEntity.getWeight());
assertNotNull(qualityRuleEntity.getCreatedAt());
assertNotNull(qualityRuleEntity.getUpdatedAt());
final QualityRule qualityRule = new QualityRule();
qualityRule.setName("NAME");
qualityRule.setDescription("DESC");
qualityRule.setWeight(1);
verify(qualityRuleRepository, times(1)).update(argThat(argument -> "NAME".equals(argument.getName()) && "DESC".equals(argument.getDescription()) && Integer.valueOf(1).equals(argument.getWeight()) && QUALITY_RULE_ID.equals(argument.getId()) && argument.getCreatedAt() != null && argument.getUpdatedAt() != null));
verify(auditService, times(1)).createEnvironmentAuditLog(eq(ImmutableMap.of(QUALITY_RULE, QUALITY_RULE_ID)), eq(QualityRule.AuditEvent.QUALITY_RULE_UPDATED), any(Date.class), any(), any());
}
use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceImpl method create.
@Override
public QualityRuleEntity create(NewQualityRuleEntity newEntity) {
try {
final QualityRule qualityRule = convert(newEntity);
final QualityRule createdQualityRule = qualityRuleRepository.create(qualityRule);
auditService.createEnvironmentAuditLog(Collections.singletonMap(QUALITY_RULE, createdQualityRule.getId()), QualityRule.AuditEvent.QUALITY_RULE_CREATED, qualityRule.getCreatedAt(), null, qualityRule);
return convert(createdQualityRule);
} catch (TechnicalException e) {
LOGGER.error("An error occurs while trying to create a quality rule {}", newEntity, e);
throw new TechnicalManagementException("An error occurs while trying to create a quality rule " + newEntity, e);
}
}
use of io.gravitee.repository.management.model.QualityRule in project gravitee-management-rest-api by gravitee-io.
the class QualityRuleServiceImpl method delete.
@Override
public void delete(final String qualityRule) {
try {
final Optional<QualityRule> qualityRuleOptional = qualityRuleRepository.findById(qualityRule);
if (qualityRuleOptional.isPresent()) {
qualityRuleRepository.delete(qualityRule);
// delete all reference on api quality rule
apiQualityRuleRepository.deleteByQualityRule(qualityRule);
auditService.createEnvironmentAuditLog(Collections.singletonMap(QUALITY_RULE, qualityRule), QualityRule.AuditEvent.QUALITY_RULE_DELETED, new Date(), null, qualityRuleOptional.get());
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete quality rule {}", qualityRule, ex);
throw new TechnicalManagementException("An error occurs while trying to delete quality rule " + qualityRule, ex);
}
}
Aggregations