blob: b6a57d9f5147720d4e70a0361117a846696bd8e3 [file] [log] [blame]
Vidyashree Rama620b6e92016-03-28 11:59:27 +05301/*
2 * Copyright 2016 Open Networking Laboratory
3 *
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
19import org.junit.Test;
20import org.onosproject.yangutils.datamodel.YangNode;
21import org.onosproject.yangutils.datamodel.YangModule;
22import org.onosproject.yangutils.datamodel.YangNotification;
23import org.onosproject.yangutils.datamodel.YangStatusType;
24import org.onosproject.yangutils.datamodel.YangNodeType;
25import org.onosproject.yangutils.datamodel.YangTypeDef;
26import org.onosproject.yangutils.datamodel.YangLeaf;
27import org.onosproject.yangutils.datamodel.YangDataTypes;
28import org.onosproject.yangutils.parser.exceptions.ParserException;
29import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
30
31import java.io.IOException;
32import java.util.ListIterator;
33
34import static org.hamcrest.core.Is.is;
35import static org.junit.Assert.assertThat;
36
37/**
38 * Test cases for testing notification listener functionality.
39 */
40public class NotificationListenerTest {
41
42 private final YangUtilsParserManager manager = new YangUtilsParserManager();
43
44 /**
45 * Checks valid notification statement.
46 */
47 @Test
48 public void processValidNotificationStatement() throws IOException, ParserException {
49
50 YangNode node = manager.getDataModel("src/test/resources/ValidNotificationStatement.yang");
51
52 assertThat((node instanceof YangModule), is(true));
53 assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
54 YangModule yangNode = (YangModule) node;
55 assertThat(yangNode.getName(), is("rock"));
56
57 YangNotification yangNotification = (YangNotification) yangNode.getChild();
58 assertThat(yangNotification.getName(), is("link-failure"));
59 assertThat(yangNotification.getDescription(), is("\"A link failure has been detected\""));
60 assertThat(yangNotification.getStatus(), is(YangStatusType.DEPRECATED));
61 assertThat(yangNotification.getReference(), is("\"reference\""));
62
63 YangTypeDef typeDef = (YangTypeDef) yangNotification.getChild();
64 assertThat(typeDef.getName(), is("my-type"));
65 assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
66 assertThat(typeDef.getDerivedType().getDataTypeExtendedInfo()
67 .getBaseType().getDataType(), is(YangDataTypes.INT32));
68
69 ListIterator<YangLeaf> leafIterator = yangNotification.getListOfLeaf().listIterator();
70 YangLeaf leafInfo = leafIterator.next();
71
72 assertThat(leafInfo.getLeafName(), is("if-name"));
73 assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref"));
74 }
75}