Search in sources :

Example 11 with Page

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

the class PageResourceTest method shouldGetPage.

@Test
public void shouldGetPage() {
    final Response response = target(PUBLISHED_PAGE).request().get();
    assertEquals(OK_200, response.getStatus());
    final Page pageResponse = response.readEntity(Page.class);
    assertNotNull(pageResponse);
    assertNull(pageResponse.getContent());
    assertNotNull(pageResponse.getLinks());
}
Also used : ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) Page(io.gravitee.rest.api.portal.rest.model.Page) Test(org.junit.Test)

Example 12 with Page

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

the class ApiResourceNotAuthenticatedTest method init.

@Before
public void init() {
    resetAllMocks();
    mockApi = new ApiEntity();
    mockApi.setId(API);
    doReturn(mockApi).when(apiService).findById(API);
    when(accessControlService.canAccessApiFromPortal(API)).thenReturn(true);
    when(accessControlService.canAccessApiFromPortal(mockApi)).thenReturn(true);
    doReturn(Arrays.asList(new PageEntity())).when(pageService).search(any(), eq(GraviteeContext.getCurrentEnvironment()));
    PlanEntity plan1 = new PlanEntity();
    plan1.setId("A");
    plan1.setStatus(PlanStatus.PUBLISHED);
    PlanEntity plan2 = new PlanEntity();
    plan2.setId("B");
    plan2.setStatus(PlanStatus.PUBLISHED);
    PlanEntity plan3 = new PlanEntity();
    plan3.setId("C");
    plan3.setStatus(PlanStatus.CLOSED);
    doReturn(new HashSet<PlanEntity>(Arrays.asList(plan1, plan2, plan3))).when(planService).findByApi(API);
    doReturn(new Api()).when(apiMapper).convert(any());
    doReturn(new Page()).when(pageMapper).convert(any());
    doReturn(new Plan()).when(planMapper).convert(any());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PlanEntity(io.gravitee.rest.api.model.PlanEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Page(io.gravitee.rest.api.portal.rest.model.Page) Api(io.gravitee.rest.api.portal.rest.model.Api) Plan(io.gravitee.rest.api.portal.rest.model.Plan) Before(org.junit.Before)

Example 13 with Page

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

the class PagesResourceTest method shouldGetNoPageIfAuthorizeAndNotPublished.

@Test
public void shouldGetNoPageIfAuthorizeAndNotPublished() {
    doReturn(Collections.emptyList()).when(pageService).search(any(), isNull(), eq(GraviteeContext.getCurrentEnvironment()));
    Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    PagesResponse pagesResponse = response.readEntity(PagesResponse.class);
    List<Page> pages = pagesResponse.getData();
    assertNotNull(pages);
    assertEquals(0, pages.size());
}
Also used : PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Response(javax.ws.rs.core.Response) Page(io.gravitee.rest.api.portal.rest.model.Page) PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Test(org.junit.Test)

Example 14 with Page

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

the class PagesResourceTest method shouldGetNoPageIfNotAuthorizeAndPublishedPageAndNotSystemFolder.

@Test
public void shouldGetNoPageIfNotAuthorizeAndPublishedPageAndNotSystemFolder() {
    PageEntity publishedPage = new PageEntity();
    publishedPage.setPublished(true);
    doReturn(singletonList(publishedPage)).when(pageService).search(any(), isNull(), eq(GraviteeContext.getCurrentEnvironment()));
    Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    PagesResponse pagesResponse = response.readEntity(PagesResponse.class);
    List<Page> pages = pagesResponse.getData();
    assertNotNull(pages);
    assertEquals(0, pages.size());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Response(javax.ws.rs.core.Response) Page(io.gravitee.rest.api.portal.rest.model.Page) PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Test(org.junit.Test)

Example 15 with Page

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

the class PagesResourceTest method shouldGetPagesIfAuthorizeAndPublishedPageAndNotSystemFolder.

@Test
public void shouldGetPagesIfAuthorizeAndPublishedPageAndNotSystemFolder() {
    PageEntity publishedPage = new PageEntity();
    publishedPage.setPublished(true);
    PageEntity markdownTemplatePage = new PageEntity();
    markdownTemplatePage.setPublished(true);
    markdownTemplatePage.setType(PageType.MARKDOWN_TEMPLATE.name());
    doReturn(Arrays.asList(publishedPage, markdownTemplatePage)).when(pageService).search(any(), isNull(), eq(GraviteeContext.getCurrentEnvironment()));
    when(accessControlService.canAccessPageFromPortal(any(PageEntity.class))).thenAnswer(invocationOnMock -> {
        PageEntity page = invocationOnMock.getArgument(0);
        return !PageType.MARKDOWN_TEMPLATE.name().equals(page.getType());
    });
    final Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    final PagesResponse pagesResponse = response.readEntity(PagesResponse.class);
    List<Page> pages = pagesResponse.getData();
    assertNotNull(pages);
    assertEquals(1, pages.size());
    assertNotNull(pages.get(0).getLinks());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Response(javax.ws.rs.core.Response) Page(io.gravitee.rest.api.portal.rest.model.Page) PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Test(org.junit.Test)

Aggregations

Page (io.gravitee.rest.api.portal.rest.model.Page)24 Response (javax.ws.rs.core.Response)14 Test (org.junit.Test)14 PageEntity (io.gravitee.rest.api.model.PageEntity)13 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)7 Before (org.junit.Before)6 PagesResponse (io.gravitee.rest.api.portal.rest.model.PagesResponse)4 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)3 PageLinks (io.gravitee.rest.api.portal.rest.model.PageLinks)3 RequirePortalAuth (io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)3 ArrayList (java.util.ArrayList)3 Visibility (io.gravitee.rest.api.model.Visibility)2 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)2 Api (io.gravitee.rest.api.portal.rest.model.Api)2 Metadata (io.gravitee.rest.api.portal.rest.model.Metadata)2 PageConfiguration (io.gravitee.rest.api.portal.rest.model.PageConfiguration)2 Plan (io.gravitee.rest.api.portal.rest.model.Plan)2 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)2 PageNotFoundException (io.gravitee.rest.api.service.exceptions.PageNotFoundException)2 UnauthorizedAccessException (io.gravitee.rest.api.service.exceptions.UnauthorizedAccessException)2