From 61d04cd9d97d2f01e327998b3c4d925473213f9b Mon Sep 17 00:00:00 2001 From: Jakub Toth Date: Wed, 27 May 2015 11:41:45 +0200 Subject: [PATCH] Bug 2358 - Remove tests cnsn to json and add tests nn to json Tests of codecs are included in codecs yangtools yang-data-codec-gson and yang-data-impl but we test codec on input data and also with presentation of Rest path. * remove CnSnToJsonNotExistingLeafTypeTest.java test * add NnToJsonNotExistingLeafTypeTest.java to nn/to/json/test/ * test with not existing leaf type Change-Id: Id7a1256b42a3a754e13343613dcad7059a2316c4 Signed-off-by: Jakub Toth (cherry picked from commit 1fa839d51563b9588bf7502e86a5e9c2425fab2f) --- .../CnSnToJsonNotExistingLeafTypeTest.java | 40 --------- .../test/NnToJsonNotExistingLeafTypeTest.java | 89 +++++++++++++++++++ 2 files changed, 89 insertions(+), 40 deletions(-) delete mode 100644 opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java create mode 100644 opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonNotExistingLeafTypeTest.java diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java deleted file mode 100644 index c04a40ffc5..0000000000 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.cnsn.to.json.test; - -import org.junit.BeforeClass; -import org.opendaylight.controller.sal.restconf.impl.test.DummyType; -import org.opendaylight.controller.sal.restconf.impl.test.TestUtils; -import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder; - -public class CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLoader { - - @BeforeClass - public static void initialize() { - dataLoad("/cnsn-to-json/simple-data-types"); - } - - @SuppressWarnings("unused") - private DataSchemaNode prepareDataSchemaNode() { - final ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont", - "simple:uri", "2012-12-17"), SchemaPath.create(true, QName.create("dummy"))); - final LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1", - "simple:uri", "2012-12-17"), SchemaPath.create(true, QName.create("dummy"))); - leafBuild.setType(new DummyType()); - leafBuild.setConfiguration(true); - - contBuild.addChildNode(leafBuild); - return contBuild.build(); - } - -} diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonNotExistingLeafTypeTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonNotExistingLeafTypeTest.java new file mode 100644 index 0000000000..94ad703e43 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonNotExistingLeafTypeTest.java @@ -0,0 +1,89 @@ +/* + * 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.nn.to.json.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import com.google.common.base.Preconditions; +import org.junit.Test; +import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext; +import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext; +import org.opendaylight.controller.sal.restconf.impl.test.DummyType; +import org.opendaylight.controller.sal.restconf.impl.test.TestUtils; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; +import org.opendaylight.yangtools.yang.data.impl.schema.Builders; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder; + +public class NnToJsonNotExistingLeafTypeTest { + + @Test + public void incorrectTopLevelElementTest() { + final NormalizedNodeContext normalizedNodeContext = prepareNormalizedNode(); + assertNotNull(normalizedNodeContext); + assertEquals(normalizedNodeContext.getData().getNodeType() + .getLocalName(), "cont"); + + final String output = NormalizedNodes.toStringTree(normalizedNodeContext + .getData()); + assertNotNull(output); + assertTrue(output.contains("lf1")); + } + + private NormalizedNodeContext prepareNormalizedNode() { + final QName lf1 = QName.create("simple:uri", "2012-12-17", "lf1"); + + final DataSchemaNode contSchemaNode = prepareDataSchemaNode(); + + Preconditions.checkState(contSchemaNode instanceof ContainerSchemaNode); + final ContainerSchemaNode conContSchemaNode = (ContainerSchemaNode) contSchemaNode; + + final DataContainerNodeAttrBuilder contContBuilder = Builders + .containerBuilder(conContSchemaNode); + + final DataSchemaNode lf1SchemaNode = conContSchemaNode + .getDataChildByName(lf1); + Preconditions.checkState(lf1SchemaNode instanceof LeafSchemaNode); + + final String lf1String = ""; + contContBuilder.withChild(Builders + .leafBuilder((LeafSchemaNode) lf1SchemaNode) + .withValue(lf1String).build()); + + final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext( + new InstanceIdentifierContext(null, + contSchemaNode, null, null), contContBuilder.build()); + + return testNormalizedNodeContext; + } + + private DataSchemaNode prepareDataSchemaNode() { + final ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder( + "module", 1, TestUtils.buildQName("cont", "simple:uri", + "2012-12-17"), SchemaPath.create(true, + QName.create("dummy"))); + final LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", + 2, TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), + SchemaPath.create(true, QName.create("dummy"))); + leafBuild.setType(new DummyType()); + leafBuild.setConfiguration(true); + + contBuild.addChildNode(leafBuild); + return contBuild.build(); + } + +} -- 2.36.6