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=1b85d46fc6ebdfa9b13de079db728b9dadf2beac;hb=eb887b1c2c8cd2768f8b4c2ed2b5054f97798466;hp=4ccbc97f351721e08897cee463829d4cf09c451c;hpb=0eb621d29daaf08979c356e2148e99c48458e169;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 4ccbc97f35..1b85d46fc6 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 @@ -1,9 +1,11 @@ /* - * 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 + * 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.cluster.datastore.node; @@ -15,9 +17,9 @@ import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFa 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.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.YangInstanceIdentifier; 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; @@ -32,127 +34,147 @@ public class NormalizedNodeToNodeCodecTest { - private SchemaContext schemaContext; + private SchemaContext schemaContext; - @Before - public void setUp(){ - schemaContext = TestModel.createTestContext(); - assertNotNull("Schema context must not be null.", schemaContext); - } + @Before + public void setUp() { + schemaContext = TestModel.createTestContext(); + assertNotNull("Schema context must not be null.", schemaContext); + } - private YangInstanceIdentifier instanceIdentifierFromString(String s){ + private YangInstanceIdentifier instanceIdentifierFromString(String s) { - String[] ids = s.split("/"); + 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; + List pathArguments = new ArrayList<>(); + for (String nodeId : ids) { + if (!"".equals(nodeId)) { + pathArguments.add(NodeIdentifierFactory.getArgument(nodeId)); + } } + final YangInstanceIdentifier instanceIdentifier = + YangInstanceIdentifier.create(pathArguments); + return instanceIdentifier; + } - @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"; + @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"; - NormalizedNodeGetter normalizedNodeGetter = new NormalizedNodeGetter(id); - new NormalizedNodeNavigator(normalizedNodeGetter).navigate( - YangInstanceIdentifier.builder().build().toString(), documentOne); + NormalizedNodeGetter normalizedNodeGetter = new NormalizedNodeGetter(id); + new NormalizedNodeNavigator(normalizedNodeGetter).navigate( + YangInstanceIdentifier.builder().build().toString(), documentOne); - // Validate the value of id can be retrieved from the normalized node - NormalizedNode output = normalizedNodeGetter.getOutput(); - assertNotNull(output); + // Validate the value of id can be retrieved from the normalized node + NormalizedNode output = normalizedNodeGetter.getOutput(); + assertNotNull(output); - NormalizedNodeToNodeCodec codec = new NormalizedNodeToNodeCodec(schemaContext); - Container container = codec.encode(instanceIdentifierFromString(id),output); + NormalizedNodeToNodeCodec codec = + new NormalizedNodeToNodeCodec(schemaContext); + Container container = + codec.encode(instanceIdentifierFromString(id), output); - assertNotNull(container); - assertEquals(id, container.getParentPath()+"/"+container.getNormalizedNode().getPath()) ; + 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 - final Node node = container.getNormalizedNode(); + // Decode the normalized node from the ProtocolBuffer form + // first get the node representation of normalized node + final Node node = container.getNormalizedNode(); - NormalizedNode normalizedNode = codec.decode(instanceIdentifierFromString(id),node); + NormalizedNode normalizedNode = + codec.decode(instanceIdentifierFromString(id), node); - assertEquals(normalizedNode.getValue().toString(),output.getValue().toString()); - } + assertEquals(normalizedNode.getValue().toString(), output.getValue() + .toString()); + } - @Test - public void testThatANormalizedNodeToProtoBuffNodeEncodeDecode() throws Exception { - final NormalizedNode documentOne = TestModel.createTestContainer(); + @Test + public void testThatANormalizedNodeToProtoBuffNodeEncodeDecode() + throws Exception { + final NormalizedNode documentOne = TestModel.createTestContainer(); - final NormalizedNodeToNodeCodec normalizedNodeToNodeCodec = new NormalizedNodeToNodeCodec(schemaContext); + final NormalizedNodeToNodeCodec normalizedNodeToNodeCodec = + new NormalizedNodeToNodeCodec(schemaContext); - Container container = normalizedNodeToNodeCodec.encode(YangInstanceIdentifier.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); + 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(YangInstanceIdentifier.builder().build(), 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()); + assertEquals(container.getParentPath(), containerResult.getParentPath()); + assertEquals(container.getNormalizedNode().getChildCount(), container + .getNormalizedNode().getChildCount()); - Assert.assertEquals(containerResult.getNormalizedNode().getChildCount(),container.getNormalizedNode().getChildCount()); + Assert.assertEquals(containerResult.getNormalizedNode().getChildCount(), + container.getNormalizedNode().getChildCount()); - //check first level children are proper - ListchildrenResult = containerResult.getNormalizedNode().getChildList(); - ListchildrenOriginal = container.getNormalizedNode().getChildList(); + // check first level children are proper + List childrenResult = + containerResult.getNormalizedNode().getChildList(); + List childrenOriginal = container.getNormalizedNode().getChildList(); - System.out.println("-------------------------------------------------"); + System.out.println("-------------------------------------------------"); - System.out.println(childrenOriginal.toString()); + System.out.println(childrenOriginal.toString()); - System.out.println("-------------------------------------------------"); + System.out.println("-------------------------------------------------"); - System.out.println(childrenResult.toString()); + System.out.println(childrenResult.toString()); - boolean bFound; - for(Node resultChild: childrenResult){ - bFound = false; - for(Node originalChild:childrenOriginal){ - if(originalChild.getPath().equals(resultChild.getPath()) - && resultChild.getType().equals(resultChild.getType())){ - bFound=true; - break; - } - } - Assert.assertTrue(bFound); + boolean bFound; + for (Node resultChild : childrenResult) { + bFound = false; + for (Node originalChild : childrenOriginal) { + if (originalChild.getPath().equals(resultChild.getPath()) + && resultChild.getType().equals(resultChild.getType())) { + bFound = true; + break; } - + } + 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); + @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}]"; - MapEntryNode uno = TestModel.createAugmentedListEntry(1, "Uno"); + YangInstanceIdentifier identifier = instanceIdentifierFromString(stringId); - NormalizedNodeToNodeCodec codec = - new NormalizedNodeToNodeCodec(schemaContext); + MapEntryNode uno = TestModel.createAugmentedListEntry(1, "Uno"); - Container encode = codec - .encode(identifier, uno); + NormalizedNodeToNodeCodec codec = + new NormalizedNodeToNodeCodec(schemaContext); - System.out.println(encode.getNormalizedNode()); + Container encode = codec.encode(identifier, uno); - codec.decode(identifier, encode.getNormalizedNode()); - } + System.out.println(encode.getNormalizedNode()); + + codec.decode(identifier, encode.getNormalizedNode()); + } }