Bug 2358 - Remove tests cnsn to xml and add tests nn to xml 08/22608/4
authorJakub Toth <jatoth@cisco.com>
Mon, 1 Jun 2015 08:24:40 +0000 (10:24 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 8 Jul 2015 14:20:13 +0000 (14:20 +0000)
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 <jatoth@cisco.com>
(cherry picked from commit 0c957832fd6587f5cfe6fb8de215d97cd6fd9c24)

opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlNotExistingLeafTypeTest.java [deleted file]
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/xml/test/NnToXmlNotExistingLeafTypeTest.java [new file with mode: 0644]

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 (file)
index 757560a..0000000
+++ /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 (file)
index 0000000..50ca667
--- /dev/null
@@ -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<NodeIdentifier, ContainerNode> 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<DataSchemaNode>(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;
+    }
+
+}