Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / test / NotificationStmtTest.java
1 /*
2  * Copyright (c) 2015 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.test;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
14 import java.util.Set;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
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.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
25
26 public class NotificationStmtTest {
27
28     private static final YangStatementSourceImpl NOTIFICATION_MODULE = new YangStatementSourceImpl("/model/baz.yang",
29             false);
30     private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl("/model/bar.yang",
31             false);
32
33     @Test
34     public void notificationTest() throws ReactorException {
35         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
36         StmtTestUtils.addSources(reactor, NOTIFICATION_MODULE, IMPORTED_MODULE);
37
38         EffectiveSchemaContext result = reactor.buildEffective();
39         assertNotNull(result);
40
41         Module testModule = result.findModuleByName("baz", null);
42         assertNotNull(testModule);
43
44         Set<NotificationDefinition> notifications = testModule.getNotifications();
45         assertEquals(1, notifications.size());
46
47         NotificationDefinition notification = notifications.iterator().next();
48         assertEquals("event", notification.getQName().getLocalName());
49         assertEquals(3, notification.getChildNodes().size());
50
51         LeafSchemaNode leaf = (LeafSchemaNode) notification.getDataChildByName("event-class");
52         assertNotNull(leaf);
53         leaf = (LeafSchemaNode) notification.getDataChildByName("severity");
54         assertNotNull(leaf);
55         AnyXmlSchemaNode anyXml = (AnyXmlSchemaNode) notification.getDataChildByName("reporting-entity");
56         assertNotNull(anyXml);
57     }
58 }