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"));
}
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"));
}
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));
}
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"));
}
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);
}
Aggregations