use of com.enonic.xp.schema.content.GetContentTypeParams in project xp by enonic.
the class CreateContentCommandTest method createContent_unknown_parent_content_type.
@Test
public void createContent_unknown_parent_content_type() {
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenAnswer(a -> BuiltinContentTypesAccessor.getContentType(((GetContentTypeParams) a.getArgument(0)).getContentTypeName()));
final NodePath sitePath = initContent(ContentTypeName.site(), "site", ContentConstants.CONTENT_ROOT_PATH);
final NodePath parentPath = initContent(ContentTypeName.from("unknown:unknown"), "parent", sitePath);
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.dataMedia()).name("media").parent(ContentPath.from("/site/parent")).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
final Content content = command.execute();
assertNotNull(content);
}
use of com.enonic.xp.schema.content.GetContentTypeParams in project xp by enonic.
the class CreateContentCommandTest method createContentInValidPageTemplate.
@Test
public void createContentInValidPageTemplate() {
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenAnswer(a -> BuiltinContentTypesAccessor.getContentType(((GetContentTypeParams) a.getArgument(0)).getContentTypeName()));
final NodePath sitePath = initContent(ContentTypeName.site(), "site", ContentConstants.CONTENT_ROOT_PATH);
final NodePath templatePath = initContent(ContentTypeName.pageTemplate(), "template", sitePath);
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.dataMedia()).name("media").parent(ContentPath.from("/site/template")).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
final Content content = command.execute();
assertNotNull(content);
assertEquals(ContentPath.from("/site/template"), content.getParentPath());
}
use of com.enonic.xp.schema.content.GetContentTypeParams in project xp by enonic.
the class CreateContentCommandTest method createContentInTemplateFolder_fails.
@Test
public void createContentInTemplateFolder_fails() {
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenAnswer(a -> BuiltinContentTypesAccessor.getContentType(((GetContentTypeParams) a.getArgument(0)).getContentTypeName()));
initContent(ContentTypeName.templateFolder(), "template", ContentConstants.CONTENT_ROOT_PATH);
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.folder()).name("folder").parent(ContentPath.from("/template")).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
assertThrows(IllegalArgumentException.class, command::execute);
}
use of com.enonic.xp.schema.content.GetContentTypeParams in project xp by enonic.
the class CreateContentCommandTest method createTemplateFolderInRoot_fails.
@Test
public void createTemplateFolderInRoot_fails() {
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenAnswer(a -> BuiltinContentTypesAccessor.getContentType(((GetContentTypeParams) a.getArgument(0)).getContentTypeName()));
mockContentRootNode();
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.pageTemplate()).name("template").parent(ContentPath.ROOT).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
assertThrows(IllegalArgumentException.class, command::execute);
}
use of com.enonic.xp.schema.content.GetContentTypeParams 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));
}
Aggregations