Search in sources :

Example 1 with ApiService

use of io.gravitee.rest.api.service.ApiService in project gravitee-management-rest-api by gravitee-io.

the class ScheduledSubscriptionsServiceTest method shouldCloseOutdatedSubscriptions.

@Test
public void shouldCloseOutdatedSubscriptions() {
    ApiEntity apiEntity = mock(ApiEntity.class);
    when(apiEntity.getId()).thenReturn("API_ID");
    SubscriptionEntity endDateInThePast = mock(SubscriptionEntity.class);
    when(endDateInThePast.getId()).thenReturn("end_date_in_the_past");
    when(apiService.findAllLight()).thenReturn(Collections.singleton(apiEntity));
    when(subscriptionService.search(argThat(subscriptionQuery -> subscriptionQuery.getApis().equals(Collections.singleton("API_ID")) && subscriptionQuery.getStatuses().equals(Collections.singleton(SubscriptionStatus.ACCEPTED)) && subscriptionQuery.getEndingAtBefore() > 0))).thenReturn(new HashSet<>(Collections.singletonList(endDateInThePast)));
    service.run();
    verify(apiService, times(1)).findAllLight();
    verify(subscriptionService, times(1)).close("end_date_in_the_past");
}
Also used : InjectMocks(org.mockito.InjectMocks) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) SubscriptionStatus(io.gravitee.rest.api.model.SubscriptionStatus) Date(java.util.Date) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Test(org.junit.Test) ApiService(io.gravitee.rest.api.service.ApiService) HashSet(java.util.HashSet) Mockito(org.mockito.Mockito) SubscriptionService(io.gravitee.rest.api.service.SubscriptionService) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Test(org.junit.Test)

Aggregations

SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)1 SubscriptionStatus (io.gravitee.rest.api.model.SubscriptionStatus)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 ApiService (io.gravitee.rest.api.service.ApiService)1 SubscriptionService (io.gravitee.rest.api.service.SubscriptionService)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 InjectMocks (org.mockito.InjectMocks)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)1