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);
}
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());
}
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);
}
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);
}
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());
}
Aggregations