2 * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore.messages;
10 import static org.junit.Assert.assertEquals;
11 import java.io.Serializable;
12 import org.apache.commons.lang.SerializationUtils;
13 import org.junit.Test;
14 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
15 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
16 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
20 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
23 * Unit tests for ReadDataReply.
25 * @author Thomas Pantelis
27 public class ReadDataReplyTest {
30 public void testSerialization() {
31 NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
32 new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
33 withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
35 ReadDataReply expected = new ReadDataReply(data, DataStoreVersions.CURRENT_VERSION);
37 Object serialized = expected.toSerializable();
38 assertEquals("Serialized type", ReadDataReply.class, serialized.getClass());
40 ReadDataReply actual = ReadDataReply.fromSerializable(SerializationUtils.clone(
41 (Serializable) serialized));
42 assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
43 assertEquals("getNormalizedNode", expected.getNormalizedNode(), actual.getNormalizedNode());
47 public void testIsSerializedType() {
48 assertEquals("isSerializedType", true, ReadDataReply.isSerializedType(
49 ShardTransactionMessages.ReadDataReply.newBuilder().build()));
50 assertEquals("isSerializedType", true, ReadDataReply.isSerializedType(new ReadDataReply()));
51 assertEquals("isSerializedType", false, ReadDataReply.isSerializedType(new Object()));
55 * Tests backwards compatible serialization/deserialization of a ReadDataReply message with the
56 * base and R1 Helium versions, which used the protobuff ReadDataReply message.
59 public void testSerializationWithHeliumR1Version() throws Exception {
60 NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
61 new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
62 withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
64 ReadDataReply expected = new ReadDataReply(data, DataStoreVersions.HELIUM_1_VERSION);
66 Object serialized = expected.toSerializable();
67 assertEquals("Serialized type", ShardTransactionMessages.ReadDataReply.class, serialized.getClass());
69 ReadDataReply actual = ReadDataReply.fromSerializable(SerializationUtils.clone(
70 (Serializable) serialized));
71 assertEquals("getNormalizedNode", expected.getNormalizedNode(), actual.getNormalizedNode());