Search in sources :

Example 6 with PageEntity

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);
}
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 7 with PageEntity

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();
}
Also used : UpdatePageEntity(io.gravitee.management.model.UpdatePageEntity) NewPageEntity(io.gravitee.management.model.NewPageEntity) PageEntity(io.gravitee.management.model.PageEntity) Permissions(io.gravitee.management.rest.security.Permissions)

Example 8 with PageEntity

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);
}
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 9 with PageEntity

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);
}
Also used : PageEntity(io.gravitee.management.model.PageEntity) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.management.model.ApiEntity) RolePermissionAction(io.gravitee.management.model.permissions.RolePermissionAction) Test(org.junit.Test)

Example 10 with PageEntity

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

Aggregations

PageEntity (io.gravitee.management.model.PageEntity)13 Test (org.junit.Test)11 ApiEntity (io.gravitee.management.model.ApiEntity)5 Response (javax.ws.rs.core.Response)5 NewPageEntity (io.gravitee.management.model.NewPageEntity)2 PageConfigurationEntity (io.gravitee.management.model.PageConfigurationEntity)1 UpdatePageEntity (io.gravitee.management.model.UpdatePageEntity)1 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)1 Permissions (io.gravitee.management.rest.security.Permissions)1 Page (io.gravitee.repository.management.model.Page)1 URL (java.net.URL)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1 Matchers.anyString (org.mockito.Matchers.anyString)1