Search in sources :

Example 11 with PageRepository

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PageServiceImpl(io.gravitee.rest.api.service.impl.PageServiceImpl) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) TemplateException(freemarker.template.TemplateException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) PageReferenceType(io.gravitee.repository.management.model.PageReferenceType) NotificationTemplateService(io.gravitee.rest.api.service.notification.NotificationTemplateService) Sets(org.mockito.internal.util.collections.Sets) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) PageRepository(io.gravitee.repository.management.api.PageRepository) io.gravitee.rest.api.model(io.gravitee.rest.api.model) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Test(org.junit.Test) Mockito(org.mockito.Mockito) ReflectionTestUtils.setField(org.springframework.test.util.ReflectionTestUtils.setField) Page(io.gravitee.repository.management.model.Page) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) Optional(java.util.Optional) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SearchEngineService(io.gravitee.rest.api.service.search.SearchEngineService) Page(io.gravitee.repository.management.model.Page) Test(org.junit.Test)

Example 12 with PageRepository

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) PageServiceImpl(io.gravitee.rest.api.service.impl.PageServiceImpl) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ImportConfiguration(io.gravitee.rest.api.service.spring.ImportConfiguration) URL(java.net.URL) Mock(org.mockito.Mock) TemplateException(freemarker.template.TemplateException) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) HashMap(java.util.HashMap) PageReferenceType(io.gravitee.repository.management.model.PageReferenceType) NotificationTemplateService(io.gravitee.rest.api.service.notification.NotificationTemplateService) Map(java.util.Map) PageRepository(io.gravitee.repository.management.api.PageRepository) io.gravitee.rest.api.model(io.gravitee.rest.api.model) InjectMocks(org.mockito.InjectMocks) Charsets(com.google.common.base.Charsets) Resources(com.google.common.io.Resources) Assert.assertNotNull(org.junit.Assert.assertNotNull) IOException(java.io.IOException) Test(org.junit.Test) Mockito(org.mockito.Mockito) ReflectionTestUtils.setField(org.springframework.test.util.ReflectionTestUtils.setField) MediaType(io.gravitee.common.http.MediaType) Page(io.gravitee.repository.management.model.Page) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) SearchEngineService(io.gravitee.rest.api.service.search.SearchEngineService) HashMap(java.util.HashMap) Page(io.gravitee.repository.management.model.Page) Test(org.junit.Test)

Aggregations

PageRepository (io.gravitee.repository.management.api.PageRepository)12 Page (io.gravitee.repository.management.model.Page)12 PageReferenceType (io.gravitee.repository.management.model.PageReferenceType)12 PageServiceImpl (io.gravitee.rest.api.service.impl.PageServiceImpl)12 Test (org.junit.Test)12 RunWith (org.junit.runner.RunWith)12 Mockito (org.mockito.Mockito)12 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)12 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)11 SearchEngineService (io.gravitee.rest.api.service.search.SearchEngineService)11 Collections (java.util.Collections)11 Optional (java.util.Optional)11 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)11 InjectMocks (org.mockito.InjectMocks)11 Mock (org.mockito.Mock)11 TemplateException (freemarker.template.TemplateException)10 io.gravitee.rest.api.model (io.gravitee.rest.api.model)10 io.gravitee.rest.api.service.exceptions (io.gravitee.rest.api.service.exceptions)10 NotificationTemplateService (io.gravitee.rest.api.service.notification.NotificationTemplateService)10 HashMap (java.util.HashMap)10