Search in sources :

Example 21 with PageEntity

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

the class PagesResourceTest method shouldGetNoPageIfAuthorizeAndPublishedPageAndSystemFolder.

@Test
public void shouldGetNoPageIfAuthorizeAndPublishedPageAndSystemFolder() {
    PageEntity publishedPage = new PageEntity();
    publishedPage.setPublished(true);
    publishedPage.setType("SYSTEM_FOLDER");
    doReturn(singletonList(publishedPage)).when(pageService).search(any(), isNull(), eq(GraviteeContext.getCurrentEnvironment()));
    Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    PagesResponse pagesResponse = response.readEntity(PagesResponse.class);
    List<Page> pages = pagesResponse.getData();
    assertNotNull(pages);
    assertEquals(0, pages.size());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Response(javax.ws.rs.core.Response) Page(io.gravitee.rest.api.portal.rest.model.Page) PagesResponse(io.gravitee.rest.api.portal.rest.model.PagesResponse) Test(org.junit.Test)

Example 22 with PageEntity

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

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

the class ApiPagesResourceTest method init.

@Before
public void init() throws IOException {
    resetAllMocks();
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    doReturn(mockApi).when(apiService).findById(API);
    PageEntity markdownTemplate = new PageEntity();
    markdownTemplate.setType(PageType.MARKDOWN_TEMPLATE.name());
    doReturn(Arrays.asList(new PageEntity(), markdownTemplate)).when(pageService).search(any(), isNull(), eq(GraviteeContext.getCurrentEnvironment()));
    when(accessControlService.canAccessPageFromPortal(eq(API), any(PageEntity.class))).thenAnswer(invocationOnMock -> {
        PageEntity page = invocationOnMock.getArgument(1);
        return !PageType.MARKDOWN_TEMPLATE.name().equals(page.getType());
    });
    doReturn(new Page()).when(pageMapper).convert(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) Before(org.junit.Before)

Example 24 with PageEntity

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

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

Aggregations

PageEntity (io.gravitee.rest.api.model.PageEntity)67 Test (org.junit.Test)48 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)15 OAIDescriptor (io.gravitee.rest.api.service.swagger.OAIDescriptor)15 Page (io.gravitee.rest.api.portal.rest.model.Page)13 Response (javax.ws.rs.core.Response)13 UpdatePageEntity (io.gravitee.rest.api.model.UpdatePageEntity)9 PageConfigurationOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.page.PageConfigurationOAITransformer)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)6 EntrypointsOAITransformer (io.gravitee.rest.api.service.impl.swagger.transformer.entrypoints.EntrypointsOAITransformer)6 SwaggerDescriptor (io.gravitee.rest.api.service.swagger.SwaggerDescriptor)5 Before (org.junit.Before)5 Page (io.gravitee.repository.management.model.Page)4 NewPageEntity (io.gravitee.rest.api.model.NewPageEntity)4 PageNotFoundException (io.gravitee.rest.api.service.exceptions.PageNotFoundException)4 ArgumentMatchers (org.mockito.ArgumentMatchers)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 PageRepository (io.gravitee.repository.management.api.PageRepository)3 PageReferenceType (io.gravitee.repository.management.model.PageReferenceType)3