Deprecate 3PC protobuff messages
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / messages / CommitTransactionReplyTest.java
1 /*
2  * Copyright (c) 2016 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.protobuff.messages.cohort3pc.ThreePhaseCommitCohortMessages;
16
17 /**
18  * Unit tests for CommitTransactionReply.
19  *
20  * @author Thomas Pantelis
21  */
22 public class CommitTransactionReplyTest {
23
24     @Test
25     public void testSerialization() {
26         CommitTransactionReply expected = CommitTransactionReply.instance(DataStoreVersions.CURRENT_VERSION);
27
28         Object serialized = expected.toSerializable();
29         assertEquals("Serialized type", CommitTransactionReply.class, serialized.getClass());
30
31         CommitTransactionReply actual = (CommitTransactionReply)SerializationUtils.clone((Serializable) serialized);
32         assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
33     }
34
35     @Test
36     public void testSerializationWithPreBoronVersion() {
37         CommitTransactionReply expected = CommitTransactionReply.instance(DataStoreVersions.LITHIUM_VERSION);
38
39         Object serialized = expected.toSerializable();
40         assertEquals("Serialized type", ThreePhaseCommitCohortMessages.CommitTransactionReply.class, serialized.getClass());
41     }
42
43     @Test
44     public void testIsSerializedType() {
45         assertEquals("isSerializedType", true, CommitTransactionReply.isSerializedType(
46                 ThreePhaseCommitCohortMessages.CommitTransactionReply.newBuilder().build()));
47
48         assertEquals("isSerializedType", true, CommitTransactionReply.isSerializedType(new CommitTransactionReply()));
49         assertEquals("isSerializedType", false, CommitTransactionReply.isSerializedType(new Object()));
50     }
51 }