Search in sources :

Example 6 with PageRepository

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)));
}
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)

Example 7 with PageRepository

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());
}
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 8 with PageRepository

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());
}
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)

Example 9 with PageRepository

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());
}
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)

Example 10 with PageRepository

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)));
}
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)

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