Search in sources :

Example 6 with MoveContentParams

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

the class MoveContentCommandTest method move_fragment_to_the_same_site.

@Test
public void move_fragment_to_the_same_site() throws Exception {
    final PropertyTree existingContentData = new PropertyTree();
    existingContentData.addString("myData", "aaa");
    final Site parentSite = createSite(existingContentData, ContentPath.ROOT);
    final Content existingContent = createContent(existingContentData, parentSite.getPath(), ContentTypeName.fragment());
    final Content existingFolder = createContent(existingContentData, parentSite.getPath(), ContentTypeName.folder());
    MoveContentParams params = MoveContentParams.create().contentId(existingContent.getId()).parentContentPath(existingFolder.getPath()).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().parentPath(NodePath.ROOT).build();
    Mockito.when(nodeService.getById(NodeId.from(existingContent.getId()))).thenReturn(mockNode);
    Mockito.when(nodeService.move(Mockito.any(MoveNodeParams.class))).thenReturn(mockNode);
    Mockito.when(translator.fromNode(mockNode, true)).thenReturn(existingContent);
    Mockito.when(translator.fromNode(mockNode, false)).thenReturn(existingContent);
    final Node mockFolderNode = Node.create().parentPath(NodePath.ROOT).build();
    Mockito.when(nodeService.getByPath(ContentNodeHelper.translateContentPathToNodePath(existingFolder.getPath()))).thenReturn(mockFolderNode);
    Mockito.when(translator.fromNode(mockFolderNode, true)).thenReturn(existingFolder);
    Mockito.when(translator.fromNode(mockFolderNode, false)).thenReturn(existingFolder);
    final ContentType contentType = ContentType.create().name("folder").displayName("folder").setBuiltIn().setFinal(false).setAbstract(false).build();
    Mockito.when(contentTypeService.getByName(new GetContentTypeParams().contentTypeName(existingFolder.getType()))).thenReturn(contentType);
    // exercise
    command.execute();
    Mockito.verify(nodeService, Mockito.times(1)).move(Mockito.any(MoveNodeParams.class));
}
Also used : Site(com.enonic.xp.site.Site) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) 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 7 with MoveContentParams

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

the class MoveContentHandler method move.

private Content move(final ContentId sourceId, final ContentPath newPath) {
    final MoveContentParams moveParams = MoveContentParams.create().contentId(sourceId).parentContentPath(newPath).build();
    final MoveContentsResult result = contentService.move(moveParams);
    return contentService.getById(result.getMovedContents().first());
}
Also used : MoveContentParams(com.enonic.xp.content.MoveContentParams) MoveContentsResult(com.enonic.xp.content.MoveContentsResult)

Example 8 with MoveContentParams

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

the class ContentServiceImplTest_move method audit_data.

@Test
public void audit_data() throws Exception {
    final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    final Content site = createContent(ContentPath.ROOT, "site");
    final Content child1 = createContent(site.getPath(), "child1");
    final MoveContentParams params = MoveContentParams.create().contentId(child1.getId()).parentContentPath(ContentPath.ROOT).build();
    final MoveContentsResult result = this.contentService.move(params);
    Mockito.verify(auditLogService, Mockito.timeout(5000).atLeast(17)).log(captor.capture());
    final PropertySet logResultSet = captor.getAllValues().stream().filter(log -> log.getType().equals("system.content.move")).findFirst().get().getData().getSet("result");
    assertEquals(child1.getId().toString(), logResultSet.getStrings("movedContents").iterator().next());
}
Also used : MoveContentParams(com.enonic.xp.content.MoveContentParams) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) Content(com.enonic.xp.content.Content) MoveContentsResult(com.enonic.xp.content.MoveContentsResult) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 9 with MoveContentParams

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

the class ContentServiceImplTest_move method move_from_site_to_root.

@Test
public void move_from_site_to_root() throws Exception {
    final PropertyTree siteData = new PropertyTree();
    siteData.setSet("siteConfig", this.createSiteConfig());
    final Content site = createContent(ContentPath.ROOT, "site", siteData, ContentTypeName.site());
    final Content content = createContent(site.getPath(), "child", new PropertyTree(), this.createExtraDatas());
    refresh();
    final MoveContentParams params = MoveContentParams.create().contentId(content.getId()).parentContentPath(ContentPath.ROOT).build();
    final MoveContentsResult result = this.contentService.move(params);
    final Content movedContent = contentService.getById(result.getMovedContents().first());
    assertEquals(movedContent.getAllExtraData().getSize(), 1);
}
Also used : MoveContentParams(com.enonic.xp.content.MoveContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) MoveContentsResult(com.enonic.xp.content.MoveContentsResult) Test(org.junit.jupiter.api.Test)

Example 10 with MoveContentParams

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

the class ContentServiceImplTest_move method move_to_the_same_parent.

@Test
public void move_to_the_same_parent() throws Exception {
    final PropertyTree siteData = new PropertyTree();
    siteData.setSet("siteConfig", this.createSiteConfig());
    final Content site = createContent(ContentPath.ROOT, "site", siteData, ContentTypeName.site());
    final Content content = createContent(site.getPath(), "child", new PropertyTree(), this.createExtraDatas());
    refresh();
    final MoveContentParams params = MoveContentParams.create().contentId(content.getId()).parentContentPath(content.getParentPath()).build();
    assertThrows(ContentAlreadyMovedException.class, () -> this.contentService.move(params));
}
Also used : MoveContentParams(com.enonic.xp.content.MoveContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

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