use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.
the class ContentServiceImplTest_update method update_content_image.
@Test
public void update_content_image() throws Exception {
final ByteSource image = loadImage("cat-small.jpg");
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.imageMedia()).createAttachments(createAttachment("cat", "image/jpg", image)).build();
final Content content = this.contentService.create(createContentParams);
final UpdateContentParams updateContentParams = new UpdateContentParams();
updateContentParams.contentId(content.getId()).editor(edit -> {
edit.displayName = "new display name";
}).clearAttachments(true).createAttachments(createAttachment("darth", "image/jpg", loadImage("darth-small.jpg")));
this.contentService.update(updateContentParams);
final Content storedContent = this.contentService.getById(content.getId());
final Attachments attachments = storedContent.getAttachments();
assertEquals(1, attachments.getSize());
}
use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.
the class ContentServiceImplTest_update method audit_data.
@Test
public void audit_data() {
final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
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);
Mockito.verify(auditLogService, Mockito.timeout(5000).atLeast(16)).log(captor.capture());
final PropertySet logResultSet = captor.getAllValues().stream().filter(log -> log.getType().equals("system.content.update")).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.UpdateContentParams in project xp by enonic.
the class ProjectContentEventListenerTest method testArchivedNotInherited.
@Test
public void testArchivedNotInherited() throws InterruptedException {
final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "content"));
handleEvents();
targetContext.runWith(() -> contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).editor(edit -> edit.data = new PropertyTree())));
handleEvents();
sourceContext.runWith(() -> contentService.archive(ArchiveContentParams.create().contentId(sourceContent.getId()).build()));
handleEvents();
final Content targetContent = targetContext.callWith(() -> contentService.getById(sourceContent.getId()));
assertEquals("/content", targetContent.getPath().toString());
}
use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.
the class ProjectContentEventListenerTest method testUpdated.
@Test
public void testUpdated() throws InterruptedException {
final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "name"));
final Content updatedContent = sourceContext.callWith(() -> {
final Content updated = contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).editor((edit -> {
edit.data = new PropertyTree();
edit.displayName = "newDisplayName";
edit.extraDatas = ExtraDatas.create().add(createExtraData()).build();
edit.owner = PrincipalKey.from("user:system:newOwner");
edit.language = Locale.forLanguageTag("no");
edit.page = createPage();
})));
return updated;
});
handleEvents();
final Content targetContent = targetContext.callWith(() -> contentService.getById(sourceContent.getId()));
compareSynched(updatedContent, targetContent);
assertEquals(4, targetContent.getInherit().size());
}
use of com.enonic.xp.content.UpdateContentParams in project xp by enonic.
the class ParentContentSynchronizerTest method syncWithChildren.
@Test
public void syncWithChildren() throws Exception {
final Content sourceContent = sourceContext.callWith(() -> createContent(ContentPath.ROOT, "name"));
final Content sourceChild1 = sourceContext.callWith(() -> createContent(sourceContent.getPath(), "child1"));
sync(sourceContent.getId(), true);
assertTrue(targetContext.callWith(() -> contentService.contentExists(sourceChild1.getId())));
final Content sourceChild1_1 = sourceContext.callWith(() -> createContent(sourceContent.getPath(), "child1_1"));
sync(sourceContent.getId(), true);
assertTrue(targetContext.callWith(() -> contentService.contentExists(sourceChild1_1.getId())));
sourceContext.callWith(() -> contentService.move(MoveContentParams.create().contentId(sourceChild1_1.getId()).parentContentPath(ContentPath.ROOT).build()));
sourceContext.callWith(() -> contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(sourceChild1.getPath()).build()));
sourceContext.callWith(() -> contentService.update(new UpdateContentParams().contentId(sourceContent.getId()).editor(edit -> edit.data = new PropertyTree())));
sync(null, true);
refresh();
assertEquals("/child1_1", targetContext.callWith(() -> contentService.getById(sourceChild1_1.getId()).getPath().toString()));
assertFalse(targetContext.callWith(() -> contentService.contentExists(sourceChild1.getId())));
}
Aggregations