2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.export;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertTrue;
12 import static org.opendaylight.yangtools.yang.model.export.DeclaredStatementFormatter.defaultInstance;
14 import java.util.Collection;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement.NameToEffectiveSubmoduleNamespace;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class YangTextSnippetTest {
25 public void testNotification() {
26 final SchemaContext schema = YangParserTestUtils.parseYangResource("/bugs/bug2444/yang/notification.yang");
27 assertFormat(schema.getModules());
31 public void testSubmoduleNamespaces() throws Exception {
32 SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/yt992");
33 assertFormat(schema.getModules());
36 private static void assertFormat(final Collection<? extends Module> modules) {
37 for (Module module : modules) {
38 assertTrue(module instanceof ModuleEffectiveStatement);
39 final ModuleEffectiveStatement stmt = (ModuleEffectiveStatement) module;
40 assertNotNull(formatModule(stmt));
42 for (SubmoduleEffectiveStatement substmt : stmt.getAll(NameToEffectiveSubmoduleNamespace.class).values()) {
43 assertNotNull(formatSubmodule(substmt));
48 private static String formatModule(final ModuleEffectiveStatement stmt) {
49 return defaultInstance().toYangTextSnippet(stmt, stmt.getDeclared()).toString();
52 private static String formatSubmodule(final SubmoduleEffectiveStatement stmt) {
53 return defaultInstance().toYangTextSnippet(stmt, stmt.getDeclared()).toString();