use of com.enonic.xp.node.Node in project xp by enonic.
the class GetNearestSiteCommandTest method get_nearest_site_no_nearest_site.
@Test
public void get_nearest_site_no_nearest_site() throws Exception {
final Node node = Node.create().id(NodeId.from("test")).name("myContent").parentPath(ContentConstants.CONTENT_ROOT_PATH).build();
final ContentId contentId = ContentId.from("aaa");
final Content content = Content.create().id(contentId).name("name").parentPath(ContentPath.from("/aaa")).build();
final ContentPath contentPath = ContentPath.from("/mycontent");
final Content parent = Content.create().path(contentPath).id(ContentId.from("bbb")).build();
Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenReturn(node);
Mockito.when(this.nodeService.getByPath(Mockito.isA(NodePath.class))).thenReturn(node);
Mockito.when(this.translator.fromNode(node, true)).thenReturn(content, parent);
assertNull(createCommand(contentId).execute());
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class MoveContentCommandTest method move_to_the_same_parent.
@Test
public void move_to_the_same_parent() throws Exception {
final PropertyTree existingContentData = new PropertyTree();
existingContentData.addString("myData", "aaa");
final Content existingContent = createContent(existingContentData, ContentPath.ROOT, ContentTypeName.folder());
final MoveContentParams params = MoveContentParams.create().contentId(existingContent.getId()).parentContentPath(ContentPath.ROOT).build();
final MoveContentCommand command = MoveContentCommand.create(params).contentTypeService(this.contentTypeService).nodeService(this.nodeService).translator(this.translator).eventPublisher(this.eventPublisher).build();
final Node mockNode = Node.create().name(existingContent.getName().toString()).parentPath(ContentNodeHelper.translateContentParentToNodeParentPath(existingContent.getParentPath())).build();
Mockito.when(nodeService.getById(NodeId.from(existingContent.getId()))).thenReturn(mockNode);
Mockito.when(nodeService.nodeExists(mockNode.path())).thenReturn(true);
Mockito.when(translator.fromNode(mockNode, true)).thenReturn(existingContent);
Mockito.when(translator.fromNode(mockNode, false)).thenReturn(existingContent);
// exercise
assertThrows(ContentAlreadyMovedException.class, command::execute);
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class GetContentByPathAndVersionIdCommandTest 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.getByPathAndVersionId(any(NodePath.class), any(NodeVersionId.class))).thenReturn(node);
when(translator.fromNode(any(Node.class), anyBoolean())).thenReturn(content);
final Content result = createInstance().execute();
assertNotNull(result);
assertEquals(content, result);
verify(nodeService, times(1)).getByPathAndVersionId(any(NodePath.class), any(NodeVersionId.class));
verify(translator, times(1)).fromNode(any(Node.class), anyBoolean());
verifyNoMoreInteractions(nodeService, translator);
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class CreateIssueCommentCommandTest method create.
@Test
public void create() {
final Node issueNode = Node.create().name("parent-issue").build();
final PrincipalKey creator = PrincipalKey.from("user:store:one");
final CreateIssueCommentParams params = CreateIssueCommentParams.create().issue(IssueId.create()).creator(creator).creatorDisplayName("Creator One").text("Comment text...").build();
final CreateIssueCommentCommand command = createIssueCommentCommand(params);
Mockito.when(this.nodeService.findByQuery(Mockito.any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().build());
Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenReturn(issueNode);
final IssueComment comment = command.execute();
assertNotNull(comment);
assertEquals("Comment text...", comment.getText());
assertEquals(creator, comment.getCreator());
assertEquals("Creator One", comment.getCreatorDisplayName());
}
use of com.enonic.xp.node.Node in project xp by enonic.
the class UpdateIssueCommentCommandTest method update.
@Test
public void update() {
final Node issueNode = Node.create().name("parent-issue").path(NodePath.ROOT.toString()).id(NodeId.from(UUID.randomUUID())).build();
final PrincipalKey creator = PrincipalKey.from("user:store:one");
final UpdateIssueCommentParams params = UpdateIssueCommentParams.create().comment(NodeId.from(UUID.randomUUID())).text("Comment text...").build();
PropertyTree data = new IssueCommentDataSerializer().toCreateNodeData(CreateIssueCommentParams.create().text(params.getText()).creator(creator).creatorDisplayName("Creator One").issue(IssueId.from(issueNode.id().toString())).build());
final Node commentNode = Node.create().parentPath(issueNode.path()).name("comment-node").data(data).build();
final UpdateIssueCommentCommand command = updateIssueCommentCommand(params);
Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenReturn(issueNode);
Mockito.when(this.nodeService.update(Mockito.any(UpdateNodeParams.class))).thenReturn(commentNode);
final IssueComment comment = command.execute();
assertNotNull(comment);
assertEquals("Comment text...", comment.getText());
assertEquals(creator, comment.getCreator());
assertEquals("Creator One", comment.getCreatorDisplayName());
}
Aggregations