3 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
11 package org.opendaylight.controller.protobuff.messages.shard;
14 * This test case is present to ensure that if others have used proper version of protocol buffer
15 * for the ShardManager.proto messages
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
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.opendaylight.controller.protobuff.messages.AbstractMessagesTest;
29 public class ShardManagerMessagesTest extends AbstractMessagesTest {
32 public void verifySerialization() throws Exception {
33 ShardManagerMessages.FindPrimary.Builder builder =
34 ShardManagerMessages.FindPrimary.newBuilder();
35 builder.setShardName("Inventory");
37 writeToFile((com.google.protobuf.GeneratedMessage.Builder<?>) builder);
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);
44 Assert.assertEquals("Inventory", findPrimaryNew.getShardName());
46 // Here we compare with the version we had shipped to catch any protobuff compiler version
48 ShardManagerMessages.FindPrimary findPrimaryOriginal =
49 (ShardManagerMessages.FindPrimary) readFromTestDataFile(ShardManagerMessages.FindPrimary.PARSER);
51 Assert.assertEquals(findPrimaryNew.getShardName(),
52 findPrimaryOriginal.getShardName());
57 public String getTestFileName() {
58 return ShardManagerMessagesTest.class.getSimpleName();