45dcd12d0519317a37ae4c9e0ba82b43441fc71b
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / src / test / java / org / opendaylight / controller / protobuff / messages / shard / ShardManagerMessagesTest.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.shard;
12
13 /**
14  * This test case is present to ensure that if others have used proper version of protocol buffer
15  * for the ShardManager.proto messages
16  *
17  * If a different version of protocol buffer and there is change in serializaiton format
18  * this test would break as we are comparing with protocol buffer 2.5 generated
19  * serialized data.
20  *
21  * @author: syedbahm
22  *
23  */
24
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.opendaylight.controller.protobuff.messages.AbstractMessagesTest;
28
29 public class ShardManagerMessagesTest extends AbstractMessagesTest {
30
31   @Test
32   public void verifySerialization() throws Exception {
33     ShardManagerMessages.FindPrimary.Builder builder =
34         ShardManagerMessages.FindPrimary.newBuilder();
35     builder.setShardName("Inventory");
36
37     writeToFile((com.google.protobuf.GeneratedMessage.Builder<?>) builder);
38
39
40     // Here we will read the same and check we got back what we had saved
41     ShardManagerMessages.FindPrimary findPrimaryNew =
42         (ShardManagerMessages.FindPrimary) readFromFile(ShardManagerMessages.FindPrimary.PARSER);
43
44     Assert.assertEquals("Inventory", findPrimaryNew.getShardName());
45
46     // Here we compare with the version we had shipped to catch any protobuff compiler version
47     // changes
48     ShardManagerMessages.FindPrimary findPrimaryOriginal =
49         (ShardManagerMessages.FindPrimary) readFromTestDataFile(ShardManagerMessages.FindPrimary.PARSER);
50
51     Assert.assertEquals(findPrimaryNew.getShardName(),
52         findPrimaryOriginal.getShardName());
53
54   }
55
56   @Override
57   public String getTestFileName() {
58     return ShardManagerMessagesTest.class.getSimpleName();
59   }
60
61 }