use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.
the class ContentServiceImplTest_update method update_workflow_info.
@Test
public void update_workflow_info() throws Exception {
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).workflowInfo(WorkflowInfo.inProgress()).build();
final Content content = this.contentService.create(createContentParams);
final UpdateContentParams updateContentParams = new UpdateContentParams();
updateContentParams.contentId(content.getId()).editor(edit -> {
edit.workflowInfo = WorkflowInfo.create().state(WorkflowState.PENDING_APPROVAL).checks(Map.of("Laywer review", WorkflowCheckState.PENDING)).build();
});
this.contentService.update(updateContentParams);
final Content storedContent = this.contentService.getById(content.getId());
assertNotNull(storedContent.getWorkflowInfo());
assertNotNull(storedContent.getWorkflowInfo().getState());
assertNotNull(storedContent.getWorkflowInfo().getChecks());
assertEquals(WorkflowState.PENDING_APPROVAL, storedContent.getWorkflowInfo().getState());
assertEquals(Map.of("Laywer review", WorkflowCheckState.PENDING), storedContent.getWorkflowInfo().getChecks());
}
use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.
the class ContentServiceImplTest_update method update_with_metadata.
@Test
public void update_with_metadata() throws Exception {
final PropertyTree data = new PropertyTree();
data.setString("testString", "value");
data.setString("testString2", "value");
final Mixin mixin = Mixin.create().name("myapplication:my_mixin").addFormItem(Input.create().name("inputToBeMixedIn").label("Mixed in").inputType(InputTypeName.TEXT_LINE).build()).build();
Mockito.when(this.mixinService.getByName(Mockito.isA(MixinName.class))).thenReturn(mixin);
final ExtraData extraData = new ExtraData(XDataName.from("myapplication:my_mixin"), new PropertyTree());
ExtraDatas extraDatas = ExtraDatas.from(List.of(extraData));
final CreateContentParams createContentParams = CreateContentParams.create().contentData(data).displayName("This is my content").parent(ContentPath.ROOT).permissions(AccessControlList.empty()).type(ContentTypeName.folder()).extraDatas(extraDatas).build();
final Content content = this.contentService.create(createContentParams);
assertTrue(content.hasExtraData());
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"));
}
use of com.enonic.xp.content.UpdateContentParams 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"));
}
use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.
the class ContentServiceImplTest_update method update_incorrect_content_data.
private void update_incorrect_content_data(Content content, PropertyTree invalidData) {
final UpdateContentParams updateContentParams = new UpdateContentParams();
updateContentParams.contentId(content.getId()).editor(edit -> {
edit.data = invalidData;
});
boolean illegalArgumentExceptionThrown = false;
try {
this.contentService.update(updateContentParams);
} catch (Exception e) {
illegalArgumentExceptionThrown = true;
}
assertTrue(illegalArgumentExceptionThrown);
}
use of com.enonic.xp.content.UpdateContentParams 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());
}
Aggregations