use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_IsDisplayableTest method shouldBeDisplayablePublicApiAndPublishedPageAsAuthenticated.
@Test
public void shouldBeDisplayablePublicApiAndPublishedPageAsAuthenticated() throws TechnicalException {
final ApiEntity apiEntityMock = mock(ApiEntity.class);
doReturn(Visibility.PUBLIC).when(apiEntityMock).getVisibility();
boolean displayable = pageService.isDisplayable(apiEntityMock, true, USERNAME);
assertTrue(displayable);
verify(membershipServiceMock, never()).getMember(any(), any(), any(), any());
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_IsDisplayableTest method shouldBeDisplayablePrivateApiAndPublishedPageAsApiMember.
@Test
public void shouldBeDisplayablePrivateApiAndPublishedPageAsApiMember() throws TechnicalException {
final ApiEntity apiEntityMock = mock(ApiEntity.class);
doReturn(Visibility.PRIVATE).when(apiEntityMock).getVisibility();
doReturn(mock(MemberEntity.class)).when(membershipServiceMock).getMember(eq(MembershipReferenceType.API), any(), eq(USERNAME), eq(RoleScope.API));
boolean displayable = pageService.isDisplayable(apiEntityMock, true, USERNAME);
assertTrue(displayable);
verify(membershipServiceMock, times(1)).getMember(eq(MembershipReferenceType.API), any(), eq(USERNAME), eq(RoleScope.API));
verify(membershipServiceMock, never()).getMember(eq(MembershipReferenceType.GROUP), any(), any(), eq(RoleScope.API));
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_IsDisplayableTest method shouldNotBeDisplayablePrivateApiAndPublishedPageAsUnauthenticated.
@Test
public void shouldNotBeDisplayablePrivateApiAndPublishedPageAsUnauthenticated() throws TechnicalException {
final ApiEntity apiEntityMock = mock(ApiEntity.class);
doReturn(Visibility.PRIVATE).when(apiEntityMock).getVisibility();
boolean displayable = pageService.isDisplayable(apiEntityMock, true, null);
assertFalse(displayable);
verify(membershipServiceMock, never()).getMember(any(), any(), any(), any());
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_IsDisplayableTest method shouldNotBeDisplayablePublicApiAndUnpublishedPageAsUnauthenticated.
/**
* *****************************
* Tests for not published pages
* *****************************
*/
@Test
public void shouldNotBeDisplayablePublicApiAndUnpublishedPageAsUnauthenticated() throws TechnicalException {
final ApiEntity apiEntityMock = mock(ApiEntity.class);
doReturn(Visibility.PUBLIC).when(apiEntityMock).getVisibility();
boolean displayable = pageService.isDisplayable(apiEntityMock, false, null);
assertFalse(displayable);
verify(membershipServiceMock, never()).getMember(any(), any(), any(), any());
}
use of io.gravitee.management.model.ApiEntity 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 = createSubscription("end_date_in_the_past", SubscriptionStatus.ACCEPTED, new Date(0));
SubscriptionEntity noEndDate = createSubscription("no_end_date", SubscriptionStatus.ACCEPTED, null);
SubscriptionEntity endDateInTheFuture = createSubscription("end_date_in_the_future", SubscriptionStatus.ACCEPTED, new Date(Long.MAX_VALUE));
when(apiService.findAll()).thenReturn(Collections.singleton(apiEntity));
SubscriptionQuery query = new SubscriptionQuery();
query.setApi(apiEntity.getId());
query.setStatuses(Collections.singleton(SubscriptionStatus.ACCEPTED));
when(subscriptionService.search(query)).thenReturn(new HashSet<>(Arrays.asList(endDateInThePast, noEndDate, endDateInTheFuture)));
service.run();
verify(apiService, times(1)).findAll();
verify(subscriptionService, times(1)).search(query);
verify(subscriptionService, times(1)).close("end_date_in_the_past");
verify(subscriptionService, never()).close("no_end_date");
verify(subscriptionService, never()).close("end_date_in_the_future");
}
Aggregations