Search in sources :

Example 36 with PropertySet

use of com.enonic.xp.data.PropertySet in project xp by enonic.

the class ContentDataSerializerTest method update_propertyTree_populated_with_extraData.

@Test
public void update_propertyTree_populated_with_extraData() {
    final ContentDataSerializer contentDataSerializer = createContentDataSerializer();
    PropertyTree mixinData = new PropertyTree();
    mixinData.setString("myKey1", "myValue1");
    mixinData.setString("myKey2", "myValue2");
    final PropertyTree updatedProperties = contentDataSerializer.toUpdateNodeData(UpdateContentTranslatorParams.create().editedContent(Content.create().name("myContent").parentPath(ContentPath.ROOT).creator(PrincipalKey.ofAnonymous()).extraDatas(ExtraDatas.create().add(new ExtraData(XDataName.from(ApplicationKey.SYSTEM, "myMixin"), mixinData)).build()).build()).modifier(PrincipalKey.ofAnonymous()).build());
    final PropertySet extraData = updatedProperties.getSet(ContentPropertyNames.EXTRA_DATA);
    assertNotNull(extraData);
    final PropertySet systemAppData = extraData.getSet(ApplicationKey.SYSTEM.getName());
    assertNotNull(systemAppData);
    final PropertySet myMixinData = systemAppData.getSet("myMixin");
    assertNotNull(myMixinData);
    assertEquals("myValue1", myMixinData.getString("myKey1"));
    assertEquals("myValue1", myMixinData.getString("myKey1"));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ExtraData(com.enonic.xp.content.ExtraData) Test(org.junit.jupiter.api.Test)

Example 37 with PropertySet

use of com.enonic.xp.data.PropertySet in project xp by enonic.

the class ContentDataSerializerTest method update_add_content_data.

@Test
public void update_add_content_data() {
    final ContentDataSerializer contentDataSerializer = createContentDataSerializer();
    final PropertyTree propertyTree = new PropertyTree();
    propertyTree.setString("myData", "myValue");
    final PropertyTree data = contentDataSerializer.toUpdateNodeData(UpdateContentTranslatorParams.create().editedContent(Content.create().name("myContent").parentPath(ContentPath.ROOT).creator(PrincipalKey.ofAnonymous()).data(propertyTree).build()).modifier(PrincipalKey.ofAnonymous()).build());
    final PropertySet contentData = data.getSet("data");
    assertNotNull(contentData);
    assertNotNull(contentData.getString("myData"));
    assertEquals("myValue", contentData.getString("myData"));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 38 with PropertySet

use of com.enonic.xp.data.PropertySet in project xp by enonic.

the class ContentDataSerializerTest method update_propertyTree_populated_with_new_attachment_properties.

@Test
public void update_propertyTree_populated_with_new_attachment_properties() {
    final ContentDataSerializer contentDataSerializer = createContentDataSerializer();
    final String binaryName = "myName";
    final String binaryLabel = "myLabel";
    final String binaryMimeType = "myMimeType";
    final byte[] binaryData = "my binary".getBytes();
    final UpdateContentTranslatorParams params = UpdateContentTranslatorParams.create().editedContent(Content.create().name("myContent").parentPath(ContentPath.ROOT).creator(PrincipalKey.ofAnonymous()).validationErrors(ValidationErrors.create().add(ValidationError.attachmentError(ValidationErrorCode.from(ApplicationKey.SYSTEM, "SOME_CODE"), BinaryReference.from("prevFile")).message("someError").build()).build()).build()).modifier(PrincipalKey.ofAnonymous()).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(ByteSource.wrap(binaryData)).label(binaryLabel).mimeType(binaryMimeType).name(binaryName).build())).build();
    final PropertyTree data = contentDataSerializer.toUpdateNodeData(params);
    final PropertySet attachmentData = data.getSet(ContentPropertyNames.ATTACHMENT);
    assertNotNull(attachmentData);
    assertEquals(binaryName, attachmentData.getString(ContentPropertyNames.ATTACHMENT_NAME));
    assertEquals(binaryLabel, attachmentData.getString(ContentPropertyNames.ATTACHMENT_LABEL));
    assertEquals(binaryMimeType, attachmentData.getString(ContentPropertyNames.ATTACHMENT_MIMETYPE));
    assertEquals(binaryData.length + "", attachmentData.getString(ContentPropertyNames.ATTACHMENT_SIZE));
    assertEquals(binaryName, attachmentData.getString(ContentPropertyNames.ATTACHMENT_BINARY_REF));
}
Also used : UpdateContentTranslatorParams(com.enonic.xp.content.UpdateContentTranslatorParams) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 39 with PropertySet

use of com.enonic.xp.data.PropertySet in project xp by enonic.

the class PageDataSerializerTest method page_config.

