blob: 7da24680734932e30a7429b76e9d375d182c8461 [file] [log] [blame]
Vidyashree Rama506cbe12016-03-28 11:59:27 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Vidyashree Rama506cbe12016-03-28 11:59:27 +05303 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yangutils.parser.impl.listeners;
18
Vidyashree Rama506cbe12016-03-28 11:59:27 +053019import java.io.IOException;
20import java.util.ListIterator;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053021import org.junit.Test;
22import org.onosproject.yangutils.datamodel.YangLeaf;
23import org.onosproject.yangutils.datamodel.YangModule;
24import org.onosproject.yangutils.datamodel.YangNode;
25import org.onosproject.yangutils.datamodel.YangNodeType;
26import org.onosproject.yangutils.datamodel.YangNotification;
27import org.onosproject.yangutils.datamodel.YangStatusType;
28import org.onosproject.yangutils.datamodel.YangTypeDef;
29import org.onosproject.yangutils.parser.exceptions.ParserException;
30import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
Vidyashree Rama506cbe12016-03-28 11:59:27 +053031
32import static org.hamcrest.core.Is.is;
33import static org.junit.Assert.assertThat;
34
35/**
36 * Test cases for testing notification listener functionality.
37 */
38public class NotificationListenerTest {
39
40 private final YangUtilsParserManager manager = new YangUtilsParserManager();
41
42 /**
43 * Checks valid notification statement.
44 */
45 @Test
46 public void processValidNotificationStatement() throws IOException, ParserException {
47
48 YangNode node = manager.getDataModel("src/test/resources/ValidNotificationStatement.yang");
49
50 assertThat((node instanceof YangModule), is(true));
51 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
52 YangModule yangNode = (YangModule) node;
53 assertThat(yangNode.getName(), is("rock"));
54
55 YangNotification yangNotification = (YangNotification) yangNode.getChild();
56 assertThat(yangNotification.getName(), is("link-failure"));
57 assertThat(yangNotification.getDescription(), is("\"A link failure has been detected\""));
58 assertThat(yangNotification.getStatus(), is(YangStatusType.DEPRECATED));
59 assertThat(yangNotification.getReference(), is("\"reference\""));
60
61 YangTypeDef typeDef = (YangTypeDef) yangNotification.getChild();
62 assertThat(typeDef.getName(), is("my-type"));
63 assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
Vidyashree Rama506cbe12016-03-28 11:59:27 +053064
65 ListIterator<YangLeaf> leafIterator = yangNotification.getListOfLeaf().listIterator();
66 YangLeaf leafInfo = leafIterator.next();
67
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053068 assertThat(leafInfo.getName(), is("if-name"));
janani b6240d292016-05-17 18:20:33 +053069 assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
Vidyashree Rama506cbe12016-03-28 11:59:27 +053070 }
71}