From b58442115d8bb23436030f46c84b3df7cc36b685 Mon Sep 17 00:00:00 2001 From: Jakub Toth Date: Mon, 1 Jun 2015 10:24:40 +0200 Subject: [PATCH] Bug 2358 - Remove tests cnsn to xml and add tests nn to xml 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 CnSnToXmlNotExistingLeafTypeTest test * add NnToXmlNotExistingLeafTypeTest to nn/to/xml/test/ * negative test for not existing leaf type Change-Id: I6f55fd82c40a03726aecb78cfc2ece9888cf9717 Signed-off-by: Jakub Toth (cherry picked from commit 0c957832fd6587f5cfe6fb8de215d97cd6fd9c24) --- .../CnSnToXmlNotExistingLeafTypeTest.java | 35 ------- .../test/NnToXmlNotExistingLeafTypeTest.java | 91 +++++++++++++++++++ 2 files changed, 91 insertions(+), 35 deletions(-) delete mode 100644 opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlNotExistingLeafTypeTest.java create mode 100644 opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnToXmlNotExistingLeafTypeTest.java diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlNotExistingLeafTypeTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlNotExistingLeafTypeTest.java deleted file mode 100644 index 757560acfd..0000000000 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlNotExistingLeafTypeTest.java +++ /dev/null @@ -1,35 +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.xml.test; - -import org.opendaylight.controller.sal.restconf.impl.test.DummyType; -import org.opendaylight.controller.sal.restconf.impl.test.TestUtils; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CnSnToXmlNotExistingLeafTypeTest { - - private static final Logger LOG = LoggerFactory.getLogger(CnSnToXmlNotExistingLeafTypeTest.class); - - - private DataSchemaNode prepareDataSchemaNode() { - final ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont", - "simple:uri", "2012-12-17"), null); - final LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", 2, TestUtils.buildQName("lf1", - "simple:uri", "2012-12-17"), null); - 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/xml/test/NnToXmlNotExistingLeafTypeTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnToXmlNotExistingLeafTypeTest.java new file mode 100644 index 0000000000..50ca667f00 --- /dev/null +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnToXmlNotExistingLeafTypeTest.java @@ -0,0 +1,91 @@ +/* + * 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.xml.test; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import javax.ws.rs.core.MediaType; +import org.junit.Test; +import org.opendaylight.controller.sal.rest.impl.NormalizedNodeXmlBodyWriter; +import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest; +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.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.SchemaContext; +import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder; +import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder; + +public class NnToXmlNotExistingLeafTypeTest extends AbstractBodyReaderTest { + + public NnToXmlNotExistingLeafTypeTest() throws NoSuchFieldException, + SecurityException { + super(); + } + + @Test(expected = NullPointerException.class) + public void incorrectTopLevelElementTest() throws Exception { + final NormalizedNodeXmlBodyWriter xmlBodyWriter = new NormalizedNodeXmlBodyWriter(); + final OutputStream output = new ByteArrayOutputStream(); + + final NormalizedNodeContext normalizedNodeContext = prepareNNC(prepareDataSchemaNode()); + xmlBodyWriter.writeTo(normalizedNodeContext, null, null, null, + mediaType, null, output); + + } + + private NormalizedNodeContext prepareNNC(final DataSchemaNode dataSchemaNode) { + final QName cont = QName.create("simple:uri", "2012-12-17", "cont"); + final QName lf = QName.create("simple:uri", "2012-12-17", "lf1"); + + final DataSchemaNode contSchema = ((ContainerSchemaNode) dataSchemaNode) + .getDataChildByName(cont); + final DataContainerNodeAttrBuilder dataCont = Builders + .containerBuilder((ContainerSchemaNode) contSchema); + + final DataSchemaNode lfSchema = ((ContainerSchemaNode) dataSchemaNode) + .getDataChildByName(lf); + + dataCont.withChild(Builders.leafBuilder((LeafSchemaNode) lfSchema) + .withValue("any value").build()); + + final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext( + new InstanceIdentifierContext(null, contSchema, + null, (SchemaContext) dataSchemaNode), dataCont.build()); + + return testNormalizedNodeContext; + } + + private DataSchemaNode prepareDataSchemaNode() { + final ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder( + "module", 1, TestUtils.buildQName("cont", "simple:uri", + "2012-12-17"), null); + final LeafSchemaNodeBuilder leafBuild = new LeafSchemaNodeBuilder("module", + 2, TestUtils.buildQName("lf1", "simple:uri", "2012-12-17"), + null); + leafBuild.setType(new DummyType()); + leafBuild.setConfiguration(true); + + contBuild.addChildNode(leafBuild); + return contBuild.build(); + } + + @Override + protected MediaType getMediaType() { + return null; + } + +} -- 2.36.6