X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fnode%2FNormalizedNodeToNodeCodecTest.java;h=a9f9c722deefd942f3259fea3f05a929d42aa827;hb=refs%2Fchanges%2F68%2F10268%2F9;hp=bdad86ddc1e8fb5521607fbb91a575a99e677d38;hpb=c911a187bdcd6160c1929e53466cd9de681c2098;p=controller.git 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 bdad86ddc1..a9f9c722de 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 @@ -10,12 +10,12 @@ 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.NodeIdentifierFactory; 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; @@ -24,11 +24,11 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import java.util.ArrayList; import java.util.List; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class NormalizedNodeToNodeCodecTest { @@ -43,21 +43,9 @@ public class NormalizedNodeToNodeCodecTest { } private YangInstanceIdentifier instanceIdentifierFromString(String s) { - - String[] ids = s.split("/"); - - List pathArguments = new ArrayList<>(); - for (String nodeId : ids) { - if (!"".equals(nodeId)) { - pathArguments.add(NodeIdentifierFactory.getArgument(nodeId)); - } - } - final YangInstanceIdentifier instanceIdentifier = - YangInstanceIdentifier.create(pathArguments); - return instanceIdentifier; + return PathUtils.toYangInstanceIdentifier(s); } - @Test public void testNormalizeNodeAttributesToProtoBuffNode() { final NormalizedNode documentOne = TestModel.createTestContainer(); @@ -69,7 +57,7 @@ public class NormalizedNodeToNodeCodecTest { NormalizedNodeGetter normalizedNodeGetter = new NormalizedNodeGetter(id); new NormalizedNodeNavigator(normalizedNodeGetter).navigate( - YangInstanceIdentifier.builder().build().toString(), documentOne); + PathUtils.toString(YangInstanceIdentifier.builder().build()), documentOne); // Validate the value of id can be retrieved from the normalized node NormalizedNode output = normalizedNodeGetter.getOutput(); @@ -87,7 +75,8 @@ public class NormalizedNodeToNodeCodecTest { assertNotNull(container); assertEquals(id, container.getParentPath() + "/" - + container.getNormalizedNode().getPath()); + + NormalizedNodeSerializer.deSerialize(container.getNormalizedNode(), + container.getNormalizedNode().getPathArgument())); // Decode the normalized node from the ProtocolBuffer form // first get the node representation of normalized node @@ -122,7 +111,7 @@ public class NormalizedNodeToNodeCodecTest { .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 = @@ -130,10 +119,8 @@ public class NormalizedNodeToNodeCodecTest { .build(), decode); assertEquals(container.getParentPath(), containerResult.getParentPath()); - assertEquals(container.getNormalizedNode().getChildCount(), container - .getNormalizedNode().getChildCount()); - Assert.assertEquals(containerResult.getNormalizedNode().getChildCount(), + assertEquals(containerResult.getNormalizedNode().getChildCount(), container.getNormalizedNode().getChildCount()); // check first level children are proper @@ -153,13 +140,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); } }