Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.parser.impl.listeners; |
| 18 | |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
| 20 | import java.util.ListIterator; |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 21 | import org.junit.Test; |
| 22 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 23 | import org.onosproject.yangutils.datamodel.YangModule; |
| 24 | import org.onosproject.yangutils.datamodel.YangNode; |
| 25 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| 26 | import org.onosproject.yangutils.datamodel.YangNotification; |
| 27 | import org.onosproject.yangutils.datamodel.YangStatusType; |
| 28 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
| 29 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 30 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 31 | |
| 32 | import static org.hamcrest.core.Is.is; |
| 33 | import static org.junit.Assert.assertThat; |
| 34 | |
| 35 | /** |
| 36 | * Test cases for testing notification listener functionality. |
| 37 | */ |
| 38 | public 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 Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 64 | |
| 65 | ListIterator<YangLeaf> leafIterator = yangNotification.getListOfLeaf().listIterator(); |
| 66 | YangLeaf leafInfo = leafIterator.next(); |
| 67 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 68 | assertThat(leafInfo.getName(), is("if-name")); |
janani b | b08850e | 2016-05-17 18:20:33 +0530 | [diff] [blame] | 69 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
Vidyashree Rama | 620b6e9 | 2016-03-28 11:59:27 +0530 | [diff] [blame] | 70 | } |
| 71 | } |