Bug 2358 - Remove tests cnsn to json and add tests nn to json 18/22618/6
authorJakub Toth <jatoth@cisco.com>
Wed, 27 May 2015 09:41:45 +0000 (11:41 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 23 Jul 2015 09:04:06 +0000 (09:04 +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 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 <jatoth@cisco.com>
(cherry picked from commit 1fa839d51563b9588bf7502e86a5e9c2425fab2f)

opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonNotExistingLeafTypeTest.java [deleted file]
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonNotExistingLeafTypeTest.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/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 (file)
index c04a40f..0000000
+++ /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 (file)
index 0000000..94ad703
--- /dev/null
@@ -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<NodeIdentifier, ContainerNode> 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<DataSchemaNode>(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();
+    }
+
+}