use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class CreateContentCommandTest method createPageTemplateUnderTemplateFolder.
@Test
public void createPageTemplateUnderTemplateFolder() {
final PropertyTree parentNodeData = new PropertyTree();
parentNodeData.setString(ContentPropertyNames.TYPE, ContentTypeName.templateFolder().toString());
parentNodeData.setSet(ContentPropertyNames.DATA, new PropertySet());
parentNodeData.setString(ContentPropertyNames.CREATOR, "user:myidprovider:user1");
final Node parentNode = Node.create().id(NodeId.from("id1")).name("_templates").parentPath(ContentConstants.CONTENT_ROOT_PATH).data(parentNodeData).build();
Mockito.when(nodeService.getByPath(Mockito.eq(NodePath.create("/content/_templates").build()))).thenReturn(parentNode);
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.pageTemplate()).name("mytemplate").parent(ContentPath.from("/_templates")).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.documentMedia()).name(ContentTypeName.dataMedia()).build());
// exercise
final Content createdContent = command.execute();
assertNotNull(createdContent);
}
use of com.enonic.xp.content.CreateContentParams 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.content.CreateContentParams 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.content.CreateContentParams in project xp by enonic.
the class CreateContentCommandTest method createTemplateFolderOutsideSite.
@Test
public void createTemplateFolderOutsideSite() {
final PropertyTree parentNodeData = new PropertyTree();
parentNodeData.setString(ContentPropertyNames.TYPE, ContentTypeName.unstructured().toString());
parentNodeData.setSet(ContentPropertyNames.DATA, new PropertySet());
parentNodeData.setString(ContentPropertyNames.CREATOR, "user:myidprovider:user1");
final Node parentNode = Node.create().id(NodeId.from("id1")).name("parent").parentPath(ContentConstants.CONTENT_ROOT_PATH).data(parentNodeData).build();
Mockito.when(nodeService.getByPath(Mockito.eq(NodePath.create("/content/parent").build()))).thenReturn(parentNode);
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.templateFolder()).name("_templates").parent(ContentPath.from("/parent")).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.documentMedia()).name(ContentTypeName.dataMedia()).build());
assertThrows(IllegalArgumentException.class, command::execute);
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class CreateContentCommandTest method createContentForDisallowedContentType_fails.
@Test
public void createContentForDisallowedContentType_fails() {
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.folder()).allowChildContent(false).build());
initContent(ContentTypeName.folder(), "folder", ContentConstants.CONTENT_ROOT_PATH);
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.folder()).name("folder").parent(ContentPath.from("/folder")).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
assertThrows(IllegalArgumentException.class, command::execute);
}
Aggregations