YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug3799Test.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.stmt;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import java.util.Collection;
16 import java.util.Set;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23
24 public class Bug3799Test {
25
26     @Test
27     public void test() throws Exception {
28         SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug3799");
29         assertNotNull(schema);
30
31         Set<Module> modules = schema.getModules();
32         assertNotNull(modules);
33         assertEquals(1, modules.size());
34
35         Module testModule = modules.iterator().next();
36         Set<Module> subModules = testModule.getSubmodules();
37         assertNotNull(subModules);
38         assertEquals(1, subModules.size());
39
40         Module testSubmodule = subModules.iterator().next();
41
42         Set<NotificationDefinition> notifications = testSubmodule
43                 .getNotifications();
44         assertNotNull(notifications);
45         assertEquals(1, notifications.size());
46
47         NotificationDefinition bazNotification = notifications.iterator()
48                 .next();
49         Collection<DataSchemaNode> childNodes = bazNotification.getChildNodes();
50         assertNotNull(childNodes);
51         assertEquals(1, childNodes.size());
52
53         DataSchemaNode child = childNodes.iterator().next();
54         assertTrue(child instanceof LeafSchemaNode);
55
56         LeafSchemaNode leafBar = (LeafSchemaNode) child;
57         String bar = leafBar.getQName().getLocalName();
58         assertEquals("bar", bar);
59     }
60
61 }