package org.opendaylight.controller.cluster.datastore.messages;
import static org.junit.Assert.assertEquals;
+
import java.io.Serializable;
import org.apache.commons.lang.SerializationUtils;
import org.junit.Test;
import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
-import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
@Test
public void testSerialization() {
- NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
- new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
- withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
+ NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
+ .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
ReadDataReply expected = new ReadDataReply(data, DataStoreVersions.CURRENT_VERSION);
@Test
public void testIsSerializedType() {
- assertEquals("isSerializedType", true, ReadDataReply.isSerializedType(
- ShardTransactionMessages.ReadDataReply.newBuilder().build()));
assertEquals("isSerializedType", true, ReadDataReply.isSerializedType(new ReadDataReply()));
assertEquals("isSerializedType", false, ReadDataReply.isSerializedType(new Object()));
}
-
- /**
- * Tests backwards compatible serialization/deserialization of a ReadDataReply message with the
- * base and R1 Helium versions, which used the protobuff ReadDataReply message.
- */
- @Test
- public void testSerializationWithHeliumR1Version() throws Exception {
- NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
- new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
- withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
-
- ReadDataReply expected = new ReadDataReply(data, DataStoreVersions.HELIUM_1_VERSION);
-
- Object serialized = expected.toSerializable();
- assertEquals("Serialized type", ShardTransactionMessages.ReadDataReply.class, serialized.getClass());
-
- ReadDataReply actual = ReadDataReply.fromSerializable(SerializationUtils.clone(
- (Serializable) serialized));
- assertEquals("getNormalizedNode", expected.getNormalizedNode(), actual.getNormalizedNode());
- }
}