use of com.enonic.xp.node.AttachedBinary in project xp by enonic.
the class NodeVersionJsonDumpSerializerTest method serialize_deserialize.
@Test
public void serialize_deserialize() throws Exception {
PropertyTree nodeData = new PropertyTree();
nodeData.setDouble("a.b.c", 2.0);
nodeData.setLocalDate("b", LocalDate.of(2013, 1, 2));
nodeData.setString("c", "runar");
nodeData.setLocalDateTime("d", LocalDateTime.of(2013, 1, 2, 3, 4, 5, 0));
nodeData.setBinaryReference("e", BinaryReference.from("myImage1"));
nodeData.setBinaryReference("f", BinaryReference.from("myImage2"));
final AccessControlEntry entry1 = AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allow(Permission.READ).deny(Permission.DELETE).build();
final AccessControlEntry entry2 = AccessControlEntry.create().principal(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).allow(Permission.MODIFY).deny(Permission.PUBLISH).build();
AccessControlList acl = AccessControlList.create().add(entry1).add(entry2).build();
IndexValueProcessor indexValueProcessor = new IndexValueProcessor() {
@Override
public Value process(final Value value) {
return value;
}
@Override
public String getName() {
return "indexValueProcessor";
}
};
IndexConfig indexConfig = IndexConfig.create().enabled(true).fulltext(true).nGram(true).decideByType(false).includeInAllText(true).path(true).addIndexValueProcessor(indexValueProcessor).addIndexValueProcessor(indexValueProcessor).build();
NodeVersion nodeVersion = NodeVersion.create().id(NodeId.from("myId")).indexConfigDocument(PatternIndexConfigDocument.create().analyzer("myAnalyzer").defaultConfig(IndexConfig.MINIMAL).add("myPath", indexConfig).build()).data(nodeData).childOrder(ChildOrder.create().add(FieldOrderExpr.create(IndexPath.from("modifiedTime"), OrderExpr.Direction.ASC)).add(FieldOrderExpr.create(IndexPath.from("displayName"), OrderExpr.Direction.DESC)).build()).permissions(acl).nodeType(NodeType.from("myNodeType")).attachedBinaries(AttachedBinaries.create().add(new AttachedBinary(BinaryReference.from("myImage1"), "a")).add(new AttachedBinary(BinaryReference.from("myImage2"), "b")).build()).build();
final String expectedNodeStr = readJson("serialized-node.json");
final String expectedIndexConfigStr = readJson("serialized-index.json");
final String expectedAccessControlStr = readJson("serialized-access.json");
final String serializedNode = new String(this.serializer.toNodeString(nodeVersion), StandardCharsets.UTF_8);
final String serializedIndexConfig = new String(this.serializer.toIndexConfigDocumentString(nodeVersion), StandardCharsets.UTF_8);
final String serializedAccessControl = new String(this.serializer.toAccessControlString(nodeVersion), StandardCharsets.UTF_8);
assertEquals(expectedNodeStr, serializedNode);
assertEquals(expectedIndexConfigStr, serializedIndexConfig);
assertEquals(expectedAccessControlStr, serializedAccessControl);
final NodeVersion deSerializedNode = this.serializer.toNodeVersion(expectedNodeStr.getBytes(StandardCharsets.UTF_8), expectedIndexConfigStr.getBytes(StandardCharsets.UTF_8), expectedAccessControlStr.getBytes(StandardCharsets.UTF_8));
assertEquals(nodeVersion, deSerializedNode);
}
Aggregations