Vidyashree Rama | e2bd9ba | 2016-03-29 14:37:02 +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 | e2bd9ba | 2016-03-29 14:37:02 +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 | |
| 19 | import java.io.IOException; |
| 20 | import java.util.ListIterator; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.yangutils.datamodel.YangNode; |
| 24 | import org.onosproject.yangutils.datamodel.YangModule; |
| 25 | import org.onosproject.yangutils.datamodel.YangAugment; |
| 26 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 27 | import org.onosproject.yangutils.datamodel.YangNodeIdentifier; |
| 28 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
| 29 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| 30 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 31 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 32 | |
| 33 | import static org.hamcrest.core.Is.is; |
| 34 | import static org.junit.Assert.assertThat; |
| 35 | |
| 36 | /** |
| 37 | * Test cases for testing augment listener functionality. |
| 38 | */ |
| 39 | public class AugmentListenerTest { |
| 40 | |
| 41 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 42 | |
| 43 | /** |
| 44 | * Checks valid augment statement. |
| 45 | */ |
| 46 | @Test |
| 47 | public void processValidAugmentStatement() throws IOException, ParserException { |
| 48 | |
| 49 | YangNode node = manager.getDataModel("src/test/resources/ValidAugmentStatement.yang"); |
| 50 | |
| 51 | assertThat((node instanceof YangModule), is(true)); |
| 52 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 53 | YangModule yangNode = (YangModule) node; |
| 54 | assertThat(yangNode.getName(), is("Test")); |
| 55 | |
| 56 | YangAugment yangAugment = (YangAugment) yangNode.getChild(); |
Vidyashree Rama | e2bd9ba | 2016-03-29 14:37:02 +0530 | [diff] [blame] | 57 | ListIterator<YangNodeIdentifier> nodeIdentifierIterator = yangAugment.getTargetNode().listIterator(); |
| 58 | YangNodeIdentifier yangNodeIdentifier = nodeIdentifierIterator.next(); |
| 59 | assertThat(yangNodeIdentifier.getPrefix(), is("if")); |
| 60 | assertThat(yangNodeIdentifier.getName(), is("interfaces")); |
| 61 | |
| 62 | ListIterator<YangLeaf> leafIterator = yangAugment.getListOfLeaf().listIterator(); |
| 63 | YangLeaf leafInfo = leafIterator.next(); |
| 64 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 65 | assertThat(leafInfo.getName(), is("ds0ChannelNumber")); |
Vidyashree Rama | e2bd9ba | 2016-03-29 14:37:02 +0530 | [diff] [blame] | 66 | assertThat(leafInfo.getDataType().getDataTypeName(), is("ChannelNumber")); |
| 67 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED)); |
| 68 | } |
| 69 | } |