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