Search in sources :

Example 1 with FindContentByParentResult

use of com.enonic.xp.content.FindContentByParentResult 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 2 with FindContentByParentResult

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

the class GetChildContentHandlerTest method getChildrenByPath.

@Test
public void getChildrenByPath() throws Exception {
    final Contents contents = TestDataFixtures.newContents(3);
    final FindContentByParentResult findResult = FindContentByParentResult.create().hits(contents.getSize()).totalHits(20).contents(contents).build();
    Mockito.when(this.contentService.findByParent(Mockito.isA(FindContentByParentParams.class))).thenReturn(findResult);
    runFunction("/test/GetChildContentHandlerTest.js", "getChildrenByPath");
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) Contents(com.enonic.xp.content.Contents) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Test(org.junit.jupiter.api.Test)

Example 3 with FindContentByParentResult

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

the class ProjectContentEventListenerTest method testManualOrderUpdated.

@Test
public void testManualOrderUpdated() 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(() -> {
        final FindContentByParentResult result = contentService.findByParent(FindContentByParentParams.create().parentId(sourceContent.getId()).build());
        final Iterator<Content> iterator = result.getContents().iterator();
        assertEquals(sourceChild3.getId(), iterator.next().getId());
        assertEquals(sourceChild2.getId(), iterator.next().getId());
        assertEquals(sourceChild1.getId(), iterator.next().getId());
    });
    sourceContext.runWith(() -> contentService.setChildOrder(SetContentChildOrderParams.create().contentId(sourceContent.getId()).childOrder(ChildOrder.manualOrder()).build()));
    handleEvents();
    sourceContext.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()));
    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());
    });
}
Also used : FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 4 with FindContentByParentResult

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

the class GetChildContentHandlerTest method getChildrenByPath_allParameters.

@Test
public void getChildrenByPath_allParameters() throws Exception {
    final Contents contents = TestDataFixtures.newContents(3);
    final FindContentByParentResult findResult = FindContentByParentResult.create().hits(contents.getSize()).totalHits(20).contents(contents).build();
    final FindContentByParentParams expectedFindParams = FindContentByParentParams.create().parentPath(ContentPath.from("/a/b/mycontent")).from(5).size(3).childOrder(ChildOrder.from("_modifiedTime ASC")).build();
    Mockito.when(this.contentService.findByParent(Mockito.eq(expectedFindParams))).thenReturn(findResult);
    runFunction("/test/GetChildContentHandlerTest.js", "getChildrenByPath_allParameters");
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) Contents(com.enonic.xp.content.Contents) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Test(org.junit.jupiter.api.Test)

Example 5 with FindContentByParentResult

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

the class GetChildContentHandlerTest method getChildrenByPath_notFound.

@Test
public void getChildrenByPath_notFound() throws Exception {
    final FindContentByParentResult findResult = FindContentByParentResult.create().hits(0).totalHits(0).contents(Contents.empty()).build();
    Mockito.when(this.contentService.findByParent(Mockito.isA(FindContentByParentParams.class))).thenReturn(findResult);
    runFunction("/test/GetChildContentHandlerTest.js", "getChildrenByPath_notFound");
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Test(org.junit.jupiter.api.Test)

Aggregations

FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)33 Test (org.junit.jupiter.api.Test)26 Content (com.enonic.xp.content.Content)18 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)18 ContentPath (com.enonic.xp.content.ContentPath)7 Contents (com.enonic.xp.content.Contents)4 ArrayDeque (java.util.ArrayDeque)2 ArchiveConstants (com.enonic.xp.archive.ArchiveConstants)1 ContentConstants (com.enonic.xp.content.ContentConstants)1 BRANCH_DRAFT (com.enonic.xp.content.ContentConstants.BRANCH_DRAFT)1 CONTENT_ROOT_PATH_ATTRIBUTE (com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE)1 ContentId (com.enonic.xp.content.ContentId)1 ContentService (com.enonic.xp.content.ContentService)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 MediaInfoService (com.enonic.xp.media.MediaInfoService)1 NodePath (com.enonic.xp.node.NodePath)1 PageTemplate (com.enonic.xp.page.PageTemplate)1 PageTemplates (com.enonic.xp.page.PageTemplates)1