Bug 2358 - Remove tests cnsn to json and add tests nn to json 17/22617/6
authorJakub Toth <jatoth@cisco.com>
Wed, 27 May 2015 10:44:31 +0000 (12:44 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 23 Jul 2015 09:04:02 +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 CnSnToJsonWithAugmentTest test
* add NnToJsonWithAugmentTest to nn/to/json/test/
  * positive test for test augmented elements

Change-Id: I4c8b92e828ade1d43a5af5384ec7938854fda9ce
Signed-off-by: Jakub Toth <jatoth@cisco.com>
(cherry picked from commit 6b97753fc17bb2d9d73047038105754fcebe029d)

opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonWithAugmentTest.java [deleted file]
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonWithAugmentTest.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/CnSnToJsonWithAugmentTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonWithAugmentTest.java
deleted file mode 100644 (file)
index ab977fe..0000000
+++ /dev/null
@@ -1,20 +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.YangAndXmlAndDataSchemaLoader;
-
-public class CnSnToJsonWithAugmentTest extends YangAndXmlAndDataSchemaLoader {
-
-    @BeforeClass
-    public static void initialize() {
-        dataLoad("/cnsn-to-json/augmentation", 5, "yang", "cont");
-    }
-
-}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonWithAugmentTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/nn/to/json/test/NnToJsonWithAugmentTest.java
new file mode 100644 (file)
index 0000000..f9bfb0b
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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.assertTrue;
+import com.google.common.base.Preconditions;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
+import org.opendaylight.controller.sal.rest.impl.NormalizedNodeJsonBodyWriter;
+import org.opendaylight.controller.sal.rest.impl.test.providers.AbstractBodyReaderTest;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+public class NnToJsonWithAugmentTest extends AbstractBodyReaderTest {
+
+    private static SchemaContext schemaContext;
+    private final NormalizedNodeJsonBodyWriter xmlBodyWriter;
+
+    public NnToJsonWithAugmentTest() throws NoSuchFieldException,
+            SecurityException {
+        super();
+        xmlBodyWriter = new NormalizedNodeJsonBodyWriter();
+    }
+
+    @BeforeClass
+    public static void initialize() {
+        schemaContext = schemaContextLoader("/nn-to-json/augmentation",
+                schemaContext);
+        controllerContext.setSchemas(schemaContext);
+    }
+
+    @Test
+    public void augmentedElementsToJson() throws WebApplicationException,
+            IOException {
+        final String uri = "yang:cont";
+        final String pathToInputFile = "/nn-to-json/augmentation/xml/data.xml";
+
+        final NormalizedNodeContext testNN = TestRestconfUtils
+                .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
+
+        final OutputStream output = new ByteArrayOutputStream();
+        xmlBodyWriter
+                .writeTo(testNN, null, null, null, mediaType, null, output);
+        final String jsonOutput = output.toString();
+
+        Preconditions.checkNotNull(jsonOutput);
+
+        assertTrue(jsonOutput.contains("\"cont1\"" + ":" + '{'));
+        assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf11\""));
+        assertTrue(jsonOutput.contains("\"lst1\"" + ":" + '['));
+        assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_1\""));
+        assertTrue(jsonOutput.contains("\"lf11\"" + ":" + "\"lf1_2\""));
+        assertTrue(jsonOutput.contains("\"lflst1\"" + ":" + "["));
+        assertTrue(jsonOutput.contains("\"lf2\"" + ":" + "\"lf2\""));
+    }
+
+    @Override
+    protected MediaType getMediaType() {
+        return new MediaType(MediaType.APPLICATION_XML, null);
+    }
+}