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