Search in sources :

Example 41 with Node

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());
}
Also used : Content(com.enonic.xp.content.Content) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) ContentPath(com.enonic.xp.content.ContentPath) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 42 with Node

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);
}
Also used : MoveContentParams(com.enonic.xp.content.MoveContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 43 with Node

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);
}
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) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 44 with Node

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());
}
Also used : Node(com.enonic.xp.node.Node) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) IssueComment(com.enonic.xp.issue.IssueComment) PrincipalKey(com.enonic.xp.security.PrincipalKey) CreateIssueCommentParams(com.enonic.xp.issue.CreateIssueCommentParams) Test(org.junit.jupiter.api.Test)

Example 45 with Node

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());
}
Also used : Node(com.enonic.xp.node.Node) PropertyTree(com.enonic.xp.data.PropertyTree) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) IssueCommentDataSerializer(com.enonic.xp.core.impl.issue.serializer.IssueCommentDataSerializer) NodeId(com.enonic.xp.node.NodeId) IssueComment(com.enonic.xp.issue.IssueComment) PrincipalKey(com.enonic.xp.security.PrincipalKey) UpdateIssueCommentParams(com.enonic.xp.issue.UpdateIssueCommentParams) 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