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