Search in sources :

Example 81 with Content

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

the class OccurrenceValidatorTest method given_input_with_maxOccur1_with_three_null_data_when_validate_then_hasErrors_returns_false.

@Test
public void given_input_with_maxOccur1_with_three_null_data_when_validate_then_hasErrors_returns_false() {
    contentType.getForm().getFormItems().add(Input.create().name("myInput").label("Input").inputType(InputTypeName.TEXT_LINE).maximumOccurrences(1).build());
    Content content = Content.create().path(MY_CONTENT_PATH).type(contentType.getName()).build();
    content.getData().setString("myInput[0]", null);
    content.getData().setString("myInput[1]", null);
    content.getData().setString("myInput[2]", null);
    // exercise
    final ValidationErrors validationResults = validate(content);
    assertFalse(validationResults.hasErrors());
}
Also used : ValidationErrors(com.enonic.xp.content.ValidationErrors) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 82 with Content

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

the class ContentServiceImplTest_update method update_content_with_thumbnail_keep_on_update.

@Test
public void update_content_with_thumbnail_keep_on_update() 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 UpdateContentParams updateContentParams2 = new UpdateContentParams();
    updateContentParams2.contentId(content.getId()).editor(edit -> {
        edit.displayName = "brand new display name";
    });
    this.contentService.update(updateContentParams2);
    final Content reUpdatedContent = this.contentService.getById(content.getId());
    assertNotNull(reUpdatedContent.getThumbnail());
    assertEquals(thumbnail.size(), reUpdatedContent.getThumbnail().getSize());
    assertEquals("brand new display name", reUpdatedContent.getDisplayName());
}
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) Test(org.junit.jupiter.api.Test)

Example 83 with Content

use of com.enonic.xp.content.Content 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());
}
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 84 with Content

use of com.enonic.xp.content.Content 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"));
}
Also used : MixinName(com.enonic.xp.schema.mixin.MixinName) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ExtraDatas(com.enonic.xp.content.ExtraDatas) ExtraData(com.enonic.xp.content.ExtraData) Mixin(com.enonic.xp.schema.mixin.Mixin) Test(org.junit.jupiter.api.Test)

Example 85 with Content

use of com.enonic.xp.content.Content 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)

Aggregations

Content (com.enonic.xp.content.Content)560 Test (org.junit.jupiter.api.Test)432 PropertyTree (com.enonic.xp.data.PropertyTree)130 CreateContentParams (com.enonic.xp.content.CreateContentParams)57 ContentId (com.enonic.xp.content.ContentId)50 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)48 ContentPath (com.enonic.xp.content.ContentPath)47 ValidationErrors (com.enonic.xp.content.ValidationErrors)47 Site (com.enonic.xp.site.Site)43 PropertySet (com.enonic.xp.data.PropertySet)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)27 Page (com.enonic.xp.page.Page)26 Contents (com.enonic.xp.content.Contents)25 Node (com.enonic.xp.node.Node)25 ContentIds (com.enonic.xp.content.ContentIds)24 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)24 ContentQuery (com.enonic.xp.content.ContentQuery)23 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)23 DataValidationError (com.enonic.xp.content.DataValidationError)21 ContentType (com.enonic.xp.schema.content.ContentType)20