Search in sources :

Example 1 with PageLinks

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

the class ApiPageResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    doReturn(mockApi).when(apiService).findById(API);
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any(), argThat(q -> singletonList(API).equals(q.getIds())));
    doReturn(true).when(accessControlService).canAccessApiFromPortal(API);
    PageEntity page1 = new PageEntity();
    page1.setPublished(true);
    page1.setVisibility(Visibility.PUBLIC);
    page1.setContent(PAGE_CONTENT);
    doReturn(page1).when(pageService).findById(PAGE, null);
    doReturn(true).when(accessControlService).canAccessPageFromPortal(API, page1);
    doReturn(new Page()).when(pageMapper).convert(any(), any(), any());
    doReturn(new PageLinks()).when(pageMapper).computePageLinks(any(), any());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) PageLinks(io.gravitee.rest.api.portal.rest.model.PageLinks) Test(org.junit.Test) Error(io.gravitee.rest.api.portal.rest.model.Error) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Page(io.gravitee.rest.api.portal.rest.model.Page) Collections.singletonList(java.util.Collections.singletonList) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Mockito.doThrow(org.mockito.Mockito.doThrow) PageNotFoundException(io.gravitee.rest.api.service.exceptions.PageNotFoundException) Builder(javax.ws.rs.client.Invocation.Builder) Response(javax.ws.rs.core.Response) Visibility(io.gravitee.rest.api.model.Visibility) Assert(org.junit.Assert) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) PageEntity(io.gravitee.rest.api.model.PageEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Page(io.gravitee.rest.api.portal.rest.model.Page) PageLinks(io.gravitee.rest.api.portal.rest.model.PageLinks) Before(org.junit.Before)

Example 2 with PageLinks

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

the class PageResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    PageEntity publishedPage = new PageEntity();
    publishedPage.setPublished(true);
    publishedPage.setVisibility(Visibility.PUBLIC);
    publishedPage.setContent(PAGE_CONTENT);
    doReturn(publishedPage).when(pageService).findById(PUBLISHED_PAGE, null);
    PageEntity unPublishedPage = new PageEntity();
    unPublishedPage.setPublished(false);
    publishedPage.setVisibility(Visibility.PUBLIC);
    unPublishedPage.setContent(PAGE_CONTENT);
    doReturn(unPublishedPage).when(pageService).findById(UNPUBLISHED_PAGE, null);
    mockAnotherPage = new PageEntity();
    mockAnotherPage.setPublished(true);
    publishedPage.setVisibility(Visibility.PUBLIC);
    Map<String, String> metadataMap = new HashMap<>();
    metadataMap.put(ANOTHER_PAGE, ANOTHER_PAGE);
    mockAnotherPage.setMetadata(metadataMap);
    doReturn(mockAnotherPage).when(pageService).findById(ANOTHER_PAGE, null);
    doThrow(new PageNotFoundException(UNKNOWN_PAGE)).when(pageService).findById(UNKNOWN_PAGE, null);
    doReturn(new Page()).when(pageMapper).convert(any(), any(), any());
    doReturn(new PageLinks()).when(pageMapper).computePageLinks(any(), any());
    doReturn(true).when(accessControlService).canAccessApiFromPortal(anyString());
    doReturn(true).when(accessControlService).canAccessPageFromPortal(any());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PageNotFoundException(io.gravitee.rest.api.service.exceptions.PageNotFoundException) HashMap(java.util.HashMap) Page(io.gravitee.rest.api.portal.rest.model.Page) PageLinks(io.gravitee.rest.api.portal.rest.model.PageLinks) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before)

Example 3 with PageLinks

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

the class PagesResourceTest method init.

@Before
public void init() throws IOException {
    resetAllMocks();
    doReturn(new Page()).when(pageMapper).convert(any());
    doReturn(new PageLinks()).when(pageMapper).computePageLinks(any(), any());
}
Also used : Page(io.gravitee.rest.api.portal.rest.model.Page) PageLinks(io.gravitee.rest.api.portal.rest.model.PageLinks) Before(org.junit.Before)

Example 4 with PageLinks

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

the class PageMapperTest method testPageLinks.

@Test
public void testPageLinks() {
    String basePath = "/" + PAGE_ID;
    String parentPath = "/" + PAGE_PARENT;
    PageLinks links = pageMapper.computePageLinks(basePath, parentPath);
    assertNotNull(links);
    assertEquals(basePath, links.getSelf());
    assertEquals(basePath + "/content", links.getContent());
    assertEquals(parentPath, links.getParent());
}
Also used : PageLinks(io.gravitee.rest.api.portal.rest.model.PageLinks) Test(org.junit.Test)

Aggregations

PageLinks (io.gravitee.rest.api.portal.rest.model.PageLinks)4 Page (io.gravitee.rest.api.portal.rest.model.Page)3 Before (org.junit.Before)3 PageEntity (io.gravitee.rest.api.model.PageEntity)2 PageNotFoundException (io.gravitee.rest.api.service.exceptions.PageNotFoundException)2 Test (org.junit.Test)2 HttpStatusCode (io.gravitee.common.http.HttpStatusCode)1 Visibility (io.gravitee.rest.api.model.Visibility)1 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)1 Error (io.gravitee.rest.api.portal.rest.model.Error)1 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)1 java.util (java.util)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 Builder (javax.ws.rs.client.Invocation.Builder)1 Response (javax.ws.rs.core.Response)1 Assert (org.junit.Assert)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1