X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-protocolbuffer-encoding%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotobuff%2Fmessages%2Ftransaction%2FShardTransactionMessagesTest.java;h=6b538dab0da711250ab867e00a7ca42f80d45395;hb=cc6c063be5f143cd601208ef26604d90a25bd1a5;hp=2b1ee5630c0c0665cc7a25f9a7b89630d9e4ff9c;hpb=17d82f582a6bc13c78be3b19954ff8c021180e93;p=controller.git diff --git a/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/protobuff/messages/transaction/ShardTransactionMessagesTest.java b/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/protobuff/messages/transaction/ShardTransactionMessagesTest.java index 2b1ee5630c..6b538dab0d 100644 --- a/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/protobuff/messages/transaction/ShardTransactionMessagesTest.java +++ b/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/protobuff/messages/transaction/ShardTransactionMessagesTest.java @@ -1,10 +1,85 @@ +/* + * + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + */ + package org.opendaylight.controller.protobuff.messages.transaction; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.controller.protobuff.messages.AbstractMessagesTest; +import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages; +import org.opendaylight.yangtools.yang.common.QName; + /** + * This test case is present to ensure that if others have used proper version of protocol buffer + * for the ShardTransaction.proto messages + * + * If a different version of protocol buffer and there is change in serializaiton format + * this test would break as we are comparing with protocol buffer 2.5 generated + * serialized data. + * * @author: syedbahm - * Date: 7/7/14 + * */ -public class ShardTransactionMessagesTest { + + +public class ShardTransactionMessagesTest extends AbstractMessagesTest { + + private final String namespace = "urn:protobuff", revision = "2014-07-31", + localName = "test"; + + @Test + public void verifySerialization() throws Exception { + NormalizedNodeMessages.InstanceIdentifier.Builder instanceIdentifierBuilder = + NormalizedNodeMessages.InstanceIdentifier.newBuilder(); + NormalizedNodeMessages.PathArgument.Builder pathArgument = + NormalizedNodeMessages.PathArgument.newBuilder(); + pathArgument.setNodeType(NormalizedNodeMessages.QName.newBuilder() + .setValue(QName.create(namespace, revision, localName).toString()) + .build()); + pathArgument.setValue("test"); + instanceIdentifierBuilder.addArguments(pathArgument.build()); + ShardTransactionMessages.ReadData.Builder builder = + ShardTransactionMessages.ReadData.newBuilder(); + NormalizedNodeMessages.InstanceIdentifier expectedOne = + instanceIdentifierBuilder.build(); + builder.setInstanceIdentifierPathArguments(expectedOne); + + writeToFile((com.google.protobuf.GeneratedMessage.Builder) builder); + + // Here we will read the same and check we got back what we had saved + ShardTransactionMessages.ReadData readDataNew = + (ShardTransactionMessages.ReadData) readFromFile(ShardTransactionMessages.ReadData.PARSER); + + + Assert.assertEquals(expectedOne.getArgumentsCount(), readDataNew + .getInstanceIdentifierPathArguments().getArgumentsCount()); + Assert.assertEquals(expectedOne.getArguments(0), readDataNew + .getInstanceIdentifierPathArguments().getArguments(0)); + + + // the following will compare with the version we had shipped + ShardTransactionMessages.ReadData readDataOriginal = + (ShardTransactionMessages.ReadData) readFromTestDataFile(ShardTransactionMessages.ReadData.PARSER); + + + Assert.assertEquals(readDataNew.getInstanceIdentifierPathArguments() + .getArguments(0), readDataOriginal.getInstanceIdentifierPathArguments() + .getArguments(0)); + + } + + @Override + public String getTestFileName() { + return ShardTransactionMessagesTest.class.getSimpleName(); + } + }