X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2FNormalizedNodeToNodeCodecTest.java;h=0260ffb3159cf1f2dfe01246444b11f6f440a2e5;hp=c42865c659192e0584ebe93a147fee655ab284c4;hb=ecccb6d5b43dd73aef0d2d19349d19ee9b4728f7;hpb=0052eccf24fe02d693313cb68a1f6ee066211616 diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java index c42865c659..0260ffb315 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java @@ -1,21 +1,19 @@ /* + * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. * - * 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 - * + * 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.cluster.datastore.node; -import junit.framework.Assert; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeGetter; import org.opendaylight.controller.cluster.datastore.node.utils.NormalizedNodeNavigator; import org.opendaylight.controller.cluster.datastore.node.utils.PathUtils; +import org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeSerializer; import org.opendaylight.controller.cluster.datastore.util.TestModel; import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Container; import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Node; @@ -26,13 +24,11 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; import java.util.List; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class NormalizedNodeToNodeCodecTest { - - - private SchemaContext schemaContext; @Before @@ -41,7 +37,7 @@ public class NormalizedNodeToNodeCodecTest { assertNotNull("Schema context must not be null.", schemaContext); } - private YangInstanceIdentifier instanceIdentifierFromString(String s) { + private static YangInstanceIdentifier instanceIdentifierFromString(String s) { return PathUtils.toYangInstanceIdentifier(s); } @@ -59,7 +55,7 @@ public class NormalizedNodeToNodeCodecTest { PathUtils.toString(YangInstanceIdentifier.builder().build()), documentOne); // Validate the value of id can be retrieved from the normalized node - NormalizedNode output = normalizedNodeGetter.getOutput(); + NormalizedNode output = normalizedNodeGetter.getOutput(); assertNotNull(output); @@ -67,14 +63,12 @@ public class NormalizedNodeToNodeCodecTest { new NormalizedNodeToNodeCodec(schemaContext); long start = System.currentTimeMillis(); Container container = - codec.encode(instanceIdentifierFromString(id), output); + codec.encode(output); long end = System.currentTimeMillis(); System.out.println("Timetaken to encode :"+(end-start)); assertNotNull(container); - assertEquals(id, container.getParentPath() + "/" - + container.getNormalizedNode().getPath()); // Decode the normalized node from the ProtocolBuffer form // first get the node representation of normalized node @@ -82,7 +76,7 @@ public class NormalizedNodeToNodeCodecTest { start = System.currentTimeMillis(); NormalizedNode normalizedNode = - codec.decode(instanceIdentifierFromString(id), node); + codec.decode(node); end = System.currentTimeMillis(); System.out.println("Timetaken to decode :"+(end-start)); @@ -100,28 +94,18 @@ public class NormalizedNodeToNodeCodecTest { new NormalizedNodeToNodeCodec(schemaContext); Container container = - normalizedNodeToNodeCodec.encode(YangInstanceIdentifier.builder() - .build(), documentOne); + normalizedNodeToNodeCodec.encode(documentOne); final NormalizedNode decode = normalizedNodeToNodeCodec .decode( - instanceIdentifierFromString("/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test"), container.getNormalizedNode()); - assertNotNull(decode != null); + assertNotNull(decode); // let us ensure that the return decode normalized node encode returns same container Container containerResult = - normalizedNodeToNodeCodec.encode(YangInstanceIdentifier.builder() - .build(), decode); - - assertEquals(container.getParentPath(), containerResult.getParentPath()); - assertEquals(container.getNormalizedNode().getChildCount(), container - .getNormalizedNode().getChildCount()); - - Assert.assertEquals(containerResult.getNormalizedNode().getChildCount(), - container.getNormalizedNode().getChildCount()); + normalizedNodeToNodeCodec.encode(decode); // check first level children are proper List childrenResult = @@ -140,13 +124,22 @@ public class NormalizedNodeToNodeCodecTest { for (Node resultChild : childrenResult) { bFound = false; for (Node originalChild : childrenOriginal) { - if (originalChild.getPath().equals(resultChild.getPath()) - && resultChild.getType().equals(resultChild.getType())) { + + YangInstanceIdentifier.PathArgument result = NormalizedNodeSerializer.deSerialize( + containerResult.getNormalizedNode(), + resultChild.getPathArgument()); + + YangInstanceIdentifier.PathArgument original = NormalizedNodeSerializer.deSerialize( + container.getNormalizedNode(), + originalChild.getPathArgument()); + + if (original.equals(result) + && resultChild.getIntType() == resultChild.getIntType()) { bFound = true; break; } } - Assert.assertTrue(bFound); + assertTrue(bFound); } } @@ -165,11 +158,11 @@ public class NormalizedNodeToNodeCodecTest { NormalizedNodeToNodeCodec codec = new NormalizedNodeToNodeCodec(schemaContext); - Container encode = codec.encode(identifier, uno); + Container encode = codec.encode(uno); System.out.println(encode.getNormalizedNode()); - codec.decode(identifier, encode.getNormalizedNode()); + codec.decode(encode.getNormalizedNode()); } }