Merge "BUG 1082 Migrate sal-rest-connector to Async Data Broker API"
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / src / test / java / org / opendaylight / controller / protobuff / messages / cohort3pc / ThreePhaseCommitCohortMessagesTest.java
1 /*
2  *
3  *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  *  This program and the accompanying materials are made available under the
6  *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  */
10
11 package org.opendaylight.controller.protobuff.messages.cohort3pc;
12
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.controller.protobuff.messages.AbstractMessagesTest;
16
17 /**
18  * This test case is present to ensure that if others have used proper version of protocol buffer
19  * for the cohort.proto messages
20  *
21  * If a different version of protocol buffer and there is change in serializaiton format
22  * this test would break as we are comparing with protocol buffer 2.5 generated
23  * serialized data.
24  *
25  * @author: syedbahm
26  *
27  */
28
29
30 public class ThreePhaseCommitCohortMessagesTest extends AbstractMessagesTest {
31
32
33   @Test
34   public void verifySerialization() throws Exception {
35
36
37
38     ThreePhaseCommitCohortMessages.CanCommitTransactionReply.Builder builder =
39         ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder();
40     builder.setCanCommit(true);
41
42     writeToFile((com.google.protobuf.GeneratedMessage.Builder<?>) builder);
43
44     // Here we will read from the just serialized data
45
46     ThreePhaseCommitCohortMessages.CanCommitTransactionReply newCanCommitTransactionReply =
47         (ThreePhaseCommitCohortMessages.CanCommitTransactionReply) readFromFile(ThreePhaseCommitCohortMessages.CanCommitTransactionReply.PARSER);
48
49     Assert.assertTrue(newCanCommitTransactionReply.getCanCommit());
50
51
52     // Here we will read the same from our test-data file and check we got back what we had saved
53     // earlier
54     ThreePhaseCommitCohortMessages.CanCommitTransactionReply originalCanCommitTransactionReply =
55         (ThreePhaseCommitCohortMessages.CanCommitTransactionReply) readFromTestDataFile(ThreePhaseCommitCohortMessages.CanCommitTransactionReply.PARSER);
56
57     Assert.assertEquals(newCanCommitTransactionReply.getCanCommit(),
58         originalCanCommitTransactionReply.getCanCommit());
59
60   }
61
62   @Override
63   public String getTestFileName() {
64     return ThreePhaseCommitCohortMessagesTest.class.getSimpleName();
65   }
66
67
68 }