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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations