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