Search in sources :

Example 1 with QUALITY_RULE

use of io.gravitee.repository.management.model.Audit.AuditProperties.QUALITY_RULE 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());
}
Also used : QualityRule(io.gravitee.repository.management.model.QualityRule) InjectMocks(org.mockito.InjectMocks) Optional.empty(java.util.Optional.empty) QualityRuleRepository(io.gravitee.repository.management.api.QualityRuleRepository) ApiQualityRuleRepository(io.gravitee.repository.management.api.ApiQualityRuleRepository) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) Date(java.util.Date) Mock(org.mockito.Mock) Optional.of(java.util.Optional.of) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) io.gravitee.rest.api.model.quality(io.gravitee.rest.api.model.quality) Mockito(org.mockito.Mockito) List(java.util.List) Collections.singleton(java.util.Collections.singleton) QualityRuleNotFoundException(io.gravitee.rest.api.service.exceptions.QualityRuleNotFoundException) QUALITY_RULE(io.gravitee.repository.management.model.Audit.AuditProperties.QUALITY_RULE) QualityRuleServiceImpl(io.gravitee.rest.api.service.impl.QualityRuleServiceImpl) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) QualityRule(io.gravitee.repository.management.model.QualityRule) Date(java.util.Date) Test(org.junit.Test)

Example 2 with QUALITY_RULE

use of io.gravitee.repository.management.model.Audit.AuditProperties.QUALITY_RULE 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());
}
Also used : QualityRule(io.gravitee.repository.management.model.QualityRule) InjectMocks(org.mockito.InjectMocks) Optional.empty(java.util.Optional.empty) QualityRuleRepository(io.gravitee.repository.management.api.QualityRuleRepository) ApiQualityRuleRepository(io.gravitee.repository.management.api.ApiQualityRuleRepository) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) Date(java.util.Date) Mock(org.mockito.Mock) Optional.of(java.util.Optional.of) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) io.gravitee.rest.api.model.quality(io.gravitee.rest.api.model.quality) Mockito(org.mockito.Mockito) List(java.util.List) Collections.singleton(java.util.Collections.singleton) QualityRuleNotFoundException(io.gravitee.rest.api.service.exceptions.QualityRuleNotFoundException) QUALITY_RULE(io.gravitee.repository.management.model.Audit.AuditProperties.QUALITY_RULE) QualityRuleServiceImpl(io.gravitee.rest.api.service.impl.QualityRuleServiceImpl) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) QualityRule(io.gravitee.repository.management.model.QualityRule) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 ApiQualityRuleRepository (io.gravitee.repository.management.api.ApiQualityRuleRepository)2 QualityRuleRepository (io.gravitee.repository.management.api.QualityRuleRepository)2 QUALITY_RULE (io.gravitee.repository.management.model.Audit.AuditProperties.QUALITY_RULE)2 QualityRule (io.gravitee.repository.management.model.QualityRule)2 io.gravitee.rest.api.model.quality (io.gravitee.rest.api.model.quality)2 QualityRuleNotFoundException (io.gravitee.rest.api.service.exceptions.QualityRuleNotFoundException)2 QualityRuleServiceImpl (io.gravitee.rest.api.service.impl.QualityRuleServiceImpl)2 Collections.singleton (java.util.Collections.singleton)2 Date (java.util.Date)2 List (java.util.List)2 Optional.empty (java.util.Optional.empty)2 Optional.of (java.util.Optional.of)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 InjectMocks (org.mockito.InjectMocks)2 Mock (org.mockito.Mock)2