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