Merge "Removing { } from NormalizedNodeJsonBodyWriter"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / messages / DeleteDataTest.java
1 /*
2  * Copyright (c) 2015 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 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.common.NormalizedNodeMessages.InstanceIdentifier;
17 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19
20 /**
21  * Unit tests for DeleteData.
22  *
23  * @author Thomas Pantelis
24  */
25 @Deprecated
26 public class DeleteDataTest {
27
28     @Test
29     public void testSerialization() {
30         YangInstanceIdentifier path = TestModel.TEST_PATH;
31
32         DeleteData expected = new DeleteData(path, DataStoreVersions.CURRENT_VERSION);
33
34         Object serialized = expected.toSerializable();
35         assertEquals("Serialized type", DeleteData.class, serialized.getClass());
36         assertEquals("Version", DataStoreVersions.CURRENT_VERSION, ((DeleteData)serialized).getVersion());
37
38         Object clone = SerializationUtils.clone((Serializable) serialized);
39         DeleteData actual = DeleteData.fromSerializable(clone);
40         assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
41         assertEquals("getPath", expected.getPath(), actual.getPath());
42     }
43
44     @Test
45     public void testIsSerializedType() {
46         assertEquals("isSerializedType", true, DeleteData.isSerializedType(
47                 ShardTransactionMessages.DeleteData.newBuilder()
48                     .setInstanceIdentifierPathArguments(InstanceIdentifier.getDefaultInstance()).build()));
49         assertEquals("isSerializedType", true,
50                 DeleteData.isSerializedType(new DeleteData()));
51         assertEquals("isSerializedType", false, DeleteData.isSerializedType(new Object()));
52     }
53
54     /**
55      * Tests backwards compatible serialization/deserialization of a DeleteData message with the
56      * base and R1 Helium versions, which used the protobuff DeleteData message.
57      */
58     @Test
59     public void testSerializationWithHeliumR1Version() throws Exception {
60         YangInstanceIdentifier path = TestModel.TEST_PATH;
61
62         DeleteData expected = new DeleteData(path, DataStoreVersions.HELIUM_1_VERSION);
63
64         Object serialized = expected.toSerializable();
65         assertEquals("Serialized type", ShardTransactionMessages.DeleteData.class, serialized.getClass());
66
67         DeleteData actual = DeleteData.fromSerializable(SerializationUtils.clone((Serializable) serialized));
68         assertEquals("getPath", expected.getPath(), actual.getPath());
69     }
70 }