@Test
public void page_config() {
    final Page page = createPage();
    final PropertyTree pageAsData = new PropertyTree();
    pageDataSerializer.toData(page, pageAsData.getRoot());
    final PropertySet pageOnlyData = pageAsData.getRoot().getProperties(COMPONENTS).get(0).getSet();
    assertTrue(pageOnlyData.hasProperty("page.config.app-key.d-name"));
    assertEquals("42.0", pageOnlyData.getString("page.config.app-key.d-name.aim"));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)

Example 40 with PropertySet

use of com.enonic.xp.data.PropertySet in project xp by enonic.

the class PageDataSerializerTest method page_deserialize_custom_order_of_components.

@Test
public void page_deserialize_custom_order_of_components() {
    final Page page = createPage();
    final PropertyTree pageAsData = new PropertyTree();
    pageDataSerializer.toData(page, pageAsData.getRoot());
    final List<PropertySet> componentsAsData = pageAsData.getRoot().getProperties(COMPONENTS).stream().filter(Property::hasNotNullValue).map(item -> item.getSet()).collect(Collectors.toList());
    final List<PropertySet> customOrdercomponentsAsData = new ArrayList<>();
    customOrdercomponentsAsData.add(componentsAsData.get(7));
    customOrdercomponentsAsData.add(componentsAsData.get(11));
    customOrdercomponentsAsData.add(componentsAsData.get(4));
    customOrdercomponentsAsData.add(componentsAsData.get(3));
    customOrdercomponentsAsData.add(componentsAsData.get(1));
    customOrdercomponentsAsData.add(componentsAsData.get(10));
    customOrdercomponentsAsData.add(componentsAsData.get(5));
    customOrdercomponentsAsData.add(componentsAsData.get(6));
    customOrdercomponentsAsData.add(componentsAsData.get(8));
    customOrdercomponentsAsData.add(componentsAsData.get(2));
    customOrdercomponentsAsData.add(componentsAsData.get(0));
    customOrdercomponentsAsData.add(componentsAsData.get(9));
    final PropertySet root = new PropertySet();
    customOrdercomponentsAsData.forEach(componentData -> root.addSet(COMPONENTS, componentData));
    final Page parsedPage = pageDataSerializer.fromData(root);
    assertEquals(page, parsedPage);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PageDescriptor(com.enonic.xp.page.PageDescriptor) RegionDescriptors(com.enonic.xp.region.RegionDescriptors) Page(com.enonic.xp.page.Page) ArrayList(java.util.ArrayList) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Region(com.enonic.xp.region.Region) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ImageComponent(com.enonic.xp.region.ImageComponent) PageRegions(com.enonic.xp.page.PageRegions) RegionDescriptor(com.enonic.xp.region.RegionDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) TextComponent(com.enonic.xp.region.TextComponent) Property(com.enonic.xp.data.Property) PropertySet(com.enonic.xp.data.PropertySet) PageTemplateKey(com.enonic.xp.page.PageTemplateKey) Collectors(java.util.stream.Collectors) COMPONENTS(com.enonic.xp.core.impl.content.serializer.ComponentDataSerializer.COMPONENTS) Test(org.junit.jupiter.api.Test) Form(com.enonic.xp.form.Form) Mockito(org.mockito.Mockito) List(java.util.List) LayoutComponent(com.enonic.xp.region.LayoutComponent) DescriptorKey(com.enonic.xp.page.DescriptorKey) LayoutRegions(com.enonic.xp.region.LayoutRegions) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest) PartComponent(com.enonic.xp.region.PartComponent) PropertyTree(com.enonic.xp.data.PropertyTree) ArrayList(java.util.ArrayList) PropertySet(com.enonic.xp.data.PropertySet) Page(com.enonic.xp.page.Page) Property(com.enonic.xp.data.Property) Test(org.junit.jupiter.api.Test) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)

Aggregations

PropertySet (com.enonic.xp.data.PropertySet)225 PropertyTree (com.enonic.xp.data.PropertyTree)150 Test (org.junit.jupiter.api.Test)69 Content (com.enonic.xp.content.Content)30 Node (com.enonic.xp.node.Node)20 CreateContentParams (com.enonic.xp.content.CreateContentParams)12 ContentId (com.enonic.xp.content.ContentId)11 Property (com.enonic.xp.data.Property)11 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)10 PrincipalKey (com.enonic.xp.security.PrincipalKey)9 ContentQuery (com.enonic.xp.content.ContentQuery)7 DescriptorKey (com.enonic.xp.page.DescriptorKey)7 ExtraDatas (com.enonic.xp.content.ExtraDatas)6 Form (com.enonic.xp.form.Form)6 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)6 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)5 ContentPropertyNames (com.enonic.xp.content.ContentPropertyNames)5 ExtraData (com.enonic.xp.content.ExtraData)5 PropertyPath (com.enonic.xp.data.PropertyPath)5 Page (com.enonic.xp.page.Page)5