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%2Fcluster%2Fdatastore%2Fnode%2FNormalizedNodeToNodeCodecTest.java;h=4ccbc97f351721e08897cee463829d4cf09c451c;hb=83140d53722ad77dd804f7b4d761a673110b83b3;hp=9aea7a65714e0d8b3ceee8fb6ddd3f9581b5721d;hpb=9340a64d067473032111bd8c3341ea6855cd9e4a;p=controller.git diff --git a/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java b/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java index 9aea7a6571..4ccbc97f35 100644 --- a/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java +++ b/opendaylight/md-sal/sal-protocolbuffer-encoding/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java @@ -11,13 +11,14 @@ package org.opendaylight.controller.cluster.datastore.node; import junit.framework.Assert; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Container; -import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Node; 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.util.TestModel; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Container; +import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Node; +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; @@ -39,17 +40,17 @@ public class NormalizedNodeToNodeCodecTest { assertNotNull("Schema context must not be null.", schemaContext); } - private InstanceIdentifier instanceIdentifierFromString(String s){ + private YangInstanceIdentifier instanceIdentifierFromString(String s){ String[] ids = s.split("/"); - List pathArguments = new ArrayList<>(); + List pathArguments = new ArrayList<>(); for(String nodeId : ids){ if(!"".equals(nodeId)) { pathArguments.add(NodeIdentifierFactory.getArgument(nodeId)); } } - final InstanceIdentifier instanceIdentifier = InstanceIdentifier.create(pathArguments); + final YangInstanceIdentifier instanceIdentifier = YangInstanceIdentifier.create(pathArguments); return instanceIdentifier; } @@ -57,11 +58,14 @@ public class NormalizedNodeToNodeCodecTest { @Test public void testNormalizeNodeAttributesToProtoBuffNode(){ final NormalizedNode documentOne = TestModel.createTestContainer(); - String id = "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)outer-list/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)outer-list[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=2}]/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id"; + String id = "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test" + + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)outer-list" + + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)outer-list[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=2}]" + + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id"; NormalizedNodeGetter normalizedNodeGetter = new NormalizedNodeGetter(id); new NormalizedNodeNavigator(normalizedNodeGetter).navigate( - InstanceIdentifier.builder().build().toString(), documentOne); + YangInstanceIdentifier.builder().build().toString(), documentOne); // Validate the value of id can be retrieved from the normalized node NormalizedNode output = normalizedNodeGetter.getOutput(); @@ -87,17 +91,16 @@ public class NormalizedNodeToNodeCodecTest { public void testThatANormalizedNodeToProtoBuffNodeEncodeDecode() throws Exception { final NormalizedNode documentOne = TestModel.createTestContainer(); - final NormalizedNodeToNodeCodec normalizedNodeToNodeCodec = new NormalizedNodeToNodeCodec(schemaContext); - Container container = normalizedNodeToNodeCodec.encode(InstanceIdentifier.builder().build(), documentOne); + Container container = normalizedNodeToNodeCodec.encode(YangInstanceIdentifier.builder().build(), 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); //let us ensure that the return decode normalized node encode returns same container - Container containerResult = normalizedNodeToNodeCodec.encode(InstanceIdentifier.builder().build(), decode); + Container containerResult = normalizedNodeToNodeCodec.encode(YangInstanceIdentifier.builder().build(), decode); assertEquals(container.getParentPath(),containerResult.getParentPath()); assertEquals(container.getNormalizedNode().getChildCount(),container.getNormalizedNode().getChildCount()); @@ -107,6 +110,15 @@ public class NormalizedNodeToNodeCodecTest { //check first level children are proper ListchildrenResult = containerResult.getNormalizedNode().getChildList(); ListchildrenOriginal = container.getNormalizedNode().getChildList(); + + System.out.println("-------------------------------------------------"); + + System.out.println(childrenOriginal.toString()); + + System.out.println("-------------------------------------------------"); + + System.out.println(childrenResult.toString()); + boolean bFound; for(Node resultChild: childrenResult){ bFound = false; @@ -120,7 +132,27 @@ public class NormalizedNodeToNodeCodecTest { Assert.assertTrue(bFound); } + } + + @Test + public void addAugmentations(){ + String stringId = "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test" + + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)augmented-list" + + "/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)augmented-list[{(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)id=1}]"; + + YangInstanceIdentifier identifier = instanceIdentifierFromString(stringId); + + MapEntryNode uno = TestModel.createAugmentedListEntry(1, "Uno"); + + NormalizedNodeToNodeCodec codec = + new NormalizedNodeToNodeCodec(schemaContext); + + Container encode = codec + .encode(identifier, uno); + + System.out.println(encode.getNormalizedNode()); + codec.decode(identifier, encode.getNormalizedNode()); } }