Search in sources :

Example 1 with ApiEntity

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());
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) Test(org.junit.Test)

Example 2 with ApiEntity

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));
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) MemberEntity(io.gravitee.management.model.MemberEntity) Test(org.junit.Test)

Example 3 with ApiEntity

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());
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) Test(org.junit.Test)

Example 4 with ApiEntity

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());
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) Test(org.junit.Test)

Example 5 with ApiEntity

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");
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) SubscriptionEntity(io.gravitee.management.model.SubscriptionEntity) SubscriptionQuery(io.gravitee.management.model.subscription.SubscriptionQuery) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ApiEntity (io.gravitee.management.model.ApiEntity)50 Test (org.junit.Test)34 Response (javax.ws.rs.core.Response)19 UpdateApiEntity (io.gravitee.management.model.UpdateApiEntity)13 PageEntity (io.gravitee.management.model.PageEntity)5 NewApiEntity (io.gravitee.management.model.NewApiEntity)4 NewTopApiEntity (io.gravitee.management.model.NewTopApiEntity)3 TopApiEntity (io.gravitee.management.model.TopApiEntity)3 UpdateTopApiEntity (io.gravitee.management.model.UpdateTopApiEntity)3 Permission (io.gravitee.management.rest.security.Permission)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 Proxy (io.gravitee.definition.model.Proxy)2 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)2 MemberEntity (io.gravitee.management.model.MemberEntity)2 SubscriptionEntity (io.gravitee.management.model.SubscriptionEntity)2 UserEntity (io.gravitee.management.model.UserEntity)2 RolePermission (io.gravitee.management.model.permissions.RolePermission)2 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)2 SubscriptionQuery (io.gravitee.management.model.subscription.SubscriptionQuery)2