use of io.gravitee.repository.management.api.PageRepository in project gravitee-management-rest-api by gravitee-io.
the class PageService_UpdateTest method shouldUnpublishPage.
private void shouldUnpublishPage(PlanStatus planStatus) throws TechnicalException {
final String API_ID = "API_ID_TEST";
Page unpublishedPage = new Page();
unpublishedPage.setId(PAGE_ID);
unpublishedPage.setOrder(1);
unpublishedPage.setReferenceId(API_ID);
unpublishedPage.setReferenceType(PageReferenceType.API);
unpublishedPage.setType("MARKDOWN");
unpublishedPage.setPublished(true);
unpublishedPage.setVisibility("PUBLIC");
doReturn(Optional.of(unpublishedPage)).when(pageRepository).findById(PAGE_ID);
UpdatePageEntity updatePageEntity = new UpdatePageEntity();
updatePageEntity.setPublished(false);
updatePageEntity.setOrder(1);
updatePageEntity.setVisibility(Visibility.PUBLIC);
Page updatedPage = new Page();
updatedPage.setId(PAGE_ID);
updatedPage.setOrder(1);
updatedPage.setReferenceId(API_ID);
updatedPage.setReferenceType(PageReferenceType.API);
updatedPage.setType("MARKDOWN");
updatedPage.setPublished(false);
updatedPage.setVisibility("PUBLIC");
doReturn(updatedPage).when(pageRepository).update(argThat(p -> p.getId().equals(PAGE_ID)));
PlanEntity plan = mock(PlanEntity.class);
when(plan.getGeneralConditions()).thenReturn(PAGE_ID);
when(plan.getStatus()).thenReturn(planStatus);
when(planService.findByApi(API_ID)).thenReturn(Sets.newSet(plan));
pageService.update(PAGE_ID, updatePageEntity);
verify(pageRepository).update(argThat(p -> p.getId().equals(PAGE_ID) && !p.isPublished()));
verify(planService).findByApi(argThat(p -> p.equals(API_ID)));
}
use of io.gravitee.repository.management.api.PageRepository in project gravitee-management-rest-api by gravitee-io.
the class PageService_UpdateTest method shouldNotUpdateLinkPublicationStatus.
@Test
public void shouldNotUpdateLinkPublicationStatus() throws TechnicalException {
Page linkPage = new Page();
linkPage.setId(PAGE_ID);
linkPage.setOrder(1);
linkPage.setPublished(true);
linkPage.setReferenceId("DEFAULT");
linkPage.setReferenceType(PageReferenceType.ENVIRONMENT);
linkPage.setType("LINK");
linkPage.setContent("A");
linkPage.setVisibility("PUBLIC");
doReturn(Optional.of(linkPage)).when(pageRepository).findById(PAGE_ID);
UpdatePageEntity updatePageEntity = new UpdatePageEntity();
updatePageEntity.setPublished(false);
updatePageEntity.setOrder(1);
updatePageEntity.setContent("A");
updatePageEntity.setVisibility(Visibility.PUBLIC);
Page updatedPage = new Page();
updatedPage.setId(PAGE_ID);
updatedPage.setOrder(1);
updatedPage.setReferenceId("DEFAULT");
updatedPage.setReferenceType(PageReferenceType.ENVIRONMENT);
updatedPage.setType("LINK");
updatedPage.setVisibility("PUBLIC");
doReturn(updatedPage).when(pageRepository).update(any());
pageService.update(PAGE_ID, updatePageEntity);
verify(pageRepository).update(argThat(p -> p.isPublished() == linkPage.isPublished()));
verify(pageRevisionService, times(0)).create(any());
}
use of io.gravitee.repository.management.api.PageRepository in project gravitee-management-rest-api by gravitee-io.
the class PageService_CreateTest method shouldCopyPublishedStateWhenCreateLink.
@Test
public void shouldCopyPublishedStateWhenCreateLink() throws TechnicalException {
Page page = new Page();
page.setId("PAGE");
page.setType("MARKDOWN");
page.setPublished(true);
page.setVisibility("PUBLIC");
doReturn(Optional.of(page)).when(pageRepository).findById(PAGE_ID);
Map<String, String> conf = new HashMap<>();
conf.put(PageConfigurationKeys.LINK_RESOURCE_TYPE, PageConfigurationKeys.LINK_RESOURCE_TYPE_PAGE);
NewPageEntity newLink = new NewPageEntity();
newLink.setType(PageType.LINK);
newLink.setParentId("SYS");
newLink.setConfiguration(conf);
newLink.setContent(PAGE_ID);
newLink.setVisibility(Visibility.PUBLIC);
Page createdPage = new Page();
createdPage.setId("NEW_LINK");
createdPage.setReferenceId("DEFAULT");
createdPage.setReferenceType(PageReferenceType.ENVIRONMENT);
createdPage.setVisibility("PUBLIC");
doReturn(createdPage).when(pageRepository).create(any());
pageService.createPage(newLink, GraviteeContext.getCurrentEnvironment());
verify(pageRepository).create(argThat(p -> p.isPublished() == true));
// do not create revision for Link
verify(pageRevisionService, times(0)).create(any());
}
use of io.gravitee.repository.management.api.PageRepository in project gravitee-management-rest-api by gravitee-io.
the class PageService_CreateTest method shouldCreatePublishedLinkForRoot.
@Test
public void shouldCreatePublishedLinkForRoot() throws TechnicalException {
Map<String, String> conf = new HashMap<>();
conf.put(PageConfigurationKeys.LINK_RESOURCE_TYPE, PageConfigurationKeys.LINK_RESOURCE_TYPE_EXTERNAL);
NewPageEntity newFolder = new NewPageEntity();
newFolder.setType(PageType.LINK);
newFolder.setParentId("SYS");
newFolder.setConfiguration(conf);
newFolder.setContent("root");
newFolder.setVisibility(Visibility.PUBLIC);
Page createdPage = new Page();
createdPage.setId("NEW_LINK");
createdPage.setReferenceId("DEFAULT");
createdPage.setReferenceType(PageReferenceType.ENVIRONMENT);
createdPage.setVisibility("PUBLIC");
doReturn(createdPage).when(pageRepository).create(any());
pageService.createPage(newFolder, GraviteeContext.getCurrentEnvironment());
verify(pageRepository).create(argThat(p -> p.isPublished() == true));
// do not create revision for Link
verify(pageRevisionService, times(0)).create(any());
}
use of io.gravitee.repository.management.api.PageRepository in project gravitee-management-rest-api by gravitee-io.
the class PageService_UpdateTest method shouldNotUnpublishPage_LinkedToCategory.
@Test(expected = PageUsedByCategoryException.class)
public void shouldNotUnpublishPage_LinkedToCategory() throws TechnicalException {
final String API_ID = "API_ID_TEST";
Page unpublishedPage = new Page();
unpublishedPage.setId(PAGE_ID);
unpublishedPage.setOrder(1);
unpublishedPage.setReferenceId(API_ID);
unpublishedPage.setReferenceType(PageReferenceType.ENVIRONMENT);
unpublishedPage.setType("MARKDOWN");
unpublishedPage.setPublished(true);
unpublishedPage.setVisibility("PUBLIC");
doReturn(Optional.of(unpublishedPage)).when(pageRepository).findById(PAGE_ID);
UpdatePageEntity updatePageEntity = new UpdatePageEntity();
updatePageEntity.setPublished(false);
updatePageEntity.setOrder(1);
updatePageEntity.setVisibility(Visibility.PUBLIC);
when(categoryService.findByPage(PAGE_ID)).thenReturn(Collections.singletonList(new CategoryEntity()));
pageService.update(PAGE_ID, updatePageEntity);
verify(planService).findByApi(argThat(p -> p.equals(API_ID)));
}
Aggregations