Search in sources :

Example 16 with PageEntity

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

the class ConfigurationResourceTest method shouldGetPortalLinks.

@Test
public void shouldGetPortalLinks() {
    resetAllMocks();
    PageEntity sysFolder = new PageEntity();
    sysFolder.setId("SYS_FOLDER");
    sysFolder.setType("SYSTEM_FOLDER");
    sysFolder.setName("SYSTEM_FOLDER");
    sysFolder.setPublished(true);
    PageEntity linkSysFolder = new PageEntity();
    linkSysFolder.setId("LINK_SYS_FOLDER");
    linkSysFolder.setParentId("SYS_FOLDER");
    linkSysFolder.setType("LINK");
    linkSysFolder.setName("LINK");
    linkSysFolder.setContent("LINK_RES_REF");
    linkSysFolder.setPublished(true);
    Map<String, String> linkConf = new HashMap<>();
    linkConf.put(PageConfigurationKeys.LINK_RESOURCE_TYPE, "external");
    linkSysFolder.setConfiguration(linkConf);
    PageEntity swaggerSysFolder = new PageEntity();
    swaggerSysFolder.setId("SWAGGER_SYS_FOLDER");
    swaggerSysFolder.setParentId("SYS_FOLDER");
    swaggerSysFolder.setType("SWAGGER");
    swaggerSysFolder.setName("SWAGGER");
    swaggerSysFolder.setPublished(true);
    PageEntity folderSysFolder = new PageEntity();
    folderSysFolder.setId("FOLDER_SYS_FOLDER");
    folderSysFolder.setParentId("SYS_FOLDER");
    folderSysFolder.setType("FOLDER");
    folderSysFolder.setName("FOLDER");
    folderSysFolder.setPublished(true);
    PageEntity markdownFolderSysFolder = new PageEntity();
    markdownFolderSysFolder.setId("MARKDOWN_FOLDER_SYS_FOLDER");
    markdownFolderSysFolder.setParentId("FOLDER_SYS_FOLDER");
    markdownFolderSysFolder.setType("MARKDOWN");
    markdownFolderSysFolder.setName("MARKDOWN");
    markdownFolderSysFolder.setPublished(true);
    PageEntity markdownTemplate = new PageEntity();
    markdownTemplate.setId("MARKDOWN_TEMPLATE");
    markdownTemplate.setParentId("SYS_FOLDER");
    markdownTemplate.setType("MARKDOWN_TEMPLATE");
    markdownTemplate.setName("MARKDOWN_TEMPLATE");
    markdownTemplate.setPublished(true);
    when(pageService.search(any(PageQuery.class), isNull(), eq(GraviteeContext.getCurrentEnvironment()))).thenAnswer((Answer<List<PageEntity>>) invocation -> {
        PageQuery pq = invocation.getArgument(0);
        if (PageType.SYSTEM_FOLDER.equals(pq.getType())) {
            return Arrays.asList(sysFolder);
        } else if ("SYS_FOLDER".equals(pq.getParent())) {
            return Arrays.asList(linkSysFolder, swaggerSysFolder, folderSysFolder, markdownTemplate);
        } else if ("FOLDER_SYS_FOLDER".equals(pq.getParent())) {
            return Arrays.asList(markdownFolderSysFolder);
        }
        return null;
    });
    when(accessControlService.canAccessPageFromPortal(any())).thenReturn(true);
    final Response response = target("/links").request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    final LinksResponse links = response.readEntity(LinksResponse.class);
    assertNotNull(links);
    Map<String, List<CategorizedLinks>> slots = links.getSlots();
    assertNotNull(slots);
    assertEquals(1, slots.size());
    List<CategorizedLinks> sysFolderList = slots.get("system_folder");
    assertNotNull(sysFolderList);
    assertEquals(2, sysFolderList.size());
    CategorizedLinks rootCat = sysFolderList.get(0);
    assertNotNull(rootCat);
    assertTrue(rootCat.getRoot());
    assertEquals("SYSTEM_FOLDER", rootCat.getCategory());
    List<Link> rootCatLinks = rootCat.getLinks();
    assertNotNull(rootCatLinks);
    assertEquals(2, rootCatLinks.size());
    Link rootCatLink = rootCatLinks.get(0);
    assertNotNull(rootCatLink);
    assertEquals("LINK", rootCatLink.getName());
    assertEquals("LINK_RES_REF", rootCatLink.getResourceRef());
    assertEquals(ResourceTypeEnum.EXTERNAL, rootCatLink.getResourceType());
    assertNull(rootCatLink.getFolder());
    Link rootCatSwagger = rootCatLinks.get(1);
    assertNotNull(rootCatSwagger);
    assertEquals("SWAGGER", rootCatSwagger.getName());
    assertEquals("SWAGGER_SYS_FOLDER", rootCatSwagger.getResourceRef());
    assertEquals(ResourceTypeEnum.PAGE, rootCatSwagger.getResourceType());
    CategorizedLinks folderCat = sysFolderList.get(1);
    assertNotNull(folderCat);
    assertFalse(folderCat.getRoot());
    assertEquals("FOLDER", folderCat.getCategory());
    List<Link> folderCatLinks = folderCat.getLinks();
    assertNotNull(folderCatLinks);
    assertEquals(1, folderCatLinks.size());
    Link folderCatMarkdown = folderCatLinks.get(0);
    assertNotNull(folderCatMarkdown);
    assertEquals("MARKDOWN", folderCatMarkdown.getName());
    assertEquals("MARKDOWN_FOLDER_SYS_FOLDER", folderCatMarkdown.getResourceRef());
    assertEquals(ResourceTypeEnum.PAGE, folderCatMarkdown.getResourceType());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PageEntity(io.gravitee.rest.api.model.PageEntity) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) PortalSettingsEntity(io.gravitee.rest.api.model.settings.PortalSettingsEntity) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) PageType(io.gravitee.rest.api.model.PageType) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ApplicationGrantTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationGrantTypeEntity) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) Valid(javax.validation.Valid) Answer(org.mockito.stubbing.Answer) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) Mockito.doReturn(org.mockito.Mockito.doReturn) ApplicationTypesEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypesEntity) ResourceTypeEnum(io.gravitee.rest.api.portal.rest.model.Link.ResourceTypeEnum) ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) io.gravitee.rest.api.portal.rest.model(io.gravitee.rest.api.portal.rest.model) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) RoleEntity(io.gravitee.rest.api.model.RoleEntity) Mockito(org.mockito.Mockito) Response(javax.ws.rs.core.Response) Assert(org.junit.Assert) PageConfigurationKeys(io.gravitee.rest.api.model.PageConfigurationKeys) PageQuery(io.gravitee.rest.api.model.documentation.PageQuery) Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 17 with PageEntity

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

