Search in sources :

Example 6 with CreateContentParams

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

the class ContentServiceImplTest_update method update_content_data.

@Test
public void update_content_data() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.setString("testString", "value");
    data.setString("testString2", "value");
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(data).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> {
        final PropertyTree editData = edit.data;
        editData.setString("testString", "value-updated");
    });
    this.contentService.update(updateContentParams);
    final Content storedContent = this.contentService.getById(content.getId());
    assertEquals("This is my content", storedContent.getDisplayName());
    assertEquals("value-updated", storedContent.getData().getString("testString"));
    assertEquals("value", storedContent.getData().getString("testString2"));
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 7 with CreateContentParams

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

the class ContentServiceImplTest_update method update_thumbnail.

@Test
public void update_thumbnail() throws Exception {
    final ByteSource thumbnail = loadImage("cat-small.jpg");
    final CreateContentParams createContentParams = CreateContentParams.create().displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).contentData(new PropertyTree()).build();
    final Content content = this.contentService.create(createContentParams);
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> {
        edit.displayName = "new display name";
    }).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(thumbnail).name(AttachmentNames.THUMBNAIL).mimeType("image/jpeg").build()));
    this.contentService.update(updateContentParams);
    final Content updatedContent = this.contentService.getById(content.getId());
    assertNotNull(updatedContent.getThumbnail());
    assertEquals(thumbnail.size(), updatedContent.getThumbnail().getSize());
    final ByteSource newThumbnail = loadImage("darth-small.jpg");
    final UpdateContentParams updateContentParams2 = new UpdateContentParams();
    updateContentParams2.contentId(content.getId()).editor(edit -> {
        edit.displayName = "yet another display name";
    }).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(newThumbnail).name(AttachmentNames.THUMBNAIL).mimeType("image/jpeg").build()));
    this.contentService.update(updateContentParams2);
    final Content reUpdatedContent = this.contentService.getById(content.getId());
    assertNotNull(reUpdatedContent.getThumbnail());
    final Thumbnail thumbnailAttachment = reUpdatedContent.getThumbnail();
    assertEquals(newThumbnail.size(), thumbnailAttachment.getSize());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) LocalDateTime(java.time.LocalDateTime) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) WorkflowState(com.enonic.xp.content.WorkflowState) ContentTypeService(com.enonic.xp.schema.content.ContentTypeService) MixinName(com.enonic.xp.schema.mixin.MixinName) Mixin(com.enonic.xp.schema.mixin.Mixin) ArgumentCaptor(org.mockito.ArgumentCaptor) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ExtraData(com.enonic.xp.content.ExtraData) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Map(java.util.Map) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) Thumbnail(com.enonic.xp.icon.Thumbnail) XDataName(com.enonic.xp.schema.xdata.XDataName) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) ContentPath(com.enonic.xp.content.ContentPath) PropertySet(com.enonic.xp.data.PropertySet) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) ExtraDatas(com.enonic.xp.content.ExtraDatas) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) AttachmentNames(com.enonic.xp.attachment.AttachmentNames) List(java.util.List) InputTypeName(com.enonic.xp.inputtype.InputTypeName) LocalDate(java.time.LocalDate) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Attachments(com.enonic.xp.attachment.Attachments) Input(com.enonic.xp.form.Input) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ByteSource(com.google.common.io.ByteSource) Thumbnail(com.enonic.xp.icon.Thumbnail) Test(org.junit.jupiter.api.Test)

Example 8 with CreateContentParams

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

the class ParentContentSynchronizerTest method syncCreatedWithChildren.

@Test
public void syncCreatedWithChildren() throws Exception {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").createAttachments(CreateAttachments.create().add(CreateAttachment.create().byteSource(ByteSource.wrap("bytes".getBytes())).label("attachment").name("attachmentName").mimeType("image/png").build()).build()).parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content sourceContent = sourceContext.callWith(() -> this.contentService.create(createContentParams));
    final Content targetContent = syncCreated(sourceContent.getId());
    compareSynched(sourceContent, targetContent);
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 9 with CreateContentParams

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

the class ContentServiceImplTest_undoPendingDelete method not_deleted_not_resurrected.

@Test
public void not_deleted_not_resurrected() throws Exception {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").name("myContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    int result = resurrect(ContentIds.from(ContentIds.from(content.getId())));
    assertEquals(0, result);
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 10 with CreateContentParams

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

the class ContentServiceImplTest_update method update_content_modified_time_updated.

@Test
public void update_content_modified_time_updated() throws Exception {
    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);
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> {
        edit.displayName = "new display name";
    });
    this.contentService.update(updateContentParams);
    final Content updatedContent = this.contentService.getById(content.getId());
    assertEquals("new display name", updatedContent.getDisplayName());
    assertNotNull(updatedContent.getCreator());
    assertNotNull(updatedContent.getCreatedTime());
    assertNotNull(updatedContent.getModifier());
    assertNotNull(updatedContent.getModifiedTime());
    assertTrue(updatedContent.getModifiedTime().isAfter(content.getModifiedTime()));
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) 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