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