Vidyashree Rama | 918f162 | 2016-07-28 17:33:15 +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.YangAppDataStructure; |
| 22 | import org.onosproject.yangutils.datamodel.YangCompilerAnnotation; |
| 23 | import org.onosproject.yangutils.datamodel.YangDataStructure; |
| 24 | import org.onosproject.yangutils.datamodel.YangModule; |
| 25 | import org.onosproject.yangutils.datamodel.YangNode; |
| 26 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| 27 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 28 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 29 | |
| 30 | import static org.hamcrest.MatcherAssert.assertThat; |
| 31 | import static org.hamcrest.core.Is.is; |
| 32 | |
| 33 | /** |
| 34 | * Test cases for compiler annotation listener. |
| 35 | */ |
| 36 | public class CompilerAnnotationListenerTest { |
| 37 | |
| 38 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 39 | |
| 40 | /** |
| 41 | * Checks valid compiler annotation statements. |
| 42 | */ |
| 43 | @Test |
| 44 | public void processValidCompilerAnnotation() throws IOException, ParserException { |
| 45 | |
| 46 | YangNode node = manager.getDataModel("src/test/resources/ValidCompilerAnnotation.yang"); |
| 47 | |
| 48 | // Check whether the data model tree returned is of type module. |
| 49 | assertThat((node instanceof YangModule), is(true)); |
| 50 | |
| 51 | // Check whether the node type is set properly to module. |
| 52 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 53 | |
| 54 | // Check whether the module name is set correctly. |
| 55 | YangModule yangNode = (YangModule) node; |
| 56 | assertThat(yangNode.getName(), is("event")); |
| 57 | |
| 58 | YangCompilerAnnotation compilerAnnotation = yangNode.getCompilerAnnotationList() |
| 59 | .iterator().next(); |
| 60 | assertThat(compilerAnnotation.getPrefix(), is("ca")); |
| 61 | assertThat(compilerAnnotation.getPath(), is("/candidate-servers/server")); |
| 62 | |
| 63 | YangAppDataStructure appDataStructure = compilerAnnotation.getYangAppDataStructure(); |
| 64 | assertThat(appDataStructure.getPrefix(), is("abc")); |
| 65 | assertThat(appDataStructure.getDataStructure(), is(YangDataStructure.MAP)); |
| 66 | |
| 67 | assertThat(appDataStructure.getKeyList().iterator().next(), is("name")); |
| 68 | } |
| 69 | } |