Search in sources :

Example 1 with UpdatePageEntity

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;
        }
    }));
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) Page(io.gravitee.repository.management.model.Page) UpdatePageEntity(io.gravitee.management.model.UpdatePageEntity) Test(org.junit.Test)

Example 2 with UpdatePageEntity

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;
        }
    }));
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) Page(io.gravitee.repository.management.model.Page) UpdatePageEntity(io.gravitee.management.model.UpdatePageEntity) Test(org.junit.Test)

Aggregations

UpdatePageEntity (io.gravitee.management.model.UpdatePageEntity)2 Page (io.gravitee.repository.management.model.Page)2 Test (org.junit.Test)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2