Search in sources :

Example 1 with PageConfiguration

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

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

the class PageMapperTest method testMinimalConvert.

@Test
public void testMinimalConvert() {
    // init
    pageEntity = new PageEntity();
    pageEntity.setType(PAGE_TYPE);
    Instant now = Instant.now();
    pageEntity.setLastModificationDate(Date.from(now));
    // Test
    Page responsePage = pageMapper.convert(pageEntity);
    assertNotNull(responsePage);
    PageConfiguration pageConfiguration = responsePage.getConfiguration();
    assertNull(pageConfiguration);
    List<Metadata> metadatas = responsePage.getMetadata();
    assertNull(metadatas);
    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) Page(io.gravitee.rest.api.portal.rest.model.Page) Test(org.junit.Test)

Aggregations

PageEntity (io.gravitee.rest.api.model.PageEntity)2 Metadata (io.gravitee.rest.api.portal.rest.model.Metadata)2 Page (io.gravitee.rest.api.portal.rest.model.Page)2 PageConfiguration (io.gravitee.rest.api.portal.rest.model.PageConfiguration)2 Instant (java.time.Instant)2 Test (org.junit.Test)2 PageMediaEntity (io.gravitee.rest.api.model.PageMediaEntity)1