X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Fjson%2Fto%2Fcnsn%2Ftest%2FJsonToCnSnTest.java;h=8b1dc3475f6f9f986c61658124942e7f1804d234;hb=d3e6c92c1f8bf92d60c4a0ec2ee8fc734806ff5d;hp=e7421a17764fe0ecbb442b288be618ccd009eadb;hpb=6eb461f54fe6705b07f34b6cee197ea968de4991;p=controller.git 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 e7421a1776..8b1dc3475f 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,20 +1,33 @@ +/* + * 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.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; -import java.io.FileNotFoundException; -import java.util.*; +import java.util.HashSet; +import java.util.List; +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; import org.opendaylight.controller.sal.restconf.impl.ResponseException; import org.opendaylight.controller.sal.restconf.impl.test.TestUtils; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.*; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.Node; +import org.opendaylight.yangtools.yang.data.api.SimpleNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -190,11 +203,8 @@ public class JsonToCnSnTest { // "simple:data:types1" Set modules1 = new HashSet<>(); Set modules2 = new HashSet<>(); - try { - modules1 = TestUtils.loadModules(TestUtils.class.getResource("/json-to-cnsn/simple-list-yang/1").getPath()); - modules2 = TestUtils.loadModules(TestUtils.class.getResource("/json-to-cnsn/simple-list-yang/2").getPath()); - } catch (FileNotFoundException e) { - } + modules1 = TestUtils.loadModulesFrom("/json-to-cnsn/simple-list-yang/1"); + modules2 = TestUtils.loadModulesFrom("/json-to-cnsn/simple-list-yang/2"); assertNotNull(modules1); assertNotNull(modules2); @@ -206,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 @@ -223,12 +226,8 @@ public class JsonToCnSnTest { JsonToCompositeNodeProvider.INSTANCE); assertNotNull(compositeNode); - Set modules = TestUtils.resolveModulesFrom("/json-to-cnsn/identityref"); + Set modules = TestUtils.loadModulesFrom("/json-to-cnsn/identityref"); assertEquals(2, modules.size()); - Module module = TestUtils.resolveModule("identityref-module", modules); - assertNotNull(module); - DataSchemaNode dataSchemaNode = TestUtils.resolveDataSchemaNode(null, module); - assertNotNull(dataSchemaNode); TestUtils.normalizeCompositeNode(compositeNode, modules, "identityref-module:cont"); @@ -275,29 +274,42 @@ public class JsonToCnSnTest { assertEquals("iden_local", ((QName) lf14.getValue()).getLocalName()); assertEquals("identity:module", ((QName) lf14.getValue()).getNamespace().toString()); } + + @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(String jsonPath, String yangPath, String topLevelElementName, String namespace, String moduleName) { + CompositeNode compNode = loadAndNormalizeData(jsonPath, yangPath, topLevelElementName, moduleName); + verifyCompositeNode(compNode, namespace); + } + + private CompositeNode loadAndNormalizeData(String jsonPath, String yangPath, String topLevelElementName, String moduleName) { CompositeNode compositeNode = TestUtils.readInputToCnSn(jsonPath, false, JsonToCompositeNodeProvider.INSTANCE); assertNotNull(compositeNode); Set modules = null; - try { - modules = TestUtils.loadModules(TestUtils.class.getResource(yangPath).getPath()); - } catch (FileNotFoundException e) { - LOG.error(e.getMessage()); - assertTrue(false); - } + modules = TestUtils.loadModulesFrom(yangPath); assertNotNull(modules); TestUtils.normalizeCompositeNode(compositeNode, modules, moduleName + ":" + topLevelElementName); - // TestUtils.supplementNamespace(dataSchemaNode, compositeNode); assertTrue(compositeNode instanceof CompositeNodeWrapper); CompositeNode compNode = ((CompositeNodeWrapper) compositeNode).unwrap(); assertEquals(topLevelElementName, compNode.getNodeType().getLocalName()); - verifyCompositeNode(compNode, namespace); + return compNode; } private void verityMultipleItemsInList(CompositeNode compositeNode) {