Search in sources :

Example 16 with GetContentTypeParams

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);
}
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 17 with GetContentTypeParams

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());
}
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 18 with GetContentTypeParams

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);
}
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 19 with GetContentTypeParams

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);
}
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 20 with GetContentTypeParams

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

Aggregations

GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)26 ContentType (com.enonic.xp.schema.content.ContentType)18 Test (org.junit.jupiter.api.Test)17 CreateContentParams (com.enonic.xp.content.CreateContentParams)12 PropertyTree (com.enonic.xp.data.PropertyTree)8 Content (com.enonic.xp.content.Content)4 Form (com.enonic.xp.form.Form)4 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)3 ContentTypes (com.enonic.xp.schema.content.ContentTypes)3 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)2 FormItemSet (com.enonic.xp.form.FormItemSet)2 Node (com.enonic.xp.node.Node)2 NodePath (com.enonic.xp.node.NodePath)2 XData (com.enonic.xp.schema.xdata.XData)2 ContentAccessException (com.enonic.xp.content.ContentAccessException)1 ContentValidator (com.enonic.xp.content.ContentValidator)1 ContentValidatorParams (com.enonic.xp.content.ContentValidatorParams)1 CreateContentTranslatorParams (com.enonic.xp.content.CreateContentTranslatorParams)1 EditableContent (com.enonic.xp.content.EditableContent)1 MoveContentParams (com.enonic.xp.content.MoveContentParams)1