2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
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.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
24 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
28 public class NotificationStmtTest {
30 private static final StatementStreamSource NOTIFICATION_MODULE = sourceForResource("/model/baz.yang");
31 private static final StatementStreamSource IMPORTED_MODULE = sourceForResource("/model/bar.yang");
34 public void notificationTest() throws ReactorException {
35 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
36 reactor.addSources(NOTIFICATION_MODULE, IMPORTED_MODULE);
38 final EffectiveSchemaContext result = reactor.buildEffective();
39 assertNotNull(result);
41 final Module testModule = result.findModuleByName("baz", null);
42 assertNotNull(testModule);
44 final Set<NotificationDefinition> notifications = testModule.getNotifications();
45 assertEquals(1, notifications.size());
47 final NotificationDefinition notification = notifications.iterator().next();
48 assertEquals("event", notification.getQName().getLocalName());
49 assertEquals(3, notification.getChildNodes().size());
51 LeafSchemaNode leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "event-class"));
53 leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "severity"));
55 final AnyXmlSchemaNode anyXml = (AnyXmlSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "reporting-entity"));
56 assertNotNull(anyXml);