Bump odlparent/yangtools/mdsal
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / messages / ReadDataReplyTest.java
1 /*
2  * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.messages;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13
14 import java.io.Serializable;
15 import org.apache.commons.lang.SerializationUtils;
16 import org.junit.Test;
17 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
18 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
22 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
23
24 /**
25  * Unit tests for ReadDataReply.
26  *
27  * @author Thomas Pantelis
28  */
29 public class ReadDataReplyTest {
30
31     @Test
32     public void testSerialization() {
33         NormalizedNode data = ImmutableContainerNodeBuilder.create()
34                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
35                 .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
36
37         ReadDataReply expected = new ReadDataReply(data, DataStoreVersions.CURRENT_VERSION);
38
39         Object serialized = expected.toSerializable();
40         assertEquals("Serialized type", ReadDataReply.class, serialized.getClass());
41
42         ReadDataReply actual = ReadDataReply.fromSerializable(SerializationUtils.clone(
43                 (Serializable) serialized));
44         assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
45         assertEquals("getNormalizedNode", expected.getNormalizedNode(), actual.getNormalizedNode());
46     }
47
48     @Test
49     public void testIsSerializedType() {
50         assertTrue("isSerializedType", ReadDataReply.isSerializedType(new ReadDataReply()));
51         assertFalse("isSerializedType", ReadDataReply.isSerializedType(new Object()));
52     }
53 }