Search in sources :

Example 16 with UpdateContentParams

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);
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams)

Example 17 with UpdateContentParams

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

the class SyncContentServiceImplTest method resetWithRemovedSource.

@Test
public void resetWithRemovedSource() throws Exception {
    final Content source = sourceContext.callWith(() -> createContent(ContentPath.ROOT));
    syncCreated(source.getId());
    targetContext.runWith(() -> {
        contentService.update(new UpdateContentParams().contentId(source.getId()).editor(edit -> {
            edit.workflowInfo = WorkflowInfo.ready();
            edit.data = new PropertyTree();
        }));
    });
    sourceContext.runWith(() -> contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(source.getPath()).build()));
    assertThrows(IllegalArgumentException.class, () -> syncContentService.resetInheritance(ResetContentInheritParams.create().contentId(source.getId()).inherit(EnumSet.of(ContentInheritType.CONTENT)).projectName(targetProject.getName()).build()));
}
Also used : ChildOrder(com.enonic.xp.index.ChildOrder) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) ContentPath(com.enonic.xp.content.ContentPath) ProjectSyncParams(com.enonic.xp.content.ProjectSyncParams) ContentInheritType(com.enonic.xp.content.ContentInheritType) Content(com.enonic.xp.content.Content) DeleteContentParams(com.enonic.xp.content.DeleteContentParams) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) ContentSyncEventType(com.enonic.xp.core.impl.content.ContentSyncEventType) Test(org.junit.jupiter.api.Test) ParentContentSynchronizer(com.enonic.xp.core.impl.content.ParentContentSynchronizer) SyncContentServiceImpl(com.enonic.xp.core.impl.content.SyncContentServiceImpl) ContentId(com.enonic.xp.content.ContentId) ResetContentInheritParams(com.enonic.xp.content.ResetContentInheritParams) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ProjectName(com.enonic.xp.project.ProjectName) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SetContentChildOrderParams(com.enonic.xp.content.SetContentChildOrderParams) ContentEventsSyncParams(com.enonic.xp.core.impl.content.ContentEventsSyncParams) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EnumSet(java.util.EnumSet) PropertyTree(com.enonic.xp.data.PropertyTree) 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 18 with UpdateContentParams

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

the class UpdateContentCommandTest method given_content_not_found_when_handle_then_NOT_FOUND_is_returned.

@Test
public void given_content_not_found_when_handle_then_NOT_FOUND_is_returned() throws Exception {
    // setup
    PropertyTree existingContentData = new PropertyTree();
    existingContentData.addString("myData", "aaa");
    ContentId contentId = ContentId.from("mycontent");
    UpdateContentParams params = new UpdateContentParams().contentId(contentId).editor(edit -> {
    });
    UpdateContentCommand command = UpdateContentCommand.create(params).contentTypeService(this.contentTypeService).nodeService(this.nodeService).translator(this.translator).eventPublisher(this.eventPublisher).mediaInfo(this.mediaInfo).xDataService(this.xDataService).siteService(this.siteService).build();
    Mockito.when(nodeService.getById(Mockito.isA(NodeId.class))).thenThrow(new NodeNotFoundException("Node not found"));
    // exercise
    assertThrows(ContentNotFoundException.class, () -> command.execute());
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 19 with UpdateContentParams

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

the class ModifyContentHandlerTest method modifyNotMappedXDataFieldNameNotStricted.

@Test
public void modifyNotMappedXDataFieldNameNotStricted() throws Exception {
    final Content content = TestDataFixtures.newSmallContent();
    when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    when(this.contentService.update(Mockito.isA(UpdateContentParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateContentParams) invocationOnMock.getArguments()[0], TestDataFixtures.newSmallContent()));
    mockXData();
    runFunction("/test/ModifyContentHandlerTest.js", "modifyNotMappedXDataFieldName_notStricted");
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) Test(org.junit.jupiter.api.Test)

Example 20 with UpdateContentParams

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

the class ModifyContentHandlerTest method modifyByPath.

@Test
public void modifyByPath() throws Exception {
    final Content content = TestDataFixtures.newSmallContent();
    when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    when(this.contentService.update(Mockito.isA(UpdateContentParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateContentParams) invocationOnMock.getArguments()[0], TestDataFixtures.newSmallContent()));
    mockXData();
    runFunction("/test/ModifyContentHandlerTest.js", "modifyByPath");
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) 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