the class PageResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    PageEntity publishedPage = new PageEntity();
    publishedPage.setPublished(true);
    publishedPage.setVisibility(Visibility.PUBLIC);
    publishedPage.setContent(PAGE_CONTENT);
    doReturn(publishedPage).when(pageService).findById(PUBLISHED_PAGE, null);
    PageEntity unPublishedPage = new PageEntity();
    unPublishedPage.setPublished(false);
    publishedPage.setVisibility(Visibility.PUBLIC);
    unPublishedPage.setContent(PAGE_CONTENT);
    doReturn(unPublishedPage).when(pageService).findById(UNPUBLISHED_PAGE, null);
    mockAnotherPage = new PageEntity();
    mockAnotherPage.setPublished(true);
    publishedPage.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);
    doThrow(new PageNotFoundException(UNKNOWN_PAGE)).when(pageService).findById(UNKNOWN_PAGE, null);
    doReturn(new Page()).when(pageMapper).convert(any(), any(), any());
    doReturn(new PageLinks()).when(pageMapper).computePageLinks(any(), any());
    doReturn(true).when(accessControlService).canAccessApiFromPortal(anyString());
    doReturn(true).when(accessControlService).canAccessPageFromPortal(any());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PageNotFoundException(io.gravitee.rest.api.service.exceptions.PageNotFoundException) HashMap(java.util.HashMap) Page(io.gravitee.rest.api.portal.rest.model.Page) PageLinks(io.gravitee.rest.api.portal.rest.model.PageLinks) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before)

