Search in sources :

Example 56 with CreateContentParams

use of com.enonic.xp.content.CreateContentParams 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);
}
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)

Example 57 with CreateContentParams

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

the class CreateContentCommandTest method createContentWithProjectLanguage.

@Test
public void createContentWithProjectLanguage() {
    mockContentRootNode("no");
    mockContentNode("parent", "/content", "en", EnumSet.of(ContentInheritType.CONTENT));
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.folder()).name(ContentTypeName.folder()).build());
    final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.folder()).name("name").parent(ContentPath.from("/parent")).contentData(new PropertyTree()).displayName("displayName").build();
    final CreateContentCommand command = createContentCommand(params);
    Content content = command.execute();
    assertEquals("no", content.getLanguage().getLanguage());
    mockContentRootNode(null);
    content = command.execute();
    assertNull(content.getLanguage());
    mockContentNode("parent", "/content", "en", EnumSet.noneOf(ContentInheritType.class));
    content = command.execute();
    assertEquals("en", content.getLanguage().getLanguage());
}
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) ContentInheritType(com.enonic.xp.content.ContentInheritType) Test(org.junit.jupiter.api.Test)

Example 58 with CreateContentParams

use of com.enonic.xp.content.CreateContentParams 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);
}
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)

Example 59 with CreateContentParams

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

the class CreateContentCommandTest method createPageTemplateNotUnderTemplateFolder.

@Test
public void createPageTemplateNotUnderTemplateFolder() {
    final PropertyTree parentNodeData = new PropertyTree();
    parentNodeData.setString(ContentPropertyNames.TYPE, ContentTypeName.folder().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(), ContentType.create().name(ContentTypeName.folder()).setBuiltIn().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 60 with CreateContentParams

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

the class CreateContentCommandTest method createContentWithDefaultLanguage.

@Test
public void createContentWithDefaultLanguage() {
    final PropertyTree parentNodeData = new PropertyTree();
    parentNodeData.setSet(ContentPropertyNames.DATA, new PropertySet());
    parentNodeData.setString(ContentPropertyNames.CREATOR, "user:myidprovider:user1");
    parentNodeData.setString(ContentPropertyNames.LANGUAGE, "en");
    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").build()))).thenReturn(parentNode);
    final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.folder()).name("name").parent(ContentPath.from("/")).contentData(new PropertyTree()).displayName("displayName").build();
    CreateContentCommand command = createContentCommand(params);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.folder()).name(ContentTypeName.folder()).build());
    final Content content = command.execute();
    assertEquals(Locale.ENGLISH, content.getLanguage());
}
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)

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