Search in sources :

Example 1 with MoveContentParams

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

the class MoveContentCommandTest method move_non_existing_content.

@Test
public void move_non_existing_content() throws Exception {
    PropertyTree existingContentData = new PropertyTree();
    existingContentData.addString("myData", "aaa");
    ContentId contentId = ContentId.from("mycontent");
    MoveContentParams params = MoveContentParams.create().contentId(contentId).parentContentPath(ContentPath.ROOT).build();
    MoveContentCommand command = MoveContentCommand.create(params).contentTypeService(this.contentTypeService).nodeService(this.nodeService).translator(this.translator).eventPublisher(this.eventPublisher).build();
    Mockito.when(nodeService.getById(Mockito.isA(NodeId.class))).thenThrow(new NodeNotFoundException("Node not found"));
    // exercise
    assertThrows(ContentNotFoundException.class, () -> command.execute());
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) MoveContentParams(com.enonic.xp.content.MoveContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 2 with MoveContentParams

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

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

the class ContentServiceImplTest_delete method move_to_folder_starting_with_same_name_and_delete.

@Test
public void move_to_folder_starting_with_same_name_and_delete() throws Exception {
    final Content site = createContent(ContentPath.ROOT, "site");
    final Content child1 = createContent(site.getPath(), "child1");
    createContent(child1.getPath(), "child1_1");
    createContent(child1.getPath(), "child2_1");
    final Content site2 = createContent(ContentPath.ROOT, "site2");
    refresh();
    final MoveContentParams params = MoveContentParams.create().contentId(child1.getId()).parentContentPath(site2.getPath()).build();
    this.contentService.move(params);
    final DeleteContentsResult result = this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(site.getPath()).build());
    assertEquals(1, result.getDeletedContents().getSize());
}
Also used : MoveContentParams(com.enonic.xp.content.MoveContentParams) Content(com.enonic.xp.content.Content) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) Test(org.junit.jupiter.api.Test)

Example 4 with MoveContentParams

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

the class ContentServiceImplTest_publish method publish_move_delete_old_parent.

/**
 * /content1
 * /content1_1
 * /content2
 * /content2_1 -> ref:content1_1
 */
@Test
public void publish_move_delete_old_parent() throws Exception {
    createContentTree();
    this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content1.getId())).target(WS_OTHER).excludeChildrenIds(ContentIds.from(content1.getId())).build());
    final MoveContentParams params = MoveContentParams.create().contentId(content2_1.getId()).parentContentPath(content1.getPath()).build();
    this.contentService.move(params);
    this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content2.getPath()).build());
    final Content movedContent = this.contentService.getByPath(ContentPath.from(content1.getPath(), content2_1.getName().toString()));
    assertNotNull(movedContent);
}
Also used : MoveContentParams(com.enonic.xp.content.MoveContentParams) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 5 with MoveContentParams

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

the class ContentServiceImplTest_publish method doMove.

private void doMove(final ContentId contentId, final String newParent) {
    final MoveContentParams params = MoveContentParams.create().contentId(contentId).parentContentPath(ContentPath.from(newParent)).build();
    this.contentService.move(params);
}
Also used : MoveContentParams(com.enonic.xp.content.MoveContentParams)

Aggregations

MoveContentParams (com.enonic.xp.content.MoveContentParams)13 Test (org.junit.jupiter.api.Test)9 Content (com.enonic.xp.content.Content)8 MoveContentsResult (com.enonic.xp.content.MoveContentsResult)5 PropertyTree (com.enonic.xp.data.PropertyTree)5 Node (com.enonic.xp.node.Node)2 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)1 ContentId (com.enonic.xp.content.ContentId)1 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)1 PropertySet (com.enonic.xp.data.PropertySet)1 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)1 NodeId (com.enonic.xp.node.NodeId)1 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)1 ContentType (com.enonic.xp.schema.content.ContentType)1 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)1 Site (com.enonic.xp.site.Site)1