Search in sources :

Example 1 with PageRevisionEntity

use of io.gravitee.rest.api.model.PageRevisionEntity in project gravitee-management-rest-api by gravitee-io.

the class PageRevisionServiceImpl method convert.

private PageRevisionEntity convert(PageRevision revision) {
    PageRevisionEntity entity = new PageRevisionEntity();
    entity.setPageId(revision.getPageId());
    entity.setRevision(revision.getRevision());
    entity.setName(revision.getName());
    entity.setContent(revision.getContent());
    entity.setHash(revision.getHash());
    entity.setContributor(revision.getContributor());
    entity.setModificationDate(revision.getCreatedAt());
    return entity;
}
Also used : PageRevisionEntity(io.gravitee.rest.api.model.PageRevisionEntity)

Example 2 with PageRevisionEntity

use of io.gravitee.rest.api.model.PageRevisionEntity in project gravitee-management-rest-api by gravitee-io.

the class PageRevisionServiceImpl method findAll.

@Override
public io.gravitee.common.data.domain.Page<PageRevisionEntity> findAll(Pageable pageable) {
    logger.debug("get all page revisions with pageable {}", pageable);
    try {
        io.gravitee.common.data.domain.Page<PageRevision> revisions = pageRevisionRepository.findAll(pageable);
        List<PageRevisionEntity> revisionEntities = revisions.getContent().stream().map(this::convert).collect(Collectors.toList());
        return new io.gravitee.common.data.domain.Page<PageRevisionEntity>(revisionEntities, revisions.getPageNumber(), revisionEntities.size(), revisions.getTotalElements());
    } catch (TechnicalException e) {
        logger.warn("An error occurs while trying to get the page revisions {}", pageable, e);
        throw new TechnicalManagementException("An error occurs while trying to get all page revisions", e);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Page(io.gravitee.repository.management.model.Page) PageRevision(io.gravitee.repository.management.model.PageRevision) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) PageRevisionEntity(io.gravitee.rest.api.model.PageRevisionEntity)

Example 3 with PageRevisionEntity

use of io.gravitee.rest.api.model.PageRevisionEntity in project gravitee-management-rest-api by gravitee-io.

the class PageRevisionServiceTest method shouldCreateRevision_PortalPage.

@Test
public void shouldCreateRevision_PortalPage() throws TechnicalException {
    Date now = new Date();
    Page page = mock(Page.class);
    when(page.getId()).thenReturn(PAGE_ID);
    when(page.getName()).thenReturn("SomeName");
    when(page.getContent()).thenReturn("SomeContent");
    when(page.getUpdatedAt()).thenReturn(now);
    when(page.getLastContributor()).thenReturn("Author");
    when(page.getType()).thenReturn(PageType.MARKDOWN.name());
    PageRevision newRevision = mock(PageRevision.class);
    when(pageRevisionRepository.findLastByPageId(PAGE_ID)).thenReturn(Optional.empty());
    when(pageRevisionRepository.create(any())).thenReturn(newRevision);
    ArgumentCaptor<PageRevision> newRevisionCaptor = ArgumentCaptor.forClass(PageRevision.class);
    PageRevisionEntity createdRevision = pageRevisionService.create(page);
    assertNotNull(createdRevision);
    verify(pageRevisionRepository).findLastByPageId(PAGE_ID);
    verify(pageRevisionRepository).create(newRevisionCaptor.capture());
    PageRevision createdRev = newRevisionCaptor.getValue();
    assertNotNull(createdRev);
    assertEquals(1, createdRev.getRevision());
}
Also used : Page(io.gravitee.repository.management.model.Page) PageRevision(io.gravitee.repository.management.model.PageRevision) Date(java.util.Date) PageRevisionEntity(io.gravitee.rest.api.model.PageRevisionEntity) Test(org.junit.Test)

Example 4 with PageRevisionEntity

use of io.gravitee.rest.api.model.PageRevisionEntity in project gravitee-management-rest-api by gravitee-io.

the class PageRevisionServiceTest method shouldCreateRevision_NewIncrementedRevision.

@Test
public void shouldCreateRevision_NewIncrementedRevision() throws TechnicalException {
    Date now = new Date();
    Page page = mock(Page.class);
    when(page.getId()).thenReturn(PAGE_ID);
    when(page.getName()).thenReturn("SomeName");
    when(page.getContent()).thenReturn("SomeContent");
    when(page.getUpdatedAt()).thenReturn(now);
    when(page.getLastContributor()).thenReturn("Author");
    when(page.getType()).thenReturn(PageType.MARKDOWN.name());
    PageRevision lastRevision = mock(PageRevision.class);
    when(lastRevision.getRevision()).thenReturn(2);
    PageRevision newRevision = mock(PageRevision.class);
    when(pageRevisionRepository.findLastByPageId(PAGE_ID)).thenReturn(Optional.of(lastRevision));
    when(pageRevisionRepository.create(any())).thenReturn(newRevision);
    ArgumentCaptor<PageRevision> newRevisionCaptor = ArgumentCaptor.forClass(PageRevision.class);
    PageRevisionEntity createdRevision = pageRevisionService.create(page);
    assertNotNull(createdRevision);
    verify(pageRevisionRepository).findLastByPageId(PAGE_ID);
    verify(pageRevisionRepository).create(newRevisionCaptor.capture());
    PageRevision createdRev = newRevisionCaptor.getValue();
    assertNotNull(createdRev);
    assertEquals(lastRevision.getRevision() + 1, createdRev.getRevision());
}
Also used : Page(io.gravitee.repository.management.model.Page) PageRevision(io.gravitee.repository.management.model.PageRevision) Date(java.util.Date) PageRevisionEntity(io.gravitee.rest.api.model.PageRevisionEntity) Test(org.junit.Test)

Example 5 with PageRevisionEntity

use of io.gravitee.rest.api.model.PageRevisionEntity in project gravitee-management-rest-api by gravitee-io.

the class PageService_FindByIdTest method shouldFindById.

@Test
public void shouldFindById() throws TechnicalException {
    when(translationPage.getId()).thenReturn(TRANSLATION_ID);
    when(translationPage.getOrder()).thenReturn(1);
    when(translationPage.getParentId()).thenReturn(PAGE_ID);
    when(translationPage.getReferenceType()).thenReturn(PageReferenceType.ENVIRONMENT);
    when(translationPage.getReferenceId()).thenReturn("envId");
    when(translationPage.getVisibility()).thenReturn("PUBLIC");
    Map<String, String> conf = new HashMap<>();
    conf.put(PageConfigurationKeys.TRANSLATION_LANG, "FR");
    when(translationPage.getConfiguration()).thenReturn(conf);
    when(page1.getId()).thenReturn(PAGE_ID);
    when(page1.getType()).thenReturn(PageType.MARKDOWN.name());
    when(page1.getOrder()).thenReturn(1);
    when(page1.getReferenceType()).thenReturn(PageReferenceType.ENVIRONMENT);
    when(page1.getReferenceId()).thenReturn("envId");
    when(page1.getVisibility()).thenReturn("PUBLIC");
    when(pageRepository.findById(PAGE_ID)).thenReturn(Optional.of(page1));
    when(pageRepository.search(argThat(p -> "TRANSLATION".equals(p.getType()) && PAGE_ID.equals(p.getParent())))).thenReturn(Arrays.asList(translationPage));
    final PageRevisionEntity pageRevision = new PageRevisionEntity();
    pageRevision.setRevision(5);
    pageRevision.setPageId(PAGE_ID);
    when(pageRevisionService.findLastByPageId(PAGE_ID)).thenReturn(Optional.of(pageRevision));
    final PageEntity pageEntity = pageService.findById(PAGE_ID);
    assertNotNull(pageEntity);
    assertEquals(1, pageEntity.getOrder());
    assertEquals(PAGE_ID, pageEntity.getId());
    List<PageEntity> translations = pageEntity.getTranslations();
    assertNotNull(translations);
    assertEquals(1, translations.size());
    PageEntity oneTranslation = translations.get(0);
    assertNotNull(oneTranslation);
    assertEquals(TRANSLATION_ID, oneTranslation.getId());
    assertNotNull(pageEntity.getContentRevisionId());
    assertEquals(PAGE_ID, pageEntity.getContentRevisionId().getPageId());
    assertEquals(5, pageEntity.getContentRevisionId().getRevision());
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) InjectMocks(org.mockito.InjectMocks) PageServiceImpl(io.gravitee.rest.api.service.impl.PageServiceImpl) java.util(java.util) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) PageType(io.gravitee.rest.api.model.PageType) Assert.assertNotNull(org.junit.Assert.assertNotNull) Mock(org.mockito.Mock) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PageRevisionEntity(io.gravitee.rest.api.model.PageRevisionEntity) PageReferenceType(io.gravitee.repository.management.model.PageReferenceType) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) Page(io.gravitee.repository.management.model.Page) PageNotFoundException(io.gravitee.rest.api.service.exceptions.PageNotFoundException) PageRepository(io.gravitee.repository.management.api.PageRepository) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) PageConfigurationKeys(io.gravitee.rest.api.model.PageConfigurationKeys) PageEntity(io.gravitee.rest.api.model.PageEntity) PageRevisionEntity(io.gravitee.rest.api.model.PageRevisionEntity) Test(org.junit.Test)

Aggregations

PageRevisionEntity (io.gravitee.rest.api.model.PageRevisionEntity)6 Page (io.gravitee.repository.management.model.Page)5 PageRevision (io.gravitee.repository.management.model.PageRevision)4 Test (org.junit.Test)4 Date (java.util.Date)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 PageRepository (io.gravitee.repository.management.api.PageRepository)1 PageReferenceType (io.gravitee.repository.management.model.PageReferenceType)1 PageConfigurationKeys (io.gravitee.rest.api.model.PageConfigurationKeys)1 PageEntity (io.gravitee.rest.api.model.PageEntity)1 PageType (io.gravitee.rest.api.model.PageType)1 PageNotFoundException (io.gravitee.rest.api.service.exceptions.PageNotFoundException)1 PageServiceImpl (io.gravitee.rest.api.service.impl.PageServiceImpl)1 java.util (java.util)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 InjectMocks (org.mockito.InjectMocks)1