Search in sources :

Example 6 with ApiQualityRule

use of io.gravitee.repository.management.model.ApiQualityRule in project gravitee-management-rest-api by gravitee-io.

the class ApiQualityRuleServiceTest method shouldFindByApi.

@Test
public void shouldFindByApi() throws TechnicalException {
    final ApiQualityRule aqr = mock(ApiQualityRule.class);
    when(aqr.getApi()).thenReturn(API_ID);
    when(aqr.getQualityRule()).thenReturn(QUALITY_RULE_ID);
    when(aqr.isChecked()).thenReturn(true);
    when(aqr.getCreatedAt()).thenReturn(new Date(1));
    when(aqr.getUpdatedAt()).thenReturn(new Date(2));
    when(apiQualityRuleRepository.findByApi(API_ID)).thenReturn(singletonList(aqr));
    final List<ApiQualityRuleEntity> apiQualityRules = apiQualityRuleService.findByApi(API_ID);
    final ApiQualityRuleEntity apiQualityRuleEntity = apiQualityRules.iterator().next();
    assertEquals(API_ID, apiQualityRuleEntity.getApi());
    assertEquals(QUALITY_RULE_ID, apiQualityRuleEntity.getQualityRule());
    assertTrue(apiQualityRuleEntity.isChecked());
    assertEquals(new Date(1), apiQualityRuleEntity.getCreatedAt());
    assertEquals(new Date(2), apiQualityRuleEntity.getUpdatedAt());
}
Also used : ApiQualityRule(io.gravitee.repository.management.model.ApiQualityRule) Date(java.util.Date) Test(org.junit.Test)

Example 7 with ApiQualityRule

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

ApiQualityRule (io.gravitee.repository.management.model.ApiQualityRule)7 Date (java.util.Date)5 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 Test (org.junit.Test)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ApiQualityRuleRepository (io.gravitee.repository.management.api.ApiQualityRuleRepository)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 List (java.util.List)2 Optional.empty (java.util.Optional.empty)2 Optional.of (java.util.Optional.of)2 Assert (org.junit.Assert)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