Search in sources :

Example 1 with PageMediaEntity

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

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

the class MediaServiceImpl method findAllWithoutContent.

@Override
public List<MediaEntity> findAllWithoutContent(List<PageMediaEntity> pageMediaEntities, String api) {
    List<MediaEntity> result = new ArrayList<>();
    if (pageMediaEntities != null && !pageMediaEntities.isEmpty()) {
        for (PageMediaEntity pme : pageMediaEntities) {
            final Optional<Media> foundMedia = mediaRepository.findByHashAndApi(pme.getMediaHash(), api, false);
            if (foundMedia.isPresent()) {
                MediaEntity me = this.convert(foundMedia.get());
                me.setFileName(pme.getMediaName());
                me.setUploadDate(pme.getAttachedAt());
                result.add(me);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Media(io.gravitee.repository.media.model.Media) PageMediaEntity(io.gravitee.rest.api.model.PageMediaEntity) PageMediaEntity(io.gravitee.rest.api.model.PageMediaEntity) MediaEntity(io.gravitee.rest.api.model.MediaEntity)

Aggregations

PageMediaEntity (io.gravitee.rest.api.model.PageMediaEntity)2 Media (io.gravitee.repository.media.model.Media)1 MediaEntity (io.gravitee.rest.api.model.MediaEntity)1 PageEntity (io.gravitee.rest.api.model.PageEntity)1 Metadata (io.gravitee.rest.api.portal.rest.model.Metadata)1 Page (io.gravitee.rest.api.portal.rest.model.Page)1 PageConfiguration (io.gravitee.rest.api.portal.rest.model.PageConfiguration)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1