BUG-4688: Rework SchemaContext module lookups
[yangtools.git] / yang / yang-parser-impl / 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
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.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
14
15 import java.util.Set;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
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 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
25 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
27
28 public class NotificationStmtTest {
29
30     private static final StatementStreamSource NOTIFICATION_MODULE = sourceForResource("/model/baz.yang");
31     private static final StatementStreamSource IMPORTED_MODULE = sourceForResource("/model/bar.yang");
32
33     @Test
34     public void notificationTest() throws ReactorException {
35         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
36         reactor.addSources(NOTIFICATION_MODULE, IMPORTED_MODULE);
37
38         final SchemaContext result = reactor.buildEffective();
39         assertNotNull(result);
40
41         final Module testModule = result.findModules("baz").iterator().next();
42         assertNotNull(testModule);
43
44         final Set<NotificationDefinition> notifications = testModule.getNotifications();
45         assertEquals(1, notifications.size());
46
47         final NotificationDefinition notification = notifications.iterator().next();
48         assertEquals("event", notification.getQName().getLocalName());
49         assertEquals(3, notification.getChildNodes().size());
50
51         LeafSchemaNode leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(),
52                 "event-class"));
53         assertNotNull(leaf);
54         leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "severity"));
55         assertNotNull(leaf);
56         final AnyXmlSchemaNode anyXml = (AnyXmlSchemaNode) notification.getDataChildByName(QName.create(
57             testModule.getQNameModule(), "reporting-entity"));
58         assertNotNull(anyXml);
59     }
60 }