use of io.gravitee.repository.management.api.PageRepository in project gravitee-management-rest-api by gravitee-io.
the class PageService_UpdateTest method shouldUpdateOrderDecrement.
@Test
public void shouldUpdateOrderDecrement() throws TechnicalException {
final Page pageOrder1 = new Page();
pageOrder1.setId(PAGE_ID);
pageOrder1.setOrder(1);
pageOrder1.setReferenceId(API_ID);
pageOrder1.setReferenceType(PageReferenceType.API);
pageOrder1.setPublished(true);
pageOrder1.setVisibility("PUBLIC");
final Page pageOrder2 = new Page();
pageOrder2.setId("2");
pageOrder2.setOrder(2);
pageOrder2.setReferenceId(API_ID);
pageOrder2.setReferenceType(PageReferenceType.API);
pageOrder2.setVisibility("PUBLIC");
final Page pageOrder3 = new Page();
pageOrder3.setId("3");
pageOrder3.setOrder(3);
pageOrder3.setReferenceId(API_ID);
pageOrder3.setReferenceType(PageReferenceType.API);
pageOrder3.setVisibility("PUBLIC");
when(pageRepository.findById("3")).thenReturn(Optional.of(pageOrder3));
when(pageRepository.search(argThat(o -> o == null || o.getReferenceId().equals(API_ID)))).thenReturn(asList(pageOrder1, pageOrder2, pageOrder3));
when(pageRepository.update(any(Page.class))).thenReturn(pageOrder1);
final UpdatePageEntity updatePageEntity = new UpdatePageEntity();
updatePageEntity.setOrder(1);
updatePageEntity.setVisibility(Visibility.PUBLIC);
pageService.update("3", updatePageEntity);
verify(pageRepository, times(3)).update(argThat(pageToUpdate -> {
if (PAGE_ID.equals(pageToUpdate.getId())) {
return pageToUpdate.getOrder() == 2;
}
if ("2".equals(pageToUpdate.getId())) {
return pageToUpdate.getOrder() == 3;
}
if ("3".equals(pageToUpdate.getId())) {
return pageToUpdate.getOrder() == 1;
}
return false;
}));
// neither content nor name are updated
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 shouldCopyPublishedStateWhenCreateTranslation.
@Test
public void shouldCopyPublishedStateWhenCreateTranslation() throws TechnicalException {
Page page = new Page();
page.setId(PAGE_ID);
page.setType("MARKDOWN");
page.setPublished(true);
doReturn(Optional.of(page)).when(pageRepository).findById(PAGE_ID);
NewPageEntity newTranslation = new NewPageEntity();
newTranslation.setType(PageType.TRANSLATION);
newTranslation.setParentId(PAGE_ID);
Map<String, String> conf = new HashMap<>();
conf.put(PageConfigurationKeys.TRANSLATION_LANG, "fr");
newTranslation.setConfiguration(conf);
newTranslation.setPublished(false);
newTranslation.setVisibility(Visibility.PUBLIC);
Page createdPage = new Page();
createdPage.setId("NEW_TRANSLATION");
createdPage.setType("TRANSLATION");
createdPage.setReferenceId("DEFAULT");
createdPage.setReferenceType(PageReferenceType.ENVIRONMENT);
createdPage.setVisibility("PUBLIC");
doReturn(createdPage).when(pageRepository).create(any());
pageService.createPage(newTranslation, GraviteeContext.getCurrentEnvironment());
verify(pageRepository).create(argThat(p -> p.isPublished() == true));
// create revision for translate if the parent page is a Markdown or Swagger
verify(pageRevisionService, times(1)).create(any());
}
Aggregations