Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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 | |
| 17 | package org.onosproject.yangutils.parser.impl.listeners; |
| 18 | |
Vidyashree Rama | 918f162 | 2016-07-28 17:33:15 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
| 20 | import java.util.ListIterator; |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 21 | import org.junit.Test; |
| 22 | import org.onosproject.yangutils.datamodel.YangContainer; |
| 23 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 24 | import org.onosproject.yangutils.datamodel.YangList; |
| 25 | import org.onosproject.yangutils.datamodel.YangModule; |
| 26 | import org.onosproject.yangutils.datamodel.YangNode; |
| 27 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 28 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 29 | |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 30 | import static org.hamcrest.core.Is.is; |
| 31 | import static org.junit.Assert.assertThat; |
| 32 | |
| 33 | /** |
| 34 | * Test cases for testing when listener functionality. |
| 35 | */ |
| 36 | public class WhenListenerTest { |
| 37 | |
| 38 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 39 | |
| 40 | /** |
| 41 | * Checks if when listener updates the data model. |
| 42 | */ |
| 43 | @Test |
| 44 | public void processContainerSubStatementWhen() throws IOException, ParserException { |
| 45 | YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementWhen.yang"); |
| 46 | |
| 47 | YangModule yangNode = (YangModule) node; |
| 48 | assertThat(yangNode.getName(), is("Test")); |
| 49 | |
| 50 | YangList yangList = (YangList) yangNode.getChild(); |
Vidyashree Rama | 918f162 | 2016-07-28 17:33:15 +0530 | [diff] [blame] | 51 | String expectedConstraint = "../switching-capability = 'TDM'"; |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 52 | assertThat(yangList.getName(), is("interface-switching-capability")); |
Vidyashree Rama | 918f162 | 2016-07-28 17:33:15 +0530 | [diff] [blame] | 53 | assertThat(yangList.getWhen().getCondition(), is(expectedConstraint)); |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 54 | |
| 55 | YangContainer container = (YangContainer) yangList.getNextSibling(); |
| 56 | assertThat(container.getName(), is("time-division-multiplex-capable")); |
Vidyashree Rama | 13b4c55 | 2016-06-20 15:12:43 +0530 | [diff] [blame] | 57 | assertThat(container.getWhen().getCondition(), is(expectedConstraint)); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Checks if when listener updates the data model. |
| 62 | */ |
| 63 | @Test |
| 64 | public void processLeafSubStatementWhen() throws IOException, ParserException { |
| 65 | YangNode node = manager.getDataModel("src/test/resources/LeafSubStatementWhen.yang"); |
| 66 | |
| 67 | YangModule yangNode = (YangModule) node; |
| 68 | assertThat(yangNode.getName(), is("Test")); |
| 69 | |
| 70 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 71 | YangLeaf leafInfo = leafIterator.next(); |
| 72 | |
| 73 | assertThat(leafInfo.getWhen().getCondition(), is("ifType != 'ethernet'")); |
| 74 | } |
| 75 | } |