Search in sources :

Example 6 with PageRevision

use of io.gravitee.repository.management.model.PageRevision 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

PageRevision (io.gravitee.repository.management.model.PageRevision)6 Page (io.gravitee.repository.management.model.Page)4 PageRevisionEntity (io.gravitee.rest.api.model.PageRevisionEntity)4 Date (java.util.Date)3 Test (org.junit.Test)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 PageType (io.gravitee.rest.api.model.PageType)1