Bug5531: Can't get complete YIN schema on Windows 44/36944/1
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Thu, 31 Mar 2016 10:46:23 +0000 (12:46 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Thu, 31 Mar 2016 10:49:07 +0000 (12:49 +0200)
Added unit test trying to write small module to YIN. If result is not
empty and module is complete then test is sucessfull.

Change-Id: I8b0b0c0c0f787c9a6402dd8b4c74173b89a1b8c5
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug5531Test.java [new file with mode: 0644]
yang/yang-model-export/src/test/resources/bugs/bug5531/foo.yang [new file with mode: 0644]

diff --git a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug5531Test.java b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug5531Test.java
new file mode 100644 (file)
index 0000000..0d0d9d1
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016 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.yangtools.yang.model.export.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
+
+public class Bug5531Test {
+    @Test
+    public void test() throws Exception {
+        SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug5531");
+
+        assertNotNull(schema);
+        assertNotNull(schema.getModules());
+        assertEquals(1, schema.getModules().size());
+
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
+
+        // write small module of size less than 8kB
+       for (Module module : schema.getModules()) {
+           YinExportUtils.writeModuleToOutputStream(schema, module, bufferedOutputStream);
+       }
+
+        String output = byteArrayOutputStream.toString();
+
+        // if all changes were flushed then following conditions are satisfied
+        assertNotEquals("Output should not be empty", 0, output.length());
+        assertTrue("Output should contains start of the module", output.contains("<module"));
+        assertTrue("Output should contains end of the module", output.contains("</module>"));
+    }
+}
diff --git a/yang/yang-model-export/src/test/resources/bugs/bug5531/foo.yang b/yang/yang-model-export/src/test/resources/bugs/bug5531/foo.yang
new file mode 100644 (file)
index 0000000..2c6c2e3
--- /dev/null
@@ -0,0 +1,8 @@
+module foo {
+    namespace "foo";
+    prefix foo;
+
+    revision 2015-01-01 {
+        description "test";
+    }
+}