Remove deprecated PreLithium Tx context classes and related code
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / messages / MergeDataTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco 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
9 package org.opendaylight.controller.cluster.datastore.messages;
10
11 import static org.junit.Assert.assertEquals;
12 import java.io.Serializable;
13 import org.apache.commons.lang.SerializationUtils;
14 import org.junit.Test;
15 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
16 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
17 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.InstanceIdentifier;
18 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Node;
19 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
23 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
24
25 @Deprecated
26 public class MergeDataTest {
27
28     @Test
29     public void testSerialization() {
30         YangInstanceIdentifier path = TestModel.TEST_PATH;
31         NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
32                 new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
33                 withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
34
35         MergeData expected = new MergeData(path, data, DataStoreVersions.CURRENT_VERSION);
36
37         Object serialized = expected.toSerializable();
38         assertEquals("Serialized type", MergeData.class, serialized.getClass());
39         assertEquals("Version", DataStoreVersions.CURRENT_VERSION, ((MergeData)serialized).getVersion());
40
41         Object clone = SerializationUtils.clone((Serializable) serialized);
42         MergeData actual = MergeData.fromSerializable(clone);
43         assertEquals("Version", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
44         assertEquals("getPath", expected.getPath(), actual.getPath());
45         assertEquals("getData", expected.getData(), actual.getData());
46     }
47
48     @Test
49     public void testIsSerializedType() {
50         assertEquals("isSerializedType", true, MergeData.isSerializedType(
51                 ShardTransactionMessages.MergeData.newBuilder()
52                     .setInstanceIdentifierPathArguments(InstanceIdentifier.getDefaultInstance())
53                     .setNormalizedNode(Node.getDefaultInstance()).build()));
54         assertEquals("isSerializedType", true,
55                 MergeData.isSerializedType(new MergeData()));
56         assertEquals("isSerializedType", false, MergeData.isSerializedType(new Object()));
57     }
58
59     /**
60      * Tests backwards compatible serialization/deserialization of a MergeData message with the
61      * base and R1 Helium versions, which used the protobuff MergeData message.
62      */
63     @Test
64     public void testSerializationWithHeliumR1Version() throws Exception {
65         YangInstanceIdentifier path = TestModel.TEST_PATH;
66         NormalizedNode<?, ?> data = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
67                 new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
68                 withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
69
70         MergeData expected = new MergeData(path, data, DataStoreVersions.HELIUM_1_VERSION);
71
72         Object serialized = expected.toSerializable();
73         assertEquals("Serialized type", ShardTransactionMessages.MergeData.class, serialized.getClass());
74
75         MergeData actual = MergeData.fromSerializable(SerializationUtils.clone((Serializable) serialized));
76         assertEquals("getPath", expected.getPath(), actual.getPath());
77         assertEquals("getData", expected.getData(), actual.getData());
78     }
79 }