Property prop5 = createProperty("p5", valueFactories.getBinaryFactory().create("something"));
String binaryValueStr = "really really long string that will be converted to a binary value and tested like that";
Binary binaryValue = valueFactories.getBinaryFactory().create(binaryValueStr);
Property prop6 = createProperty("p6", binaryValue);
UUID uuid7 = UUID.randomUUID();
Reference ref7 = valueFactories.getReferenceFactory().create(uuid7);
Property prop7 = createProperty("p7", ref7);
UUID uuid8 = UUID.randomUUID();
Reference ref8 = valueFactories.getReferenceFactory().create(uuid8);
Property prop8 = createProperty("p8", ref8);
// Serialize the properties (and verify they're serialized properly) ...
Property[] props = new Property[] {prop1, prop2, prop3, prop4, prop5, prop6, prop7, prop8};
byte[] content = serialize(serializer, props);
List<Property> properties = deserialize(serializer, content);
assertThat(properties, hasItems(props));
// Define the old-to-new UUID mapping ...
UUID newUuid7 = UUID.randomUUID();
Map<String, String> oldToNewUuids = new HashMap<String, String>();
oldToNewUuids.put(uuid7.toString(), newUuid7.toString());
// note that 'uuid8' is not included, so 'ref8' should be untouched
// Now update the references in the serialized properties ...
ByteArrayInputStream bais = new ByteArrayInputStream(content);
ObjectInputStream ois = new ObjectInputStream(bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
try {
serializer.adjustReferenceProperties(ois, oos, oldToNewUuids);
} finally {
baos.close();
oos.close();
}
byte[] newContent = baos.toByteArray();
// Now deserialize the updated content ...
properties = deserialize(serializer, newContent);
// Update a new 'prop7' ...
Reference newRef7 = valueFactories.getReferenceFactory().create(newUuid7);
Property newProp7 = createProperty("p7", newRef7);
Property[] newProps = new Property[] {prop1, prop2, prop3, prop4, prop5, prop6, newProp7, prop8};
// Finally verify that the updated content matches the expected new properties ...
assertThat(properties, hasItems(newProps));