Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +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 org.junit.Test; |
| 21 | import org.onosproject.yangutils.datamodel.YangContainer; |
janani b | 06eca9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.YangGrouping; |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.YangList; |
| 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.datamodel.YangStatusType; |
| 28 | import org.onosproject.yangutils.datamodel.YangUses; |
| 29 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 30 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 31 | |
| 32 | import static org.hamcrest.MatcherAssert.assertThat; |
| 33 | import static org.hamcrest.core.Is.is; |
| 34 | |
| 35 | /** |
| 36 | * Test cases for testing uses listener. |
| 37 | */ |
| 38 | public class UsesListenerTest { |
| 39 | |
| 40 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 41 | |
| 42 | /** |
| 43 | * Checks uses statement inside module. |
| 44 | */ |
| 45 | @Test |
| 46 | public void processUsesInModule() throws IOException, ParserException { |
| 47 | |
| 48 | YangNode node = manager.getDataModel("src/test/resources/UsesInModule.yang"); |
| 49 | |
| 50 | // Check whether the data model tree returned is of type module. |
| 51 | assertThat((node instanceof YangModule), is(true)); |
| 52 | |
| 53 | // Check whether the node type is set properly to module. |
| 54 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 55 | |
| 56 | // Check whether the module name is set correctly. |
| 57 | YangModule yangNode = (YangModule) node; |
| 58 | assertThat(yangNode.getName(), is("Test")); |
| 59 | |
janani b | 06eca9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 60 | YangGrouping yangGrouping = (YangGrouping) yangNode.getChild(); |
| 61 | assertThat(yangGrouping.getName(), is("endpoint")); |
| 62 | |
| 63 | YangUses yangUses = (YangUses) yangGrouping.getNextSibling(); |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 64 | assertThat(yangUses.getName(), is("endpoint")); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Checks uses statement inside container. |
| 69 | */ |
| 70 | @Test |
| 71 | public void processUsesInContainer() throws IOException, ParserException { |
| 72 | |
| 73 | YangNode node = manager.getDataModel("src/test/resources/UsesInContainer.yang"); |
| 74 | |
| 75 | // Check whether the data model tree returned is of type module. |
| 76 | assertThat((node instanceof YangModule), is(true)); |
| 77 | |
| 78 | // Check whether the node type is set properly to module. |
| 79 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 80 | |
| 81 | // Check whether the module name is set correctly. |
| 82 | YangModule yangNode = (YangModule) node; |
| 83 | assertThat(yangNode.getName(), is("Test")); |
| 84 | |
janani b | 06eca9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 85 | YangGrouping yangGrouping = (YangGrouping) yangNode.getChild(); |
| 86 | assertThat(yangGrouping.getName(), is("endpoint")); |
| 87 | |
| 88 | YangContainer yangContainer = (YangContainer) yangGrouping.getNextSibling(); |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 89 | assertThat(yangContainer.getName(), is("valid")); |
| 90 | |
| 91 | YangUses yangUses = (YangUses) yangContainer.getChild(); |
| 92 | assertThat(yangUses.getName(), is("endpoint")); |
| 93 | |
| 94 | // Check attributes associated with uses. |
| 95 | assertThat(yangUses.getStatus(), is(YangStatusType.CURRENT)); |
| 96 | assertThat(yangUses.getReference(), is("\"RFC 6020\"")); |
| 97 | assertThat(yangUses.getDescription(), is("\"grouping under test\"")); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Checks uses statement inside list. |
| 102 | */ |
| 103 | @Test |
| 104 | public void processUsesInList() throws IOException, ParserException { |
| 105 | |
| 106 | YangNode node = manager.getDataModel("src/test/resources/UsesInList.yang"); |
| 107 | |
| 108 | // Check whether the data model tree returned is of type module. |
| 109 | assertThat((node instanceof YangModule), is(true)); |
| 110 | |
| 111 | // Check whether the node type is set properly to module. |
| 112 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 113 | |
| 114 | // Check whether the module name is set correctly. |
| 115 | YangModule yangNode = (YangModule) node; |
| 116 | assertThat(yangNode.getName(), is("Test")); |
| 117 | |
janani b | 06eca9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 118 | YangGrouping yangGrouping = (YangGrouping) yangNode.getChild(); |
| 119 | assertThat(yangGrouping.getName(), is("endpoint")); |
| 120 | |
| 121 | YangList yangList = (YangList) yangGrouping.getNextSibling(); |
Gaurav Agrawal | f6ccc97 | 2016-03-25 11:25:36 +0530 | [diff] [blame] | 122 | assertThat(yangList.getName(), is("valid")); |
| 123 | |
| 124 | YangUses yangUses = (YangUses) yangList.getChild(); |
| 125 | assertThat(yangUses.getName(), is("endpoint")); |
| 126 | |
| 127 | // Check attributes associated with uses. |
| 128 | assertThat(yangUses.getStatus(), is(YangStatusType.CURRENT)); |
| 129 | assertThat(yangUses.getReference(), is("\"RFC 6020\"")); |
| 130 | assertThat(yangUses.getDescription(), is("\"grouping under test\"")); |
| 131 | } |
| 132 | } |