Search in sources :

Example 1 with Content

use of com.enonic.xp.content.Content in project xp by enonic.

the class ProjectContentEventListenerTest method testCreatedInMaster.

@Test
public void testCreatedInMaster() throws InterruptedException {
    final Content sourceContent = ContextBuilder.from(sourceContext).branch(ContentConstants.BRANCH_MASTER).build().callWith(() -> createContent(ContentPath.ROOT, "name"));
    handleEvents();
    assertThrows(ContentNotFoundException.class, () -> targetContext.callWith(() -> contentService.getById(sourceContent.getId())));
}
Also used : Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 2 with Content

use of com.enonic.xp.content.Content in project xp by enonic.

the class ProjectContentEventListenerTest method testSyncDuplicateWithExistedLocalName.

@Test
public void testSyncDuplicateWithExistedLocalName() throws InterruptedException {
    targetContext.callWith(() -> createContent(ContentPath.ROOT, "localName-copy"));
    targetContext.callWith(() -> createContent(ContentPath.ROOT, "localName-copy-1"));
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "localName"));
    handleEvents();
    final ContentId duplicatedContentId = sourceContext.callWith(() -> contentService.duplicate(DuplicateContentParams.create().contentId(sourceContent.getId()).build()).getDuplicatedContents().first());
    handleEvents();
    targetContext.runWith(() -> {
        final Content duplicatedTargetContent = contentService.getById(duplicatedContentId);
        assertEquals("localName-copy-1-1", duplicatedTargetContent.getName().toString());
        assertEquals(3, duplicatedTargetContent.getInherit().size());
        assertFalse(duplicatedTargetContent.getInherit().contains(ContentInheritType.NAME));
    });
}
Also used : Content(com.enonic.xp.content.Content) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 3 with Content

use of com.enonic.xp.content.Content in project xp by enonic.

the class ProjectContentEventListenerTest method testManualOrderLocally.

@Test
public void testManualOrderLocally() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content"));
    final Content sourceChild1 = sourceContext.callWith(() -> createContent(sourceContent.getPath(), "child1"));
    final Content sourceChild2 = sourceContext.callWith(() -> createContent(sourceContent.getPath(), "child2"));
    final Content sourceChild3 = sourceContext.callWith(() -> createContent(sourceContent.getPath(), "child3"));
    handleEvents();
    sourceContext.runWith(() -> contentService.setChildOrder(SetContentChildOrderParams.create().contentId(sourceContent.getId()).childOrder(ChildOrder.from("_name DESC")).build()));
    handleEvents();
    targetContext.runWith(() -> contentService.setChildOrder(SetContentChildOrderParams.create().contentId(sourceContent.getId()).childOrder(ChildOrder.manualOrder()).build()));
    targetContext.runWith(() -> contentService.reorderChildren(ReorderChildContentsParams.create().contentId(sourceContent.getId()).add(ReorderChildParams.create().contentToMove(sourceChild2.getId()).contentToMoveBefore(sourceChild3.getId()).build()).add(ReorderChildParams.create().contentToMove(sourceChild1.getId()).contentToMoveBefore(sourceChild3.getId()).build()).build()));
    sourceContext.runWith(() -> contentService.setChildOrder(SetContentChildOrderParams.create().contentId(sourceContent.getId()).childOrder(ChildOrder.from("_name DESC")).build()));
    handleEvents();
    targetContext.runWith(() -> {
        final FindContentByParentResult result = contentService.findByParent(FindContentByParentParams.create().parentId(sourceContent.getId()).build());
        final Iterator<Content> iterator = result.getContents().iterator();
        assertEquals(sourceChild2.getId(), iterator.next().getId());
        assertEquals(sourceChild1.getId(), iterator.next().getId());
        assertEquals(sourceChild3.getId(), iterator.next().getId());
        assertTrue(contentService.getById(sourceContent.getId()).getChildOrder().isManualOrder());
    });
}
Also used : FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 4 with Content

use of com.enonic.xp.content.Content in project xp by enonic.

the class ProjectContentEventListenerTest method testMovedToExistedPath.

@Test
public void testMovedToExistedPath() throws InterruptedException {
    final Content sourceContent1 = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content"));
    final Content sourceContent2 = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content2"));
    handleEvents();
    targetContext.callWith(() -> createContent(sourceContent2.getPath(), "content"));
    sourceContext.runWith(() -> contentService.move(MoveContentParams.create().contentId(sourceContent1.getId()).parentContentPath(sourceContent2.getPath()).build()));
    handleEvents();
    final Content targetMovedContent = targetContext.callWith(() -> contentService.getById(sourceContent1.getId()));
    assertEquals("/content2/content-1", targetMovedContent.getPath().toString());
}
Also used : Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 5 with Content

use of com.enonic.xp.content.Content in project xp by enonic.

the class ProjectContentEventListenerTest method testSortedLocally.

@Test
public void testSortedLocally() throws InterruptedException {
    final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content"));
    handleEvents();
    final Content sortedInChild = targetContext.callWith(() -> contentService.setChildOrder(SetContentChildOrderParams.create().contentId(sourceContent.getId()).childOrder(ChildOrder.from("_name DESC")).build()));
    assertEquals(3, sortedInChild.getInherit().size());
    assertFalse(sortedInChild.getInherit().contains(ContentInheritType.SORT));
    final Content sortedInParent = sourceContext.callWith(() -> contentService.setChildOrder(SetContentChildOrderParams.create().contentId(sourceContent.getId()).childOrder(ChildOrder.from("_name ASC")).build()));
    handleEvents();
    assertNotEquals(sortedInParent.getChildOrder(), targetContext.callWith(() -> contentService.getById(sortedInChild.getId())));
}
Also used : Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Aggregations

Content (com.enonic.xp.content.Content)560 Test (org.junit.jupiter.api.Test)432 PropertyTree (com.enonic.xp.data.PropertyTree)130 CreateContentParams (com.enonic.xp.content.CreateContentParams)57 ContentId (com.enonic.xp.content.ContentId)50 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)48 ContentPath (com.enonic.xp.content.ContentPath)47 ValidationErrors (com.enonic.xp.content.ValidationErrors)47 Site (com.enonic.xp.site.Site)43 PropertySet (com.enonic.xp.data.PropertySet)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)27 Page (com.enonic.xp.page.Page)26 Contents (com.enonic.xp.content.Contents)25 Node (com.enonic.xp.node.Node)25 ContentIds (com.enonic.xp.content.ContentIds)24 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)24 ContentQuery (com.enonic.xp.content.ContentQuery)23 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)23 DataValidationError (com.enonic.xp.content.DataValidationError)21 ContentType (com.enonic.xp.schema.content.ContentType)20