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 = DeclaredStatementFormatter.defaultInstance().toYangTextSnippet(stmt, stmt.getDeclared())
- .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();
+ }
}