628a661ce42e702f37e32f484992381083da1211
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / messages / CanCommitTransactionReplyTest.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
16 /**
17  * Unit tests for CanCommitTransactionReply.
18  *
19  * @author Thomas Pantelis
20  */
21 public class CanCommitTransactionReplyTest {
22
23     @Test
24     public void testSerialization() {
25         testSerialization(CanCommitTransactionReply.yes(DataStoreVersions.CURRENT_VERSION),
26                 CanCommitTransactionReply.class);
27         testSerialization(CanCommitTransactionReply.no(DataStoreVersions.CURRENT_VERSION),
28                 CanCommitTransactionReply.class);
29     }
30
31     private static void testSerialization(CanCommitTransactionReply expected, Class<?> expSerialized) {
32         Object serialized = expected.toSerializable();
33         assertEquals("Serialized type", expSerialized, serialized.getClass());
34
35         CanCommitTransactionReply actual = CanCommitTransactionReply.fromSerializable(
36                 SerializationUtils.clone((Serializable) serialized));
37         assertEquals("getCanCommit", expected.getCanCommit(), actual.getCanCommit());
38         assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, actual.getVersion());
39     }
40
41     @Test
42     public void testIsSerializedType() {
43         assertEquals("isSerializedType", true, CanCommitTransactionReply.isSerializedType(
44                 new CanCommitTransactionReply()));
45         assertEquals("isSerializedType", false, CanCommitTransactionReply.isSerializedType(new Object()));
46     }
47 }