Search in sources :

Example 6 with PageRevisionEntity

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

the class PageRevisionServiceTest method shouldCreateRevision.

@Test
public void shouldCreateRevision() 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)

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