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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations