Populate SubmoduleEffectiveModule with import namespaces
[yangtools.git] / yang / yang-model-export / src / test / java / org / opendaylight / yangtools / yang / model / export / YangTextSnippetTest.java
index 7ae29ed4c6f621b21c1cce6b54ee4f11932713e2..206c939bd1c228c25b6a8eee1c36dc7f9f300209 100644 (file)
@@ -9,24 +9,47 @@ package org.opendaylight.yangtools.yang.model.export;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.opendaylight.yangtools.yang.model.export.DeclaredStatementFormatter.defaultInstance;
 
+import java.util.Collection;
 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.api.stmt.ModuleEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement.NameToEffectiveSubmoduleNamespace;
+import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class YangTextSnippetTest {
     @Test
     public void testNotification() {
         final SchemaContext schema = YangParserTestUtils.parseYangResource("/bugs/bug2444/yang/notification.yang");
+        assertFormat(schema.getModules());
+    }
+
+    @Test
+    public void testSubmoduleNamespaces() throws Exception {
+        SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/yt992");
+        assertFormat(schema.getModules());
+    }
 
-        for (Module module : schema.getModules()) {
+    private static void assertFormat(final Collection<? extends Module> modules) {
+        for (Module module : modules) {
             assertTrue(module instanceof ModuleEffectiveStatement);
             final ModuleEffectiveStatement stmt = (ModuleEffectiveStatement) module;
+            assertNotNull(formatModule(stmt));
 
-            final String str = YangTextSnippet.builder(stmt, stmt.getDeclared()).build().toString();
-            assertNotNull(str);
+            for (SubmoduleEffectiveStatement substmt : stmt.getAll(NameToEffectiveSubmoduleNamespace.class).values()) {
+                assertNotNull(formatSubmodule(substmt));
+            }
         }
     }
+
+    private static String formatModule(final ModuleEffectiveStatement stmt) {
+        return defaultInstance().toYangTextSnippet(stmt, stmt.getDeclared()).toString();
+    }
+
+    private static String formatSubmodule(final SubmoduleEffectiveStatement stmt) {
+        return defaultInstance().toYangTextSnippet(stmt, stmt.getDeclared()).toString();
+    }
 }