Example usage for org.apache.commons.lang SerializationUtils clone

List of usage examples for org.apache.commons.lang SerializationUtils clone

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationUtils clone.

Prototype

public static Object clone(Serializable object) 

Source Link

Document

Deep clone an Object using serialization.

This is many times slower than writing clone methods by hand on all objects in your object graph.

Usage

From source file:org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReplyTest.java

@Test
public void testSerialization() {
    String cohortPath = "cohort path";
    ReadyTransactionReply expected = new ReadyTransactionReply(cohortPath);

    Object serialized = expected.toSerializable();
    assertEquals("Serialized type", ReadyTransactionReply.class, serialized.getClass());

    ReadyTransactionReply actual = ReadyTransactionReply
            .fromSerializable(SerializationUtils.clone((Serializable) serialized));
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
    assertEquals("getCohortPath", cohortPath, actual.getCohortPath());
}

From source file:org.opendaylight.controller.cluster.datastore.messages.WriteDataTest.java

@Test
public void testSerialization() {
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

    WriteData expected = new WriteData(path, data, DataStoreVersions.CURRENT_VERSION);

    Object serialized = expected.toSerializable();
    assertEquals("Serialized type", WriteData.class, serialized.getClass());
    assertEquals("Version", DataStoreVersions.CURRENT_VERSION, ((WriteData) serialized).getVersion());

    Object clone = SerializationUtils.clone((Serializable) serialized);
    WriteData actual = WriteData.fromSerializable(clone);
    assertEquals("Version", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
    assertEquals("getPath", expected.getPath(), actual.getPath());
    assertEquals("getData", expected.getData(), actual.getData());
}

From source file:org.opendaylight.controller.cluster.datastore.messages.WriteDataTest.java

/**
 * Tests backwards compatible serialization/deserialization of a WriteData message with the
 * base and R1 Helium versions, which used the protobuff WriteData message.
 *//*from  ww  w.j  ava 2s .c  om*/
@Test
public void testSerializationWithHeliumR1Version() throws Exception {
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

    WriteData expected = new WriteData(path, data, DataStoreVersions.HELIUM_1_VERSION);

    Object serialized = expected.toSerializable();
    assertEquals("Serialized type", ShardTransactionMessages.WriteData.class, serialized.getClass());

    WriteData actual = WriteData.fromSerializable(SerializationUtils.clone((Serializable) serialized));
    assertEquals("getPath", expected.getPath(), actual.getPath());
    assertEquals("getData", expected.getData(), actual.getData());
}

From source file:org.opendaylight.controller.cluster.datastore.modification.DeleteModificationTest.java

@Test
public void testSerialization() {
    YangInstanceIdentifier path = TestModel.TEST_PATH;

    DeleteModification expected = new DeleteModification(path);

    DeleteModification clone = (DeleteModification) SerializationUtils.clone(expected);
    assertEquals("getPath", expected.getPath(), clone.getPath());
}

From source file:org.opendaylight.controller.cluster.datastore.modification.MergeModificationTest.java

@Test
public void testSerialization() {
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

    MergeModification expected = new MergeModification(path, data);

    MergeModification clone = (MergeModification) SerializationUtils.clone(expected);
    assertEquals("getPath", expected.getPath(), clone.getPath());
    assertEquals("getData", expected.getData(), clone.getData());
}

From source file:org.opendaylight.controller.cluster.datastore.modification.ModificationPayloadTest.java

@Test
public void test() throws Exception {

    YangInstanceIdentifier writePath = TestModel.TEST_PATH;
    NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

    MutableCompositeModification compositeModification = new MutableCompositeModification();
    compositeModification.addModification(new WriteModification(writePath, writeData));

    ModificationPayload payload = new ModificationPayload(compositeModification);

    MutableCompositeModification deserialized = (MutableCompositeModification) payload.getModification();

    assertEquals("getModifications size", 1, deserialized.getModifications().size());
    WriteModification write = (WriteModification) deserialized.getModifications().get(0);
    assertEquals("getPath", writePath, write.getPath());
    assertEquals("getData", writeData, write.getData());

    ModificationPayload cloned = (ModificationPayload) SerializationUtils.clone(payload);

    deserialized = (MutableCompositeModification) payload.getModification();

    assertEquals("getModifications size", 1, deserialized.getModifications().size());
    write = (WriteModification) deserialized.getModifications().get(0);
    assertEquals("getPath", writePath, write.getPath());
    assertEquals("getData", writeData, write.getData());
}

From source file:org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModificationTest.java

@Test
public void testSerialization() {
    YangInstanceIdentifier writePath = TestModel.TEST_PATH;
    NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

    YangInstanceIdentifier mergePath = TestModel.OUTER_LIST_PATH;
    NormalizedNode<?, ?> mergeData = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();

    YangInstanceIdentifier deletePath = TestModel.TEST_PATH;

    MutableCompositeModification compositeModification = new MutableCompositeModification();
    compositeModification.addModification(new WriteModification(writePath, writeData));
    compositeModification.addModification(new MergeModification(mergePath, mergeData));
    compositeModification.addModification(new DeleteModification(deletePath));

    MutableCompositeModification clone = (MutableCompositeModification) SerializationUtils
            .clone(compositeModification);

    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, clone.getVersion());

    assertEquals("getModifications size", 3, clone.getModifications().size());

    WriteModification write = (WriteModification) clone.getModifications().get(0);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, write.getVersion());
    assertEquals("getPath", writePath, write.getPath());
    assertEquals("getData", writeData, write.getData());

    MergeModification merge = (MergeModification) clone.getModifications().get(1);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, merge.getVersion());
    assertEquals("getPath", mergePath, merge.getPath());
    assertEquals("getData", mergeData, merge.getData());

    DeleteModification delete = (DeleteModification) clone.getModifications().get(2);
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, delete.getVersion());
    assertEquals("getPath", deletePath, delete.getPath());
}

From source file:org.opendaylight.controller.cluster.datastore.modification.WriteModificationTest.java

@Test
public void testSerialization() {
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

    WriteModification expected = new WriteModification(path, data);

    WriteModification clone = (WriteModification) SerializationUtils.clone(expected);
    assertEquals("getPath", expected.getPath(), clone.getPath());
    assertEquals("getData", expected.getData(), clone.getData());
}

From source file:org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeStreamReaderWriterTest.java

@Test
public void testWithSerializable() {
    NormalizedNode<?, ?> input = TestModel.createTestContainer();
    SampleNormalizedNodeSerializable serializable = new SampleNormalizedNodeSerializable(input);
    SampleNormalizedNodeSerializable clone = (SampleNormalizedNodeSerializable) SerializationUtils
            .clone(serializable);//from  w ww  .j  av a2  s . c om

    Assert.assertEquals(input, clone.getInput());

}

From source file:org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshotTest.java

@Test
public void testSerialization() {
    ShardManagerSnapshot expected = new ShardManagerSnapshot(Arrays.asList("shard1", "shard2"),
            Collections.emptyMap());
    ShardManagerSnapshot cloned = (ShardManagerSnapshot) SerializationUtils.clone(expected);

    assertEquals("getShardList", expected.getShardList(), cloned.getShardList());
}