Search in sources :

Example 11 with FindContentByParentParams

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

the class ContentServiceImplTest_findByParent method invalid_parent_path.

@Test
public void invalid_parent_path() throws Exception {
    final Content rootContent = createContent(ContentPath.ROOT);
    final Content childrenLevel1 = createContent(rootContent.getPath());
    this.nodeService.refresh(RefreshMode.SEARCH);
    final FindContentByParentParams params = FindContentByParentParams.create().from(0).size(30).parentPath(ContentPath.from("/test_invalid_path")).build();
    final FindContentByParentResult result = contentService.findByParent(params);
    assertNotNull(result);
    assertEquals(0, result.getTotalHits());
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) FindContentByParentResult(com.enonic.xp.content.FindContentByParentResult) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 12 with FindContentByParentParams

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

the class ContentServiceImplTest_findIdsByParent method params_size_one.

@Test
public void params_size_one() throws Exception {
    final Content parentContent = createContent(ContentPath.ROOT);
    createContent(parentContent.getPath());
    createContent(parentContent.getPath());
    createContent(parentContent.getPath());
    final ContentPath parentContentPath = parentContent.getPath();
    this.nodeService.refresh(RefreshMode.SEARCH);
    final FindContentByParentParams params = FindContentByParentParams.create().from(0).size(1).parentPath(parentContentPath).build();
    final FindContentIdsByParentResult result = contentService.findIdsByParent(params);
    assertNotNull(result);
    assertEquals(1, result.getHits());
    assertEquals(3, result.getTotalHits());
    assertEquals(1, result.getContentIds().getSize());
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) Content(com.enonic.xp.content.Content) FindContentIdsByParentResult(com.enonic.xp.content.FindContentIdsByParentResult) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

Example 13 with FindContentByParentParams

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

the class ContentServiceImplTest_findIdsByParent method createAndFindContent.

private FindContentIdsByParentResult createAndFindContent(final ContentPublishInfo publishInfo) throws Exception {
    createContent(ContentPath.ROOT, publishInfo);
    this.nodeService.refresh(RefreshMode.SEARCH);
    final FindContentByParentParams params = FindContentByParentParams.create().parentPath(ContentPath.ROOT).build();
    return contentService.findIdsByParent(params);
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams)

Example 14 with FindContentByParentParams

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

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

the class ContentResourceTest method reprocess_child_with_error.

@Test
public void reprocess_child_with_error() throws Exception {
    Content content = createContent("content-id", ContentPath.from("/path/to/content"));
    Content reprocessedContent = Content.create(content).displayName("new name").build();
    Content child = createContent("child-id", ContentPath.from(content.getPath(), "child"));
    Mockito.when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    Mockito.when(this.contentService.reprocess(content.getId())).thenReturn(reprocessedContent);
    Mockito.when(this.contentService.reprocess(child.getId())).thenThrow(new RuntimeException("errorMessage"));
    final FindContentByParentParams findParams = FindContentByParentParams.create().parentId(content.getId()).from(0).size(5).build();
    Mockito.when(this.contentService.findByParent(findParams)).thenReturn(FindContentByParentResult.create().contents(Contents.create().add(child).build()).build());
    final String result = request().path("content/reprocess").entity(readFromFile("reprocess_params.json"), MediaType.APPLICATION_JSON_TYPE).post().getAsString();
    assertEquals("{\"errors\":[\"Content '/path/to/content/child' - java.lang.RuntimeException: errorMessage\"],\"updatedContent\":[\"/path/to/content\"]}", result);
}
Also used : FindContentByParentParams(com.enonic.xp.content.FindContentByParentParams) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Aggregations

FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)23 Content (com.enonic.xp.content.Content)18 Test (org.junit.jupiter.api.Test)18 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)12 ContentPath (com.enonic.xp.content.ContentPath)10 FindContentIdsByParentResult (com.enonic.xp.content.FindContentIdsByParentResult)8 Contents (com.enonic.xp.content.Contents)1 PageTemplate (com.enonic.xp.page.PageTemplate)1 PageTemplates (com.enonic.xp.page.PageTemplates)1 ValueFilter (com.enonic.xp.query.filter.ValueFilter)1