Search in sources :

Example 36 with UpdateContentParams

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());
}
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) ByteSource(com.google.common.io.ByteSource) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Example 37 with UpdateContentParams

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"));
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 38 with UpdateContentParams

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());
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 39 with UpdateContentParams

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());
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 40 with UpdateContentParams

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())));
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateContentParams (com.enonic.xp.content.UpdateContentParams)49 Content (com.enonic.xp.content.Content)43 Test (org.junit.jupiter.api.Test)35 PropertyTree (com.enonic.xp.data.PropertyTree)27 CreateContentParams (com.enonic.xp.content.CreateContentParams)14 ContentPath (com.enonic.xp.content.ContentPath)9 EditableContent (com.enonic.xp.content.EditableContent)9 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 ContentId (com.enonic.xp.content.ContentId)8 ContentInheritType (com.enonic.xp.content.ContentInheritType)7 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)7 ByteSource (com.google.common.io.ByteSource)7 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)7 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)7 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)6 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)6 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)6 ResetContentInheritParams (com.enonic.xp.content.ResetContentInheritParams)6 SetContentChildOrderParams (com.enonic.xp.content.SetContentChildOrderParams)6