Search in sources :

Example 51 with CreateContentParams

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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 52 with CreateContentParams

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());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 53 with CreateContentParams

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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 54 with CreateContentParams

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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 55 with CreateContentParams

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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Aggregations

CreateContentParams (com.enonic.xp.content.CreateContentParams)81 Test (org.junit.jupiter.api.Test)66 PropertyTree (com.enonic.xp.data.PropertyTree)63 Content (com.enonic.xp.content.Content)52 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)25 PropertySet (com.enonic.xp.data.PropertySet)14 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)11 ContentType (com.enonic.xp.schema.content.ContentType)10 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)9 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)9 PublishContentResult (com.enonic.xp.content.PublishContentResult)7 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)7 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)6 ExtraData (com.enonic.xp.content.ExtraData)6 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)6 Attachments (com.enonic.xp.attachment.Attachments)5 Node (com.enonic.xp.node.Node)5 ByteSource (com.google.common.io.ByteSource)5 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)4 ExtraDatas (com.enonic.xp.content.ExtraDatas)4