Search in sources :

Example 1 with ApiQualityRuleRepository

use of io.gravitee.repository.management.api.ApiQualityRuleRepository 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());
}
Also used : InjectMocks(org.mockito.InjectMocks) Optional.empty(java.util.Optional.empty) API_QUALITY_RULE(io.gravitee.repository.management.model.Audit.AuditProperties.API_QUALITY_RULE) ApiQualityRuleRepository(io.gravitee.repository.management.api.ApiQualityRuleRepository) ImmutableMap(com.google.common.collect.ImmutableMap) 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) Collections.singletonList(java.util.Collections.singletonList) io.gravitee.rest.api.model.quality(io.gravitee.rest.api.model.quality) Mockito(org.mockito.Mockito) ApiQualityRuleNotFoundException(io.gravitee.rest.api.service.exceptions.ApiQualityRuleNotFoundException) List(java.util.List) ApiQualityRule(io.gravitee.repository.management.model.ApiQualityRule) Assert(org.junit.Assert) ApiQualityRuleServiceImpl(io.gravitee.rest.api.service.impl.ApiQualityRuleServiceImpl) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ApiQualityRule(io.gravitee.repository.management.model.ApiQualityRule) Date(java.util.Date) Test(org.junit.Test)

Example 2 with ApiQualityRuleRepository

use of io.gravitee.repository.management.api.ApiQualityRuleRepository 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());
}
Also used : InjectMocks(org.mockito.InjectMocks) Optional.empty(java.util.Optional.empty) API_QUALITY_RULE(io.gravitee.repository.management.model.Audit.AuditProperties.API_QUALITY_RULE) ApiQualityRuleRepository(io.gravitee.repository.management.api.ApiQualityRuleRepository) ImmutableMap(com.google.common.collect.ImmutableMap) 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) Collections.singletonList(java.util.Collections.singletonList) io.gravitee.rest.api.model.quality(io.gravitee.rest.api.model.quality) Mockito(org.mockito.Mockito) ApiQualityRuleNotFoundException(io.gravitee.rest.api.service.exceptions.ApiQualityRuleNotFoundException) List(java.util.List) ApiQualityRule(io.gravitee.repository.management.model.ApiQualityRule) Assert(org.junit.Assert) ApiQualityRuleServiceImpl(io.gravitee.rest.api.service.impl.ApiQualityRuleServiceImpl) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ApiQualityRule(io.gravitee.repository.management.model.ApiQualityRule) 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 ApiQualityRule (io.gravitee.repository.management.model.ApiQualityRule)2 API_QUALITY_RULE (io.gravitee.repository.management.model.Audit.AuditProperties.API_QUALITY_RULE)2 io.gravitee.rest.api.model.quality (io.gravitee.rest.api.model.quality)2 ApiQualityRuleNotFoundException (io.gravitee.rest.api.service.exceptions.ApiQualityRuleNotFoundException)2 ApiQualityRuleServiceImpl (io.gravitee.rest.api.service.impl.ApiQualityRuleServiceImpl)2 Collections.singletonList (java.util.Collections.singletonList)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 (org.junit.Assert)2 Test (org.junit.Test)2 RunWith (org.junit.runner.RunWith)2 InjectMocks (org.mockito.InjectMocks)2 Mock (org.mockito.Mock)2 Mockito (org.mockito.Mockito)2 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)2