Added test cases for each .proto file to ensure
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / src / test / java / org / opendaylight / controller / protobuff / messages / common / NormalizedNodeMessagesTest.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.common;
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 common.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 public class NormalizedNodeMessagesTest extends AbstractMessagesTest {
30
31   @Override
32   @Test
33   public void verifySerialization() throws Exception {
34     NormalizedNodeMessages.Attribute.Builder builder =
35         NormalizedNodeMessages.Attribute.newBuilder();
36     builder.setName("test");
37     builder.setType("fake");
38     builder.setValue("testValue");
39     writeToFile((com.google.protobuf.GeneratedMessage.Builder<?>) builder);
40
41     NormalizedNodeMessages.Attribute attributeNew =
42         (NormalizedNodeMessages.Attribute) readFromFile(NormalizedNodeMessages.Attribute.PARSER);
43     Assert.assertEquals("test", attributeNew.getName());
44     Assert.assertEquals("fake", attributeNew.getType());
45     Assert.assertEquals("testValue", attributeNew.getValue());
46
47     NormalizedNodeMessages.Attribute attributeOriginal =
48         (NormalizedNodeMessages.Attribute) readFromTestDataFile(NormalizedNodeMessages.Attribute.PARSER);
49     Assert.assertEquals(attributeNew.getName(), attributeOriginal.getName());
50   }
51
52   @Override
53   public String getTestFileName() {
54     return NormalizedNodeMessagesTest.class.getSimpleName();
55   }
56
57
58 }