Populate parser/ hierarchy
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / NotificationStmtTest.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.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
13
14 import java.util.Collection;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24
25 public class NotificationStmtTest {
26
27     @Test
28     public void notificationTest() throws ReactorException {
29         final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
30                 .addSources(sourceForResource("/model/baz.yang"), sourceForResource("/model/bar.yang"))
31                 .buildEffective();
32         assertNotNull(result);
33
34         final Module testModule = result.findModules("baz").iterator().next();
35         assertNotNull(testModule);
36
37         final Collection<? extends NotificationDefinition> notifications = testModule.getNotifications();
38         assertEquals(1, notifications.size());
39
40         final NotificationDefinition notification = notifications.iterator().next();
41         assertEquals("event", notification.getQName().getLocalName());
42         assertEquals(3, notification.getChildNodes().size());
43
44         LeafSchemaNode leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(),
45                 "event-class"));
46         assertNotNull(leaf);
47         leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "severity"));
48         assertNotNull(leaf);
49         final AnyxmlSchemaNode anyXml = (AnyxmlSchemaNode) notification.getDataChildByName(QName.create(
50             testModule.getQNameModule(), "reporting-entity"));
51         assertNotNull(anyXml);
52     }
53 }