Example 18 with PageEntity

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

the class ApiResourceNotAuthenticatedTest method init.

@Before
public void init() {
    resetAllMocks();
    mockApi = new ApiEntity();
    mockApi.setId(API);
    doReturn(mockApi).when(apiService).findById(API);
    when(accessControlService.canAccessApiFromPortal(API)).thenReturn(true);
    when(accessControlService.canAccessApiFromPortal(mockApi)).thenReturn(true);
    doReturn(Arrays.asList(new PageEntity())).when(pageService).search(any(), eq(GraviteeContext.getCurrentEnvironment()));
    PlanEntity plan1 = new PlanEntity();
    plan1.setId("A");
    plan1.setStatus(PlanStatus.PUBLISHED);
    PlanEntity plan2 = new PlanEntity();
    plan2.setId("B");
    plan2.setStatus(PlanStatus.PUBLISHED);
    PlanEntity plan3 = new PlanEntity();
    plan3.setId("C");
    plan3.setStatus(PlanStatus.CLOSED);
    doReturn(new HashSet<PlanEntity>(Arrays.asList(plan1, plan2, plan3))).when(planService).findByApi(API);
    doReturn(new Api()).when(apiMapper).convert(any());
    doReturn(new Page()).when(pageMapper).convert(any());
    doReturn(new Plan()).when(planMapper).convert(any());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PlanEntity(io.gravitee.rest.api.model.PlanEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Page(io.gravitee.rest.api.portal.rest.model.Page) Api(io.gravitee.rest.api.portal.rest.model.Api) Plan(io.gravitee.rest.api.portal.rest.model.Plan) Before(org.junit.Before)

Example 19 with PageEntity

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

the class PagesResourceTest method shouldGetNoPageIfNotAuthorizeAndPublishedPageAndNotSystemFolder.

@Test
public void shouldGetNoPageIfNotAuthorizeAndPublishedPageAndNotSystemFolder() {
    PageEntity publishedPage = new PageEntity();
    publishedPage.setPublished(true);
    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 20 with PageEntity

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

the class PagesResourceTest method shouldGetPagesIfAuthorizeAndPublishedPageAndNotSystemFolder.

@Test
public void shouldGetPagesIfAuthorizeAndPublishedPageAndNotSystemFolder() {
    PageEntity publishedPage = new PageEntity();
    publishedPage.setPublished(true);
    PageEntity markdownTemplatePage = new PageEntity();
    markdownTemplatePage.setPublished(true);
    markdownTemplatePage.setType(PageType.MARKDOWN_TEMPLATE.name());
    doReturn(Arrays.asList(publishedPage, markdownTemplatePage)).when(pageService).search(any(), isNull(), eq(GraviteeContext.getCurrentEnvironment()));
    when(accessControlService.canAccessPageFromPortal(any(PageEntity.class))).thenAnswer(invocationOnMock -> {
        PageEntity page = invocationOnMock.getArgument(0);
        return !PageType.MARKDOWN_TEMPLATE.name().equals(page.getType());
    });
    final Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    final PagesResponse pagesResponse = response.readEntity(PagesResponse.class);
    List<Page> pages = pagesResponse.getData();
    assertNotNull(pages);
    assertEquals(1, pages.size());
    assertNotNull(pages.get(0).getLinks());
}
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)

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