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.persistent;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.controller.protobuff.messages.AbstractMessagesTest;
16 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
17 import org.opendaylight.yangtools.yang.common.QName;
21 * This test case is present to ensure that if others have used proper version of protocol buffer
22 * for the peristent.proto messages
24 * If a different version of protocol buffer and there is change in serializaiton format
25 * this test would break as we are comparing with protocol buffer 2.5 generated
32 public class PersistentMessagesTest extends AbstractMessagesTest {
34 private final String namespace = "urn:protobuff", revision = "2014-07-31",
39 public void verifySerialization() throws Exception {
40 NormalizedNodeMessages.InstanceIdentifier.Builder instanceIdentifierBuilder =
41 NormalizedNodeMessages.InstanceIdentifier.newBuilder();
42 NormalizedNodeMessages.PathArgument.Builder pathArgument =
43 NormalizedNodeMessages.PathArgument.newBuilder();
44 pathArgument.setNodeType(NormalizedNodeMessages.QName.newBuilder()
45 .setValue(QName.create(namespace, revision, localName).toString())
47 pathArgument.setValue("test");
48 instanceIdentifierBuilder.addArguments(pathArgument.build());
49 NormalizedNodeMessages.InstanceIdentifier expectedOne =
50 instanceIdentifierBuilder.build();
52 PersistentMessages.Modification.Builder builder =
53 PersistentMessages.Modification.newBuilder();
54 builder.setType("test");
55 builder.setPath(expectedOne);
57 writeToFile((com.google.protobuf.GeneratedMessage.Builder<?>) builder);
59 PersistentMessages.Modification modificationNew =
60 (PersistentMessages.Modification) readFromFile(PersistentMessages.Modification.PARSER);
61 Assert.assertEquals("test", modificationNew.getType());
62 Assert.assertEquals(expectedOne.getArguments(0).getValue(), modificationNew
63 .getPath().getArguments(0).getValue());
64 Assert.assertEquals(expectedOne.getArguments(0).getType(), modificationNew
65 .getPath().getArguments(0).getType());
67 // we will compare with the serialized data that we had shipped
68 PersistentMessages.Modification modificationOriginal =
69 (PersistentMessages.Modification) readFromTestDataFile(PersistentMessages.Modification.PARSER);
70 Assert.assertEquals(modificationOriginal.getPath().getArguments(0)
71 .getValue(), modificationNew.getPath().getArguments(0).getValue());
72 Assert.assertEquals(modificationOriginal.getPath().getArguments(0)
73 .getType(), modificationNew.getPath().getArguments(0).getType());
79 public String getTestFileName() {
80 return PersistentMessagesTest.class.getSimpleName();