Search in sources :

Example 36 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class ContentNodeTranslatorTest method testFromNodeResolvingChildren.

@Test
public void testFromNodeResolvingChildren() throws Exception {
    final Node node = createNode();
    Mockito.when(this.nodeService.hasChildren(Mockito.any(Node.class))).thenReturn(true);
    final Content content = this.contentNodeTranslator.fromNode(node, true);
    assertNotNull(content);
    assertTrue(content.hasChildren());
}
Also used : Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 37 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class CreateContentCommandTest method createTemplateFolderInsideSite.

@Test
public void createTemplateFolderInsideSite() {
    final PropertyTree parentNodeData = new PropertyTree();
    parentNodeData.setString(ContentPropertyNames.TYPE, ContentTypeName.site().toString());
    parentNodeData.setSet(ContentPropertyNames.DATA, new PropertySet());
    parentNodeData.setString(ContentPropertyNames.CREATOR, "user:myidprovider:user1");
    final Node parentNode = Node.create().id(NodeId.from("id1")).name("parent").parentPath(ContentConstants.CONTENT_ROOT_PATH).data(parentNodeData).build();
    Mockito.when(nodeService.getByPath(Mockito.eq(NodePath.create("/content/parent").build()))).thenReturn(parentNode);
    final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.templateFolder()).name("_templates").parent(ContentPath.from("/parent")).contentData(new PropertyTree()).displayName("displayName").build();
    CreateContentCommand command = createContentCommand(params);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.documentMedia()).name(ContentTypeName.dataMedia()).build());
    // exercise
    final Content createdContent = command.execute();
    assertNotNull(createdContent);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 38 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class CreateContentCommandTest method mockContentRootNode.

private void mockContentRootNode(final String language) {
    final PropertyTree tree = new PropertyTree();
    tree.addString(ContentPropertyNames.TYPE, "folder");
    tree.addString(ContentPropertyNames.CREATOR, "user:system:user1");
    tree.addString(ContentPropertyNames.LANGUAGE, language);
    tree.addSet(ContentPropertyNames.DATA, new PropertySet());
    final Node contentRootNode = Node.create().id(NodeId.from("id1")).name("content").path("/content").parentPath(NodePath.ROOT).data(tree).build();
    Mockito.when(nodeService.getByPath(ContentConstants.CONTENT_ROOT_PATH)).thenReturn(contentRootNode);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet)

Example 39 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class CreateContentCommandTest method initContent.

private NodePath initContent(final ContentTypeName contentTypeName, final String name, final NodePath parentPath) {
    final PropertyTree nodeData = new PropertyTree();
    nodeData.setString(ContentPropertyNames.TYPE, contentTypeName.toString());
    nodeData.setSet(ContentPropertyNames.DATA, new PropertySet());
    nodeData.setString(ContentPropertyNames.CREATOR, "user:myidprovider:user1");
    final Node node = Node.create().id(NodeId.from(name)).name(name).parentPath(parentPath).data(nodeData).build();
    Mockito.when(nodeService.getByPath(Mockito.eq(node.path()))).thenReturn(node);
    Mockito.when(nodeService.getById(Mockito.eq(node.id()))).thenReturn(node);
    return node.path();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet)

Example 40 with Node

use of com.enonic.xp.node.Node in project xp by enonic.

the class GetContentByIdAndVersionIdCommandTest method testExecute.

@Test
public void testExecute() {
    final PropertyTree contentData = new PropertyTree();
    contentData.addString("property", "value");
    final Content content = Content.create().name("name").parentPath(ContentPath.ROOT).data(contentData).build();
    when(nodeService.getByIdAndVersionId(any(NodeId.class), any(NodeVersionId.class))).thenReturn(node);
    when(translator.fromNode(any(Node.class), anyBoolean(), anyBoolean())).thenReturn(content);
    final Content result = createInstance().execute();
    assertNotNull(result);
    assertEquals(content, result);
    verify(nodeService, times(1)).getByIdAndVersionId(any(NodeId.class), any(NodeVersionId.class));
    verify(translator, times(1)).fromNode(any(Node.class), anyBoolean(), anyBoolean());
    verifyNoMoreInteractions(nodeService, translator);
}
Also used : NodeVersionId(com.enonic.xp.node.NodeVersionId) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test)

Aggregations

Node (com.enonic.xp.node.Node)521 Test (org.junit.jupiter.api.Test)371 PropertyTree (com.enonic.xp.data.PropertyTree)114 NodeId (com.enonic.xp.node.NodeId)52 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)51 NodePath (com.enonic.xp.node.NodePath)45 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)42 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)34 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)32 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)29 NodeQuery (com.enonic.xp.node.NodeQuery)27 AccessControlList (com.enonic.xp.security.acl.AccessControlList)27 BinaryReference (com.enonic.xp.util.BinaryReference)26 ByteSource (com.google.common.io.ByteSource)24 Content (com.enonic.xp.content.Content)23 PropertySet (com.enonic.xp.data.PropertySet)20 NodeIds (com.enonic.xp.node.NodeIds)18 Context (com.enonic.xp.context.Context)17 InternalContext (com.enonic.xp.repo.impl.InternalContext)17 Application (com.enonic.xp.app.Application)16