Search in sources :

Example 1 with Page

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

the class PageMapperTest method testConvert.

@Test
public void testConvert() {
    // init
    pageEntity = new PageEntity();
    pageEntity.setLastContributor(PAGE_CONTRIBUTOR);
    Map<String, String> configuration = new HashMap<>();
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_DISPLAY_OPERATION_ID, PAGE_CONFIGURATION_DISPLAY_OPERATION_ID);
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_DOC_EXPANSION, PAGE_CONFIGURATION_DOC_EXPANSION);
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_ENABLE_FILTERING, PAGE_CONFIGURATION_ENABLE_FILTERING);
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_MAX_DISPLAYED_TAGS, PAGE_CONFIGURATION_MAX_DISPLAYED_TAGS);
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_SHOW_COMMON_EXTENSIONS, PAGE_CONFIGURATION_SHOW_COMMON_EXTENSIONS);
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_SHOW_EXTENSIONS, PAGE_CONFIGURATION_SHOW_EXTENSIONS);
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_SHOW_URL, PAGE_CONFIGURATION_SHOW_URL);
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_TRY_IT, PAGE_CONFIGURATION_TRY_IT);
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_TRY_IT_ANONYMOUS, PAGE_CONFIGURATION_TRY_IT_ANONYMOUS);
    configuration.put(PageConfigurationKeys.SWAGGER_SWAGGERUI_TRY_IT_URL, PAGE_CONFIGURATION_TRY_IT_URL);
    configuration.put(PageConfigurationKeys.SWAGGER_VIEWER, PAGE_CONFIGURATION_VIEWER);
    pageEntity.setConfiguration(configuration);
    pageEntity.setId(PAGE_ID);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("meta", PAGE_ID);
    pageEntity.setMetadata(metadata);
    pageEntity.setName(PAGE_NAME);
    pageEntity.setOrder(1);
    pageEntity.setParentId(PAGE_PARENT);
    pageEntity.setType(PAGE_TYPE);
    PageMediaEntity pme1 = new PageMediaEntity();
    pme1.setMediaHash("media_id_1");
    pme1.setMediaName("media_name_1");
    PageMediaEntity pme2 = new PageMediaEntity();
    pme2.setMediaHash("media_id_2");
    pme2.setMediaName("media_name_2");
    final List<PageMediaEntity> attachedMedia = Arrays.asList(pme1, pme2);
    pageEntity.setAttachedMedia(attachedMedia);
    Instant now = Instant.now();
    pageEntity.setLastModificationDate(Date.from(now));
    when(mediaService.findAllWithoutContent(attachedMedia, null)).thenReturn(Arrays.asList(mock(MediaEntity.class), mock(MediaEntity.class)));
    // Test
    Page responsePage = pageMapper.convert(UriBuilder.fromPath("/"), null, pageEntity);
    assertNotNull(responsePage);
    PageConfiguration pageConfiguration = responsePage.getConfiguration();
    assertNotNull(pageConfiguration);
    assertFalse(pageConfiguration.getDisplayOperationId());
    assertEquals(DocExpansionEnum.LIST, pageConfiguration.getDocExpansion());
    assertTrue(pageConfiguration.getEnableFiltering());
    assertEquals(42, pageConfiguration.getMaxDisplayedTags());
    assertFalse(pageConfiguration.getShowCommonExtensions());
    assertTrue(pageConfiguration.getShowExtensions());
    assertEquals(PAGE_CONFIGURATION_SHOW_URL, pageConfiguration.getShowUrl());
    assertTrue(pageConfiguration.getTryIt());
    assertFalse(pageConfiguration.getTryItAnonymous());
    assertEquals(PAGE_CONFIGURATION_TRY_IT_URL, pageConfiguration.getTryItUrl());
    assertEquals(ViewerEnum.REDOC, pageConfiguration.getViewer());
    assertEquals(PAGE_ID, responsePage.getId());
    List<Metadata> metadatas = responsePage.getMetadata();
    assertNotNull(metadatas);
    assertEquals(1, metadatas.size());
    Metadata m = metadatas.get(0);
    assertEquals("0", m.getOrder());
    assertEquals("meta", m.getName());
    assertEquals(PAGE_ID, m.getValue());
    assertEquals(PAGE_NAME, responsePage.getName());
    assertEquals(Integer.valueOf(1), responsePage.getOrder());
    assertEquals(PAGE_PARENT, responsePage.getParent());
    assertNotNull(responsePage.getMedia());
    assertEquals(2, responsePage.getMedia().size());
    assertEquals(TypeEnum.SWAGGER, responsePage.getType());
    assertEquals(now.toEpochMilli(), responsePage.getUpdatedAt().toInstant().toEpochMilli());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PageConfiguration(io.gravitee.rest.api.portal.rest.model.PageConfiguration) Instant(java.time.Instant) Metadata(io.gravitee.rest.api.portal.rest.model.Metadata) PageMediaEntity(io.gravitee.rest.api.model.PageMediaEntity) Page(io.gravitee.rest.api.portal.rest.model.Page) Test(org.junit.Test)

Example 2 with Page

use of io.gravitee.rest.api.portal.rest.model.Page 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 3 with Page

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

the class ApiPageResourceTest method shouldNotHaveMetadataCleared.

@Test
public void shouldNotHaveMetadataCleared() {
    PageEntity mockAnotherPage = new PageEntity();
    mockAnotherPage.setPublished(true);
    mockAnotherPage.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);
    Response response = target(API).path("pages").path(ANOTHER_PAGE).request().get();
    assertEquals(OK_200, response.getStatus());
    Page pageResponse = response.readEntity(Page.class);
    assertNotNull(pageResponse);
    assertFalse(mockAnotherPage.getMetadata().isEmpty());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) 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 4 with Page

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

the class ApiPageResourceTest method shouldGetApiPage.

@Test
public void shouldGetApiPage() {
    final Response response = target(API).path("pages").path(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 5 with Page

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

the class ApiPageResourceTest method shouldGetApiPageWithInclude.

@Test
public void shouldGetApiPageWithInclude() {
    final Response response = target(API).path("pages").path(PAGE).queryParam("include", "content").request().get();
    assertEquals(OK_200, response.getStatus());
    final Page pageResponse = response.readEntity(Page.class);
    assertNotNull(pageResponse);
    assertEquals(PAGE_CONTENT, 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)

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