use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class ContentServiceImplTest_create method create_content_unnamed.
@Test
public void create_content_unnamed() throws Exception {
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
final Content content = this.contentService.create(createContentParams);
final Content storedContent = this.contentService.getById(content.getId());
assertNotNull(storedContent.getName());
assertTrue(storedContent.getName().isUnnamed());
assertTrue(storedContent.getName().hasUniqueness());
assertNotNull(storedContent.getCreatedTime());
assertNotNull(storedContent.getCreator());
assertNotNull(storedContent.getModifiedTime());
assertNotNull(storedContent.getModifier());
assertNotNull(storedContent.getChildOrder());
assertEquals(ContentConstants.DEFAULT_CHILD_ORDER, storedContent.getChildOrder());
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class ContentServiceImplTest_create method audit_data.
@Test
public void audit_data() {
final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
final Content content = this.contentService.create(createContentParams);
Mockito.verify(auditLogService, Mockito.timeout(5000).atLeast(15)).log(captor.capture());
final PropertySet logResultSet = captor.getAllValues().stream().filter(log -> log.getType().equals("system.content.create")).findFirst().get().getData().getSet("result");
assertEquals(content.getId().toString(), logResultSet.getString("id"));
assertEquals(content.getPath().toString(), logResultSet.getString("path"));
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class ContentServiceImplTest_create method create_with_attachments.
@Test
public void create_with_attachments() throws Exception {
final String name = "cat-small.jpg";
final ByteSource image = loadImage(name);
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.imageMedia()).createAttachments(createAttachment("cat", "image/jpeg", image)).build();
final Content content = this.contentService.create(createContentParams);
final Content storedContent = this.contentService.getById(content.getId());
final Attachments attachments = storedContent.getAttachments();
assertEquals(1, attachments.getSize());
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class CreateContentHandlerTest method createContentAutoGenerateNameWithExistingName.
@Test
public void createContentAutoGenerateNameWithExistingName() throws Exception {
when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content")))).thenReturn(true);
when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-1")))).thenReturn(true);
when(this.contentService.contentExists(Mockito.eq(ContentPath.from("/a/b/my-content-2")))).thenReturn(true);
final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).build();
GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
runFunction("/test/CreateContentHandlerTest.js", "createContentAutoGenerateNameWithExistingName");
}
use of com.enonic.xp.content.CreateContentParams in project xp by enonic.
the class CreateContentHandlerTest method createContentAutoGenerateName.
@Test
public void createContentAutoGenerateName() throws Exception {
when(this.contentService.create(any(CreateContentParams.class))).thenAnswer(mock -> createContent((CreateContentParams) mock.getArguments()[0]));
final ContentType contentType = ContentType.create().name("test:myContentType").superType(ContentTypeName.structured()).build();
GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.from("test:myContentType"));
when(this.contentTypeService.getByName(Mockito.eq(getContentType))).thenReturn(contentType);
runFunction("/test/CreateContentHandlerTest.js", "createContentAutoGenerateName");
}
Aggregations