Search in sources :

Example 11 with ApiEntity

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

the class ApiPagesResourceAdminTest method shouldGetPrivateApiPublishedPage.

@Test
public void shouldGetPrivateApiPublishedPage() {
    reset(apiService, pageService, membershipService);
    final ApiEntity apiMock = mock(ApiEntity.class);
    when(apiMock.getVisibility()).thenReturn(Visibility.PRIVATE);
    when(apiMock.getName()).thenReturn(API_NAME);
    doReturn(apiMock).when(apiService).findById(API_NAME);
    final PageEntity pageMock = new PageEntity();
    pageMock.setPublished(true);
    pageMock.setName(PAGE_NAME);
    doReturn(pageMock).when(pageService).findById(PAGE_NAME, false);
    final Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    final PageEntity responsePage = response.readEntity(PageEntity.class);
    assertNotNull(responsePage);
    assertEquals(PAGE_NAME, responsePage.getName());
    verify(membershipService, never()).getRole(any(), any(), any(), any());
    verify(apiService, times(1)).findById(API_NAME);
    verify(pageService, times(1)).findById(PAGE_NAME, false);
    verify(pageService, never()).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
}
Also used : PageEntity(io.gravitee.management.model.PageEntity) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.management.model.ApiEntity) Test(org.junit.Test)

Example 12 with ApiEntity

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

the class ApiPagesResourceAdminTest method shouldGetPrivateApiUnpublishedPage.

@Test
public void shouldGetPrivateApiUnpublishedPage() {
    reset(apiService, pageService, membershipService);
    final ApiEntity apiMock = mock(ApiEntity.class);
    when(apiMock.getVisibility()).thenReturn(Visibility.PRIVATE);
    when(apiMock.getName()).thenReturn(API_NAME);
    doReturn(apiMock).when(apiService).findById(API_NAME);
    final PageEntity pageMock = new PageEntity();
    pageMock.setPublished(false);
    pageMock.setName(PAGE_NAME);
    doReturn(pageMock).when(pageService).findById(PAGE_NAME, false);
    final Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    final PageEntity responsePage = response.readEntity(PageEntity.class);
    assertNotNull(responsePage);
    assertEquals(PAGE_NAME, responsePage.getName());
    verify(membershipService, never()).getRole(any(), any(), any(), any());
    verify(apiService, times(1)).findById(API_NAME);
    verify(pageService, times(1)).findById(PAGE_NAME, false);
    verify(pageService, never()).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
}
Also used : PageEntity(io.gravitee.management.model.PageEntity) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.management.model.ApiEntity) Test(org.junit.Test)

Example 13 with ApiEntity

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

the class ApiResourceTest method shouldNotStartApiBecausePermissionDenied.

@Test
public void shouldNotStartApiBecausePermissionDenied() {
    final ApiEntity mockApi = new ApiEntity();
    mockApi.setName(API_NAME);
    doReturn(Optional.of(mockApi)).when(apiService).findById(API_NAME);
    final Response response = target(API_NAME).queryParam("action", LifecycleActionParam.LifecycleAction.START).request().post(null);
    assertEquals(FORBIDDEN_403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.management.model.ApiEntity) UpdateApiEntity(io.gravitee.management.model.UpdateApiEntity) Test(org.junit.Test)

Example 14 with ApiEntity

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

the class ApiResourceTest method shouldNotStartApiBecauseNotFound.

@Test
public void shouldNotStartApiBecauseNotFound() {
    final ApiEntity mockApi = new ApiEntity();
    mockApi.setName(API_NAME);
    doReturn(Optional.empty()).when(apiService).findById(API_NAME);
    final Response response = target(API_NAME).queryParam("action", LifecycleActionParam.LifecycleAction.START).request().post(null);
    assertEquals(NOT_FOUND_404, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.management.model.ApiEntity) UpdateApiEntity(io.gravitee.management.model.UpdateApiEntity) Test(org.junit.Test)

Example 15 with ApiEntity

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

the class ApiResourceTest method shouldNotGetApiBecausePermissionDenied.

@Test
public void shouldNotGetApiBecausePermissionDenied() {
    final ApiEntity mockApi = new ApiEntity();
    mockApi.setName(API_NAME);
    doReturn(new ApiEntity()).when(apiService).findById(API_NAME);
    final Response response = target(API_NAME).request().get();
    assertEquals(FORBIDDEN_403, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.management.model.ApiEntity) UpdateApiEntity(io.gravitee.management.model.UpdateApiEntity) 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