Vidyashree Rama | 36f2fab | 2016-07-15 14:06:56 +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 java.io.IOException; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.yangutils.datamodel.YangExtension; |
| 22 | import org.onosproject.yangutils.datamodel.YangModule; |
| 23 | import org.onosproject.yangutils.datamodel.YangNode; |
| 24 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| 25 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 26 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 27 | |
| 28 | import static org.hamcrest.MatcherAssert.assertThat; |
| 29 | import static org.hamcrest.core.Is.is; |
| 30 | |
| 31 | /** |
| 32 | * Test cases for testing extension listener. |
| 33 | */ |
| 34 | public class ExtensionListenerTest { |
| 35 | |
| 36 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 37 | |
| 38 | /** |
| 39 | * Checks extension statement as sub-statement of module. |
| 40 | */ |
| 41 | @Test |
| 42 | public void processValidExtensionStatement() throws IOException, ParserException { |
| 43 | |
| 44 | YangNode node = manager.getDataModel("src/test/resources/ValidExtensionStatement.yang"); |
| 45 | |
| 46 | assertThat((node instanceof YangModule), is(true)); |
| 47 | |
| 48 | // Check whether the node type is set properly to module. |
| 49 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 50 | |
| 51 | YangModule yangNode = (YangModule) node; |
| 52 | assertThat(yangNode.getName(), is("ietf-yang-compiler-annotation")); |
| 53 | |
| 54 | YangExtension extension = yangNode.getExtensionList().iterator().next(); |
| 55 | assertThat(extension.getName(), is("compiler-annotation")); |
| 56 | assertThat(extension.getArgumentName(), is("target")); |
| 57 | assertThat(extension.getDescription(), is("\"This extension allows for defining compiler annotations\"")); |
| 58 | } |
| 59 | } |
| 60 | |