Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / 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
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.rfc7950.reactor.RFC7950Reactors;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25
26 public class NotificationStmtTest {
27
28     @Test
29     public void notificationTest() throws ReactorException {
30         final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
31                 .addSources(sourceForResource("/model/baz.yang"), sourceForResource("/model/bar.yang"))
32                 .buildEffective();
33         assertNotNull(result);
34
35         final Module testModule = result.findModules("baz").iterator().next();
36         assertNotNull(testModule);
37
38         final Set<NotificationDefinition> notifications = testModule.getNotifications();
39         assertEquals(1, notifications.size());
40
41         final NotificationDefinition notification = notifications.iterator().next();
42         assertEquals("event", notification.getQName().getLocalName());
43         assertEquals(3, notification.getChildNodes().size());
44
45         LeafSchemaNode leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(),
46                 "event-class"));
47         assertNotNull(leaf);
48         leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "severity"));
49         assertNotNull(leaf);
50         final AnyXmlSchemaNode anyXml = (AnyXmlSchemaNode) notification.getDataChildByName(QName.create(
51             testModule.getQNameModule(), "reporting-entity"));
52         assertNotNull(anyXml);
53     }
54 }