use of io.gravitee.management.model.PageEntity 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.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalPagesResource method createPage.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a page", notes = "User must be ADMIN to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page successfully created", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.PORTAL_DOCUMENTATION, acls = RolePermissionAction.CREATE) })
public Response createPage(@ApiParam(name = "page", required = true) @Valid @NotNull NewPageEntity newPageEntity) {
int order = pageService.findMaxPortalPageOrder() + 1;
newPageEntity.setOrder(order);
newPageEntity.setLastContributor(getAuthenticatedUser());
PageEntity newPage = pageService.createPortalPage(newPageEntity);
if (newPage != null) {
return Response.created(URI.create("/portal/pages/" + newPage.getId())).entity(newPage).build();
}
return Response.serverError().build();
}
use of io.gravitee.management.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPagesResourceAdminTest method shouldGetPublicApiPublishedPage.
@Test
public void shouldGetPublicApiPublishedPage() {
reset(apiService, pageService, membershipService);
final ApiEntity apiMock = mock(ApiEntity.class);
when(apiMock.getVisibility()).thenReturn(Visibility.PUBLIC);
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.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPagesResourceNotAdminTest method shouldNotGetPrivateApiPublishedPage.
@Test
public void shouldNotGetPrivateApiPublishedPage() {
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);
doReturn(false).when(pageService).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
doReturn(true).when(roleService).hasPermission(any(), eq(ApiPermission.DOCUMENTATION), eq(new RolePermissionAction[] { RolePermissionAction.READ }));
when(groupService.isUserAuthorizedToAccessApiData(any(), any(), any())).thenReturn(Boolean.FALSE);
when(permissionService.hasPermission(any(), any(), any())).thenReturn(true);
final Response response = target().request().get();
assertEquals(UNAUTHORIZED_401, response.getStatus());
verify(apiService, atLeastOnce()).findById(API_NAME);
verify(pageService, times(1)).findById(PAGE_NAME, false);
verify(pageService, times(1)).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
}
use of io.gravitee.management.model.PageEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiPagesResourceNotAdminTest method shouldGetPublicApiPublishedPage.
@Test
public void shouldGetPublicApiPublishedPage() {
reset(apiService, pageService, membershipService);
final ApiEntity apiMock = mock(ApiEntity.class);
when(apiMock.getVisibility()).thenReturn(Visibility.PUBLIC);
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);
when(groupService.isUserAuthorizedToAccessApiData(any(), any(), any())).thenReturn(Boolean.TRUE);
when(permissionService.hasPermission(any(), any(), any())).thenReturn(true);
doReturn(pageMock).when(pageService).findById(PAGE_NAME, false);
doReturn(true).when(pageService).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
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(), eq(RoleScope.API));
verify(apiService, times(1)).findById(API_NAME);
verify(pageService, times(1)).findById(PAGE_NAME, false);
verify(pageService, times(1)).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
}
Aggregations