X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Fjson%2Fto%2Fcnsn%2Ftest%2FJsonToCnSnTest.java;h=415d58e53d3f43684aaca2edfde78eee91a033ca;hp=f2c0c29bc4372b6b54eeec0dc3bf9d9805f36663;hb=290b7c23512204074fcd0fb7163b0adea48823fd;hpb=34c82598f1a898798e5b6dfcad5186889d58dc6c diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonToCnSnTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonToCnSnTest.java index f2c0c29bc4..415d58e53d 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonToCnSnTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/json/to/cnsn/test/JsonToCnSnTest.java @@ -1,6 +1,14 @@ +/* + * 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.sal.restconf.impl.json.to.cnsn.test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -10,6 +18,7 @@ import java.util.Set; import javax.ws.rs.WebApplicationException; +import org.junit.Ignore; import org.junit.Test; import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider; import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper; @@ -49,13 +58,13 @@ public class JsonToCnSnTest { CompositeNode compositeNode = TestUtils.readInputToCnSn("/json-to-cnsn/multiple-leaflist-items.json", true, JsonToCompositeNodeProvider.INSTANCE); assertNotNull(compositeNode); - assertEquals(3, compositeNode.getChildren().size()); + assertEquals(3, compositeNode.getValue().size()); boolean lflst1_1 = false; boolean lflst1_2 = false; boolean lflst1_3 = false; - for (Node node : compositeNode.getChildren()) { + for (Node node : compositeNode.getValue()) { assertEquals("lflst1", node.getNodeType().getLocalName()); assertTrue(node instanceof SimpleNode); SimpleNode simpleNode = (SimpleNode) node; @@ -96,9 +105,9 @@ public class JsonToCnSnTest { assertNotNull(compositeNode); assertEquals("cont", compositeNode.getNodeType().getLocalName()); - assertNotNull(compositeNode.getChildren()); - assertEquals(1, compositeNode.getChildren().size()); - Node lfNode = compositeNode.getChildren().iterator().next(); + assertNotNull(compositeNode.getValue()); + assertEquals(1, compositeNode.getValue().size()); + Node lfNode = compositeNode.getValue().iterator().next(); assertTrue(lfNode instanceof SimpleNode); assertEquals(null, ((SimpleNode) lfNode).getValue()); @@ -110,7 +119,7 @@ public class JsonToCnSnTest { Throwable cause1 = null; try { TestUtils - .readInputToCnSn("/json-to-cnsn/wrong-top-level1.json", true, JsonToCompositeNodeProvider.INSTANCE); + .readInputToCnSn("/json-to-cnsn/wrong-top-level1.json", true, JsonToCompositeNodeProvider.INSTANCE); } catch (WebApplicationException e) { cause1 = e; } @@ -125,7 +134,7 @@ public class JsonToCnSnTest { Throwable cause2 = null; try { TestUtils - .readInputToCnSn("/json-to-cnsn/wrong-top-level2.json", true, JsonToCompositeNodeProvider.INSTANCE); + .readInputToCnSn("/json-to-cnsn/wrong-top-level2.json", true, JsonToCompositeNodeProvider.INSTANCE); } catch (WebApplicationException e) { cause2 = e; } @@ -135,7 +144,7 @@ public class JsonToCnSnTest { Throwable cause3 = null; try { TestUtils - .readInputToCnSn("/json-to-cnsn/wrong-top-level3.json", true, JsonToCompositeNodeProvider.INSTANCE); + .readInputToCnSn("/json-to-cnsn/wrong-top-level3.json", true, JsonToCompositeNodeProvider.INSTANCE); } catch (WebApplicationException e) { cause3 = e; } @@ -161,7 +170,7 @@ public class JsonToCnSnTest { assertEquals("cont", compositeNode.getNodeType().getLocalName()); assertTrue(compositeNode instanceof CompositeNode); - List> children = ((CompositeNode) compositeNode).getChildren(); + List> children = compositeNode.getValue(); assertEquals(1, children.size()); assertEquals("lflst2", children.get(0).getNodeType().getLocalName()); assertEquals("45", children.get(0).getValue()); @@ -181,7 +190,7 @@ public class JsonToCnSnTest { * Tests whether namespace stay unchanged if concrete values are * present in composite or simple node and if the method for update is * called. - * + * */ @Test public void notSupplyNamespaceIfAlreadySupplied() { @@ -207,15 +216,8 @@ public class JsonToCnSnTest { assertEquals("lst", compNode.getNodeType().getLocalName()); verifyCompositeNode(compNode, "simple:list:yang1"); - String exceptionMessage = ""; - try { - TestUtils.normalizeCompositeNode(compositeNode, modules2, "simple-list-yang2:lst"); - } catch (ResponseException e) { - exceptionMessage = String.valueOf(e.getResponse().getEntity()); - } - assertTrue(exceptionMessage - .contains("Data has bad format\nIf data is in XML format then namespace for lst should be simple:list:yang2.\n If data is in Json format then module name for lst should be simple-list-yang2.")); - + TestUtils.normalizeCompositeNode(compositeNode, modules2, "simple-list-yang2:lst"); + verifyCompositeNode(compNode, "simple:list:yang1"); } @Test @@ -231,13 +233,13 @@ public class JsonToCnSnTest { assertEquals("cont", compositeNode.getNodeType().getLocalName()); - List> childs = compositeNode.getChildren(); + List> childs = compositeNode.getValue(); assertEquals(1, childs.size()); Node nd = childs.iterator().next(); assertTrue(nd instanceof CompositeNode); assertEquals("cont1", nd.getNodeType().getLocalName()); - childs = ((CompositeNode) nd).getChildren(); + childs = ((CompositeNode) nd).getValue(); assertEquals(4, childs.size()); SimpleNode lf11 = null; SimpleNode lf12 = null; @@ -273,8 +275,27 @@ public class JsonToCnSnTest { assertEquals("identity:module", ((QName) lf14.getValue()).getNamespace().toString()); } - private void simpleTest(String jsonPath, String yangPath, String topLevelElementName, String namespace, - String moduleName) { + @Ignore + @Test + public void loadDataAugmentedSchemaMoreEqualNamesTest() { + boolean exceptionCaught = false; + try { + loadAndNormalizeData("/common/augment/json/dataa.json", "/common/augment/yang", "cont", "main"); + loadAndNormalizeData("/common/augment/json/datab.json", "/common/augment/yang", "cont", "main"); + } catch (ResponseException e) { + exceptionCaught = true; + } + + assertFalse(exceptionCaught); + } + + private void simpleTest(final String jsonPath, final String yangPath, final String topLevelElementName, final String namespace, + final String moduleName) { + CompositeNode compNode = loadAndNormalizeData(jsonPath, yangPath, topLevelElementName, moduleName); + verifyCompositeNode(compNode, namespace); + } + + private CompositeNode loadAndNormalizeData(final String jsonPath, final String yangPath, final String topLevelElementName, final String moduleName) { CompositeNode compositeNode = TestUtils.readInputToCnSn(jsonPath, false, JsonToCompositeNodeProvider.INSTANCE); assertNotNull(compositeNode); @@ -288,11 +309,11 @@ public class JsonToCnSnTest { CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap(); assertEquals(topLevelElementName, compNode.getNodeType().getLocalName()); - verifyCompositeNode(compNode, namespace); + return compNode; } - private void verityMultipleItemsInList(CompositeNode compositeNode) { - List> childrenNodes = compositeNode.getChildren(); + private void verityMultipleItemsInList(final CompositeNode compositeNode) { + List> childrenNodes = compositeNode.getValue(); assertEquals(4, childrenNodes.size()); boolean lf11Found = false; boolean cont11Found = false; @@ -301,7 +322,7 @@ public class JsonToCnSnTest { assertEquals("lst1", lst1Item.getNodeType().getLocalName()); assertTrue(lst1Item instanceof CompositeNode); - List> childrenLst1 = ((CompositeNode) lst1Item).getChildren(); + List> childrenLst1 = ((CompositeNode) lst1Item).getValue(); assertEquals(1, childrenLst1.size()); String localName = childrenLst1.get(0).getNodeType().getLocalName(); if (localName.equals("lf11")) { @@ -317,7 +338,7 @@ public class JsonToCnSnTest { } else if (localName.equals("lst11")) { lst11Found = true; assertTrue(childrenLst1.get(0) instanceof CompositeNode); - assertEquals(0, ((CompositeNode) childrenLst1.get(0)).getChildren().size()); + assertEquals(0, ((CompositeNode) childrenLst1.get(0)).getValue().size()); } } @@ -326,7 +347,7 @@ public class JsonToCnSnTest { assertTrue(lst11Found); } - private void verifyCompositeNode(CompositeNode compositeNode, String namespace) { + private void verifyCompositeNode(final CompositeNode compositeNode, final String namespace) { boolean cont1Found = false; boolean lst1Found = false; boolean lflst1_1Found = false; @@ -336,16 +357,16 @@ public class JsonToCnSnTest { // assertEquals(namespace, // compositeNode.getNodeType().getNamespace().toString()); - for (Node node : compositeNode.getChildren()) { + for (Node node : compositeNode.getValue()) { if (node.getNodeType().getLocalName().equals("cont1")) { if (node instanceof CompositeNode) { cont1Found = true; - assertEquals(0, ((CompositeNode) node).getChildren().size()); + assertEquals(0, ((CompositeNode) node).getValue().size()); } } else if (node.getNodeType().getLocalName().equals("lst1")) { if (node instanceof CompositeNode) { lst1Found = true; - assertEquals(0, ((CompositeNode) node).getChildren().size()); + assertEquals(0, ((CompositeNode) node).getValue().size()); } } else if (node.getNodeType().getLocalName().equals("lflst1")) { if (node instanceof SimpleNode) {