use of io.gravitee.management.model.UpdatePageEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_UpdateTest method shouldUpdateOrderIncrement.
@Test
public void shouldUpdateOrderIncrement() throws TechnicalException {
final Page pageOrder1 = new Page();
pageOrder1.setId(PAGE_ID);
pageOrder1.setOrder(1);
pageOrder1.setApi(API_ID);
final Page pageOrder2 = new Page();
pageOrder2.setId("2");
pageOrder2.setOrder(2);
pageOrder2.setApi(API_ID);
final Page pageOrder3 = new Page();
pageOrder3.setId("3");
pageOrder3.setOrder(3);
pageOrder3.setApi(API_ID);
when(pageRepository.findById(PAGE_ID)).thenReturn(Optional.of(pageOrder1));
when(pageRepository.findApiPageByApiId(API_ID)).thenReturn(asList(pageOrder1, pageOrder2, pageOrder3));
when(pageRepository.update(any(Page.class))).thenReturn(pageOrder1);
final UpdatePageEntity updatePageEntity = new UpdatePageEntity();
updatePageEntity.setOrder(2);
pageService.update(PAGE_ID, updatePageEntity);
verify(pageRepository, times(3)).update(argThat(new ArgumentMatcher<Page>() {
public boolean matches(Object argument) {
final Page pageToUpdate = (Page) argument;
if (PAGE_ID.equals(pageToUpdate.getId())) {
return pageToUpdate.getOrder() == 2;
}
if ("2".equals(pageToUpdate.getId())) {
return pageToUpdate.getOrder() == 1;
}
if ("3".equals(pageToUpdate.getId())) {
return pageToUpdate.getOrder() == 3;
}
return false;
}
}));
}
use of io.gravitee.management.model.UpdatePageEntity 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.setApi(API_ID);
final Page pageOrder2 = new Page();
pageOrder2.setId("2");
pageOrder2.setOrder(2);
pageOrder2.setApi(API_ID);
final Page pageOrder3 = new Page();
pageOrder3.setId("3");
pageOrder3.setOrder(3);
pageOrder3.setApi(API_ID);
when(pageRepository.findById("3")).thenReturn(Optional.of(pageOrder3));
when(pageRepository.findApiPageByApiId(API_ID)).thenReturn(asList(pageOrder1, pageOrder2, pageOrder3));
when(pageRepository.update(any(Page.class))).thenReturn(pageOrder1);
final UpdatePageEntity updatePageEntity = new UpdatePageEntity();
updatePageEntity.setOrder(1);
pageService.update("3", updatePageEntity);
verify(pageRepository, times(3)).update(argThat(new ArgumentMatcher<Page>() {
public boolean matches(Object argument) {
final Page pageToUpdate = (Page) argument;
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;
}
}));
}
Aggregations