Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / Bug3799Test.java
1 package org.opendaylight.yangtools.yang.stmt.test;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
7 import java.util.Collection;
8 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
9 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
10 import java.util.Set;
11 import org.opendaylight.yangtools.yang.model.api.Module;
12 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
14 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
15 import java.io.IOException;
16 import java.net.URISyntaxException;
17 import org.junit.Test;
18
19 public class Bug3799Test {
20
21     @Test
22     public void test() throws IOException, URISyntaxException, SourceException,
23             ReactorException {
24         SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug3799");
25         assertNotNull(schema);
26
27         Set<Module> modules = schema.getModules();
28         assertNotNull(modules);
29         assertEquals(1, modules.size());
30
31         Module testModule = modules.iterator().next();
32         Set<Module> subModules = testModule.getSubmodules();
33         assertNotNull(subModules);
34         assertEquals(1, subModules.size());
35
36         Module testSubmodule = subModules.iterator().next();
37
38         Set<NotificationDefinition> notifications = testSubmodule
39                 .getNotifications();
40         assertNotNull(notifications);
41         assertEquals(1, notifications.size());
42
43         NotificationDefinition bazNotification = notifications.iterator()
44                 .next();
45         Collection<DataSchemaNode> childNodes = bazNotification.getChildNodes();
46         assertNotNull(childNodes);
47         assertEquals(1, childNodes.size());
48
49         DataSchemaNode child = childNodes.iterator().next();
50         assertTrue(child instanceof LeafSchemaNode);
51
52         LeafSchemaNode leafBar = (LeafSchemaNode) child;
53         String bar = leafBar.getQName().getLocalName();
54         assertEquals("bar", bar);
55     }
56
57 }