fc985465ce47bcc9fa23f556cd7bca617a6a85f2
[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 package org.opendaylight.yangtools.yang.stmt;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.Collection;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21
22 public class Bug3799Test {
23
24     @Test
25     public void test() throws Exception {
26         SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug3799");
27         assertNotNull(schema);
28
29         Collection<? extends Module> modules = schema.getModules();
30         assertNotNull(modules);
31         assertEquals(1, modules.size());
32
33         Module testModule = modules.iterator().next();
34         Collection<? extends Module> subModules = testModule.getSubmodules();
35         assertNotNull(subModules);
36         assertEquals(1, subModules.size());
37
38         Module testSubmodule = subModules.iterator().next();
39
40         Collection<? extends NotificationDefinition> notifications = testSubmodule.getNotifications();
41         assertNotNull(notifications);
42         assertEquals(1, notifications.size());
43
44         NotificationDefinition bazNotification = notifications.iterator().next();
45         Collection<? extends 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 }