janani b | 4e53f9b | 2016-04-26 18:49:20 +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 | |
Gaurav Agrawal | c5f6327 | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.plugin.manager; |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 18 | |
| 19 | import java.io.IOException; |
| 20 | import java.util.ListIterator; |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 21 | import org.junit.Rule; |
| 22 | import org.junit.Test; |
| 23 | import org.junit.rules.ExpectedException; |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangContainer; |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangGrouping; |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 26 | import org.onosproject.yangutils.datamodel.YangInput; |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 28 | import org.onosproject.yangutils.datamodel.YangList; |
| 29 | import org.onosproject.yangutils.datamodel.YangModule; |
| 30 | import org.onosproject.yangutils.datamodel.YangNode; |
| 31 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| 32 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
| 33 | import org.onosproject.yangutils.datamodel.YangUses; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 35 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 36 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 37 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 38 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 39 | |
| 40 | import static org.hamcrest.MatcherAssert.assertThat; |
| 41 | import static org.hamcrest.core.Is.is; |
| 42 | |
| 43 | /** |
| 44 | * Test cases for testing uses intra file linking. |
| 45 | */ |
| 46 | public class IntraFileUsesLinkingTest { |
| 47 | |
| 48 | @Rule |
| 49 | public ExpectedException thrown = ExpectedException.none(); |
| 50 | |
| 51 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 52 | |
| 53 | /** |
| 54 | * Checks self resolution when grouping and uses are siblings. |
| 55 | * Grouping followed by uses. |
| 56 | */ |
| 57 | @Test |
| 58 | public void processSelfResolutionWhenUsesAndGroupingAtRootLevel() |
| 59 | throws IOException, ParserException { |
| 60 | |
| 61 | YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevel.yang"); |
| 62 | |
| 63 | // Check whether the data model tree returned is of type module. |
| 64 | assertThat((node instanceof YangModule), is(true)); |
| 65 | |
| 66 | // Check whether the node type is set properly to module. |
| 67 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 68 | |
| 69 | // Check whether the module name is set correctly. |
| 70 | YangModule yangNode = (YangModule) node; |
| 71 | assertThat(yangNode.getName(), is("Test")); |
| 72 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 73 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 74 | YangLeaf leafInfo = leafIterator.next(); |
| 75 | |
| 76 | // Check whether the information in the leaf is correct under module. |
| 77 | assertThat(leafInfo.getName(), is("hello")); |
| 78 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
| 79 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 80 | |
| 81 | // Check whether grouping is the sibling of module's child. |
| 82 | assertThat((yangNode.getChild().getNextSibling() instanceof YangGrouping), is(true)); |
| 83 | |
| 84 | YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling(); |
| 85 | leafIterator = grouping.getListOfLeaf().listIterator(); |
| 86 | leafInfo = leafIterator.next(); |
| 87 | |
| 88 | // Check whether the information in the leaf is correct under grouping. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 89 | assertThat(leafInfo.getName(), is("hello")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 90 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 91 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 92 | |
| 93 | // Check whether uses is module's child. |
| 94 | assertThat((yangNode.getChild() instanceof YangUses), is(true)); |
| 95 | YangUses uses = (YangUses) yangNode.getChild(); |
| 96 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 97 | // Check whether uses get resolved |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 98 | assertThat(uses.getResolvableStatus(), |
| 99 | is(ResolvableStatus.RESOLVED)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Checks self resolution when grouping and uses are siblings. |
| 104 | * Grouping has a child node. |
| 105 | */ |
| 106 | @Test |
| 107 | public void processSelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild() |
| 108 | throws IOException, ParserException { |
| 109 | |
| 110 | YangNode node = manager.getDataModel( |
| 111 | "src/test/resources/SelfResolutionWhenUsesAndGroupingAtRootLevelGroupingWithChild.yang"); |
| 112 | |
| 113 | // Check whether the data model tree returned is of type module. |
| 114 | assertThat((node instanceof YangModule), is(true)); |
| 115 | |
| 116 | // Check whether the node type is set properly to module. |
| 117 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 118 | |
| 119 | // Check whether the module name is set correctly. |
| 120 | YangModule yangNode = (YangModule) node; |
| 121 | assertThat(yangNode.getName(), is("Test")); |
| 122 | |
| 123 | ListIterator<YangLeaf> leafIterator; |
| 124 | YangLeaf leafInfo; |
| 125 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 126 | ListIterator<YangLeaf> leafIterator1 = yangNode.getListOfLeaf().listIterator(); |
| 127 | YangLeaf leafInfo1 = leafIterator1.next(); |
| 128 | |
| 129 | // Check whether the information in the leaf is correct under module. |
| 130 | assertThat(leafInfo1.getName(), is("treat")); |
| 131 | assertThat(leafInfo1.getDataType().getDataTypeName(), is("string")); |
| 132 | assertThat(leafInfo1.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 133 | |
| 134 | YangContainer container = (YangContainer) yangNode.getChild().getNextSibling().getNextSibling(); |
| 135 | |
| 136 | // Check whether the container name is set correctly which is under module. |
| 137 | assertThat(container.getName(), is("test")); |
| 138 | |
| 139 | leafIterator = container.getListOfLeaf().listIterator(); |
| 140 | leafInfo = leafIterator.next(); |
| 141 | |
| 142 | // Check whether the information in the leaf is correct under container which is under module. |
| 143 | assertThat(leafInfo.getName(), is("leaf2")); |
| 144 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
| 145 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 146 | |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 147 | // Check whether grouping is the sibling of module's child. |
| 148 | assertThat((yangNode.getChild().getNextSibling() instanceof YangGrouping), is(true)); |
| 149 | |
| 150 | YangGrouping grouping = (YangGrouping) yangNode.getChild().getNextSibling(); |
| 151 | leafIterator = grouping.getListOfLeaf().listIterator(); |
| 152 | leafInfo = leafIterator.next(); |
| 153 | |
| 154 | // Check whether the information in the leaf is correct under grouping. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 155 | assertThat(leafInfo.getName(), is("treat")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 156 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 157 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 158 | |
| 159 | // Check whether container is the child of grouping. |
| 160 | assertThat((grouping.getChild() instanceof YangContainer), is(true)); |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 161 | container = (YangContainer) grouping.getChild(); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 162 | |
| 163 | // Check whether the container name is set correctly which is under grouping. |
| 164 | assertThat(container.getName(), is("test")); |
| 165 | |
| 166 | leafIterator = container.getListOfLeaf().listIterator(); |
| 167 | leafInfo = leafIterator.next(); |
| 168 | |
| 169 | // Check whether the information in the leaf is correct under container which is under grouping. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 170 | assertThat(leafInfo.getName(), is("leaf2")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 171 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 172 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 173 | |
| 174 | // Check whether uses is module's child. |
| 175 | assertThat((yangNode.getChild() instanceof YangUses), is(true)); |
| 176 | YangUses uses = (YangUses) yangNode.getChild(); |
| 177 | |
| 178 | // Check whether uses get resolved. |
| 179 | assertThat(uses.getResolvableStatus(), |
| 180 | is(ResolvableStatus.RESOLVED)); |
| 181 | |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Checks self resolution when grouping in rpc and uses in output of the same rpc. |
| 186 | * Uses is followed by grouping. |
| 187 | */ |
| 188 | @Test |
| 189 | public void processSelfResolutionGroupingInRpcAndUsesInOutput() |
| 190 | throws IOException, ParserException { |
| 191 | |
| 192 | YangNode node = manager |
| 193 | .getDataModel("src/test/resources/SelfResolutionGroupingInRpcAndUsesInOutput.yang"); |
| 194 | |
| 195 | // Check whether the data model tree returned is of type module. |
| 196 | assertThat((node instanceof YangModule), is(true)); |
| 197 | |
| 198 | // Check whether the node type is set properly to module. |
| 199 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 200 | |
| 201 | // Check whether the module name is set correctly. |
| 202 | YangModule yangNode = (YangModule) node; |
| 203 | assertThat(yangNode.getName(), is("rock")); |
| 204 | |
| 205 | ListIterator<YangLeaf> leafIterator; |
| 206 | YangLeaf leafInfo; |
| 207 | |
| 208 | // Check whether grouping is the child of rpc. |
| 209 | assertThat((yangNode.getChild().getChild() instanceof YangGrouping), is(true)); |
| 210 | YangGrouping grouping = (YangGrouping) yangNode.getChild().getChild(); |
| 211 | |
| 212 | // Check whether the grouping name is set correctly. |
| 213 | assertThat(grouping.getName(), is("hello")); |
| 214 | |
| 215 | // Check whether list is the child of grouping. |
| 216 | assertThat((grouping.getChild() instanceof YangList), is(true)); |
| 217 | YangList yangListNode = (YangList) grouping.getChild(); |
| 218 | |
| 219 | // Check whether the list name is set correctly. |
| 220 | assertThat(yangListNode.getName(), is("valid")); |
| 221 | |
| 222 | leafIterator = yangListNode.getListOfLeaf().listIterator(); |
| 223 | leafInfo = leafIterator.next(); |
| 224 | |
| 225 | // Check whether the information in the leaf is correct under list which is under grouping. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 226 | assertThat(leafInfo.getName(), is("invalid-interval")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 227 | assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16")); |
| 228 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); |
| 229 | assertThat(leafInfo.getUnits(), is("\"seconds\"")); |
| 230 | assertThat(leafInfo.getReference(), is("\"RFC 6020\"")); |
| 231 | |
| 232 | // Check whether uses is input's child. |
| 233 | assertThat((yangNode.getChild().getChild().getNextSibling().getChild() instanceof YangUses), is(true)); |
| 234 | YangUses uses = (YangUses) yangNode.getChild().getChild().getNextSibling().getChild(); |
| 235 | |
| 236 | // Check whether uses get resolved. |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 237 | assertThat(uses.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 238 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 239 | YangInput inputNode = ((YangInput) yangNode.getChild().getChild().getNextSibling()); |
| 240 | assertThat((inputNode.getChild() instanceof YangUses), is(true)); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 241 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 242 | YangList yangList = ((YangList) inputNode.getChild().getNextSibling()); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 243 | assertThat(yangList.getName(), is("valid")); |
| 244 | |
| 245 | leafIterator = yangList.getListOfLeaf().listIterator(); |
| 246 | leafInfo = leafIterator.next(); |
| 247 | |
| 248 | // Check whether the information in the leaf is correct under list which is deep copied. |
| 249 | assertThat(leafInfo.getName(), is("invalid-interval")); |
| 250 | assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16")); |
| 251 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); |
| 252 | assertThat(leafInfo.getUnits(), is("\"seconds\"")); |
| 253 | assertThat(leafInfo.getReference(), is("\"RFC 6020\"")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Checks the failure scenario when uses is referring to its own grouping directly. |
| 258 | */ |
| 259 | @Test |
| 260 | public void processSelfResolutionGroupingReferencingItselfFailureScenerio() |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 261 | throws IOException { |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 262 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 263 | thrown.expect(LinkerException.class); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 264 | thrown.expectMessage( |
| 265 | "YANG file error: Duplicate input identifier detected, same as leaf \"zip-code\""); |
| 266 | YangNode node = manager |
| 267 | .getDataModel("src/test/resources/SelfResolutionGroupingReferencingItselfFailureScenerio.yang"); |
| 268 | |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Checks the when multiple uses are present and are referred to the grouping at different levels. |
| 273 | */ |
| 274 | @Test |
| 275 | public void processSelfResolutionGroupingWithMultipleUses() |
| 276 | throws IOException, ParserException { |
| 277 | |
| 278 | YangNode node = manager |
| 279 | .getDataModel("src/test/resources/SelfResolutionGroupingWithMultipleUses.yang"); |
| 280 | |
| 281 | // Check whether the data model tree returned is of type module. |
| 282 | assertThat((node instanceof YangModule), is(true)); |
| 283 | |
| 284 | // Check whether the node type is set properly to module. |
| 285 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 286 | |
| 287 | // Check whether the module name is set correctly. |
| 288 | YangModule yangNode = (YangModule) node; |
| 289 | assertThat(yangNode.getName(), is("Test")); |
| 290 | |
| 291 | ListIterator<YangLeaf> leafIterator; |
| 292 | YangLeaf leafInfo; |
| 293 | |
| 294 | // Check whether grouping is the child of container. |
| 295 | assertThat((yangNode.getChild().getChild() instanceof YangGrouping), is(true)); |
| 296 | YangGrouping grouping = (YangGrouping) yangNode.getChild().getChild(); |
| 297 | |
| 298 | // Check whether the grouping name is set correctly. |
| 299 | assertThat(grouping.getName(), is("endpoint")); |
| 300 | |
| 301 | // Check whether uses is endpoint-grouping's child. |
| 302 | assertThat((grouping.getChild() instanceof YangUses), is(true)); |
| 303 | YangUses firstUses = (YangUses) grouping.getChild(); |
| 304 | |
| 305 | // Check whether uses get resolved. |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 306 | assertThat(firstUses.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 307 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 308 | // Validate first uses child is cloned properly |
| 309 | assertThat((firstUses.getNextSibling().getNextSibling() |
| 310 | .getNextSibling().getNextSibling() instanceof YangList), is(true)); |
| 311 | YangList firstUsesChild = ((YangList) firstUses.getNextSibling().getNextSibling().getNextSibling() |
| 312 | .getNextSibling()); |
| 313 | assertThat(firstUsesChild.getName(), is("valid")); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 314 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 315 | leafIterator = firstUsesChild.getListOfLeaf().listIterator(); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 316 | leafInfo = leafIterator.next(); |
| 317 | |
| 318 | // Check whether the information in the leaf is correct under list which has been deep copied from grouping. |
| 319 | assertThat(leafInfo.getName(), is("invalid-interval")); |
| 320 | assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16")); |
| 321 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); |
| 322 | assertThat(leafInfo.getUnits(), is("\"seconds\"")); |
| 323 | assertThat(leafInfo.getReference(), is("\"RFC 6020\"")); |
| 324 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 325 | //validate uses second |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 326 | assertThat((firstUses.getNextSibling() instanceof YangContainer), is(true)); |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 327 | YangContainer container = (YangContainer) firstUses.getNextSibling(); |
| 328 | assertThat(container.getName(), is("design")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 329 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 330 | assertThat((container.getChild() instanceof YangUses), is(true)); |
| 331 | assertThat((container.getListOfLeaf().iterator().next().getName()), is("ink")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 332 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 333 | //validate uses third |
| 334 | assertThat((container.getChild().getNextSibling() instanceof YangContainer), is(true)); |
| 335 | YangContainer container2 = ((YangContainer) container.getChild().getNextSibling()); |
| 336 | assertThat(container2.getName(), is("correct")); |
| 337 | assertThat((container2.getChild() instanceof YangUses), is(true)); |
| 338 | assertThat((container2.getChild().getNextSibling() instanceof YangContainer), is(true)); |
| 339 | YangContainer thirdUsesChild = ((YangContainer) container2.getChild().getNextSibling()); |
| 340 | assertThat(thirdUsesChild.getListOfLeaf().iterator().next().getName(), is("zip-code")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 341 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 342 | //validate fourth uses |
| 343 | assertThat((firstUses.getNextSibling().getNextSibling() instanceof YangUses), is(true)); |
| 344 | YangUses fourthUses = ((YangUses) firstUses.getNextSibling().getNextSibling()); |
| 345 | assertThat((fourthUses.getNextSibling().getNextSibling().getNextSibling() instanceof YangTypeDef), |
| 346 | is(true)); |
| 347 | assertThat(fourthUses.getNextSibling().getNextSibling().getNextSibling().getName(), is("my-type")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 348 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 349 | //validate fifth uses |
| 350 | assertThat((firstUses.getNextSibling().getNextSibling().getNextSibling() instanceof YangUses), |
| 351 | is(true)); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 352 | |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 353 | //validate end point uses |
| 354 | assertThat(grouping.getNextSibling() instanceof YangUses, is(true)); |
| 355 | assertThat(grouping.getNextSibling().getNextSibling().getNextSibling().getNextSibling() |
| 356 | .getNextSibling().getNextSibling().getNextSibling().getNextSibling() instanceof YangContainer, |
| 357 | is(true)); |
| 358 | container = (YangContainer) grouping.getNextSibling().getNextSibling().getNextSibling().getNextSibling() |
| 359 | .getNextSibling().getNextSibling().getNextSibling().getNextSibling(); |
| 360 | assertThat(container.getName(), is("design")); |
| 361 | container2 = (YangContainer) container.getChild().getNextSibling(); |
| 362 | assertThat(container2.getName(), is("correct")); |
| 363 | assertThat(container2.getChild().getNextSibling().getName(), is("value")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Checks the failure scenario when uses is present under the same node many times. |
| 368 | */ |
| 369 | @Test |
| 370 | public void processSelfResolutionGroupingHavingSameUsesManyTimes() |
| 371 | throws IOException, ParserException { |
| 372 | |
| 373 | thrown.expect(ParserException.class); |
| 374 | thrown.expectMessage( |
| 375 | "YANG file error: Duplicate input identifier detected, same as uses \"failure\""); |
| 376 | YangNode node = manager |
| 377 | .getDataModel("src/test/resources/SelfResolutionGroupingHavingSameUsesManyTimes.yang"); |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Checks the rpc having both typedef and grouping. |
| 382 | * It also checks that the grouping under different nodes will not give any problem in resolving uses. |
| 383 | */ |
| 384 | @Test |
| 385 | public void processSelfResolutionRpcWithOneTypedefAndTwoGroupingUnderDifferentNode() |
| 386 | throws IOException, ParserException { |
| 387 | |
| 388 | YangNode node = manager |
| 389 | .getDataModel( |
| 390 | "src/test/resources/SelfResolutionRpcWithOneTypedefAndTwoGroupingUnderDifferentNode.yang"); |
| 391 | |
| 392 | // Check whether the data model tree returned is of type module. |
| 393 | assertThat((node instanceof YangModule), is(true)); |
| 394 | |
| 395 | // Check whether the node type is set properly to module. |
| 396 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 397 | |
| 398 | // Check whether the module name is set correctly. |
| 399 | YangModule yangNode = (YangModule) node; |
| 400 | assertThat(yangNode.getName(), is("rock")); |
| 401 | |
| 402 | ListIterator<YangLeaf> leafIterator; |
| 403 | YangLeaf leafInfo; |
| 404 | |
| 405 | // Check whether grouping is the child of input. |
| 406 | assertThat((yangNode.getChild().getChild().getChild() instanceof YangGrouping), is(true)); |
| 407 | YangGrouping groupingUnderInput = (YangGrouping) yangNode.getChild().getChild().getChild(); |
| 408 | |
| 409 | // Check whether the grouping name is set correctly. |
| 410 | assertThat(groupingUnderInput.getName(), is("creative")); |
| 411 | |
| 412 | leafIterator = groupingUnderInput.getListOfLeaf().listIterator(); |
| 413 | leafInfo = leafIterator.next(); |
| 414 | |
| 415 | // Check whether the information in the leaf is correct under grouping. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 416 | assertThat(leafInfo.getName(), is("carry")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 417 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
| 418 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 419 | |
| 420 | // Check whether grouping is the child of output. |
| 421 | assertThat((yangNode.getChild().getChild().getNextSibling().getChild() instanceof YangGrouping), is(true)); |
| 422 | YangGrouping grouping = (YangGrouping) yangNode.getChild().getChild().getNextSibling().getChild(); |
| 423 | assertThat(grouping.getName(), is("creative")); |
| 424 | |
| 425 | // Check whether typedef is the sibling of grouping. |
| 426 | assertThat((grouping.getNextSibling() instanceof YangTypeDef), is(true)); |
| 427 | |
| 428 | YangTypeDef typedef = (YangTypeDef) grouping.getNextSibling(); |
| 429 | assertThat(typedef.getName(), is("my-type")); |
| 430 | |
| 431 | // Check whether uses is the sibling of typedef. |
| 432 | assertThat((typedef.getNextSibling() instanceof YangUses), is(true)); |
| 433 | |
| 434 | // Check whether uses get resolved. |
| 435 | YangUses uses = (YangUses) typedef.getNextSibling(); |
| 436 | assertThat(uses.getName(), is("creative")); |
| 437 | assertThat(uses.getResolvableStatus(), |
| 438 | is(ResolvableStatus.RESOLVED)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Checks the failure scenario when uses is cannot resolve its grouping. |
| 443 | */ |
| 444 | @Test |
| 445 | public void processSelfResolutionNestedGroupingWithUnresolvedUses() |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 446 | throws IOException, LinkerException { |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 447 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 448 | thrown.expect(LinkerException.class); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 449 | thrown.expectMessage( |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 450 | "YANG file error: Unable to find base grouping for given uses"); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 451 | |
| 452 | YangNode node = manager |
| 453 | .getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang"); |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Checks self resolution when typedef hierarchical references are present |
| 458 | * with last type is unresolved. |
| 459 | */ |
| 460 | @Test |
| 461 | public void processSelfFileLinkingWithGroupingHierarchicalRefUnresolved() |
| 462 | throws IOException, ParserException { |
| 463 | |
| 464 | YangNode node = manager |
| 465 | .getDataModel("src/test/resources/SelfFileLinkingWithGroupingHierarchicalRefUnresolved.yang"); |
| 466 | |
| 467 | // Check whether the data model tree returned is of type module. |
| 468 | assertThat((node instanceof YangModule), is(true)); |
| 469 | |
| 470 | // Check whether the node type is set properly to module. |
| 471 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 472 | |
| 473 | // Check whether the module name is set correctly. |
| 474 | YangModule yangNode = (YangModule) node; |
| 475 | assertThat(yangNode.getName(), is("Test")); |
| 476 | |
| 477 | // Check whether container is the sibling of grouping. |
| 478 | assertThat((yangNode.getChild().getNextSibling() instanceof YangContainer), is(true)); |
| 479 | YangContainer containerWithUses = (YangContainer) yangNode.getChild().getNextSibling(); |
| 480 | assertThat(containerWithUses.getName(), is("test")); |
| 481 | |
| 482 | // Check whether uses is the child of container. |
| 483 | assertThat((containerWithUses.getChild() instanceof YangUses), is(true)); |
| 484 | YangUses uses = (YangUses) containerWithUses.getChild(); |
| 485 | assertThat(uses.getName(), is("create")); |
| 486 | |
| 487 | // Check whether uses is getting resolved. |
| 488 | assertThat(uses.getResolvableStatus(), |
| 489 | is(ResolvableStatus.RESOLVED)); |
| 490 | |
| 491 | // Check whether grouping is the child of module. |
| 492 | assertThat((yangNode.getChild() instanceof YangGrouping), is(true)); |
| 493 | YangGrouping groupingWithUses = (YangGrouping) yangNode.getChild(); |
| 494 | assertThat(groupingWithUses.getName(), is("create")); |
| 495 | |
| 496 | // Check whether uses with prefix from from other file, is the child of grouping. |
| 497 | assertThat((groupingWithUses.getChild() instanceof YangUses), is(true)); |
| 498 | YangUses uses1 = (YangUses) groupingWithUses.getChild(); |
| 499 | assertThat(uses1.getName(), is("valid")); |
| 500 | |
| 501 | // Check whether this uses is getting intra-file-resolved. |
| 502 | assertThat(uses1.getResolvableStatus(), |
| 503 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * Checks self resolution when uses has prefix of self module. |
| 508 | */ |
| 509 | @Test |
| 510 | public void processSelfFileLinkingWithGroupingWithSelfModulePrefix() |
| 511 | throws IOException, ParserException { |
| 512 | |
| 513 | YangNode node = manager.getDataModel("src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang"); |
| 514 | |
| 515 | // Check whether the data model tree returned is of type module. |
| 516 | assertThat((node instanceof YangModule), is(true)); |
| 517 | |
| 518 | // Check whether the node type is set properly to module. |
| 519 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 520 | |
| 521 | // Check whether the module name is set correctly. |
| 522 | YangModule yangNode = (YangModule) node; |
| 523 | assertThat(yangNode.getName(), is("Test")); |
| 524 | |
| 525 | // Check whether container is the sibling of grouping. |
| 526 | YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); |
| 527 | |
| 528 | // Check whether list is the child of container. |
| 529 | YangList yangList = (YangList) yangContainer.getChild(); |
| 530 | |
| 531 | // Check whether uses is the child of list. |
| 532 | assertThat((yangList.getChild() instanceof YangUses), is(true)); |
| 533 | YangUses yangUses1 = (YangUses) yangList.getChild(); |
| 534 | assertThat(yangUses1.getName(), is("FirstClass")); |
| 535 | |
| 536 | // Check whether uses is getting resolved. |
| 537 | assertThat(yangUses1.getResolvableStatus(), |
| 538 | is(ResolvableStatus.RESOLVED)); |
| 539 | |
| 540 | // Check whether grouping is the sibling of uses. |
| 541 | YangGrouping yangGrouping1 = (YangGrouping) yangUses1.getNextSibling(); |
| 542 | assertThat(yangGrouping1.getName(), is("FirstClass")); |
| 543 | |
| 544 | // Check whether uses is the child of grouping. |
| 545 | YangUses yangUses2 = (YangUses) yangGrouping1.getChild(); |
| 546 | assertThat(yangUses2.getName(), is("PassingClass")); |
| 547 | |
| 548 | // Check the uses gets resolved. |
| 549 | assertThat(yangUses2.getResolvableStatus(), |
| 550 | is(ResolvableStatus.RESOLVED)); |
| 551 | |
| 552 | // Check whether grouping is the sibling of list. |
| 553 | YangGrouping yangGrouping2 = (YangGrouping) yangList.getNextSibling(); |
| 554 | assertThat(yangGrouping2.getName(), is("PassingClass")); |
| 555 | |
| 556 | // Check uses is the child of that grouping which has prefix of the same module. |
| 557 | YangUses yangUses3 = (YangUses) yangGrouping2.getChild(); |
| 558 | assertThat(yangUses3.getName(), is("Percentage")); |
| 559 | |
| 560 | // Check uses is getting resolved. |
| 561 | assertThat(yangUses3.getResolvableStatus(), |
| 562 | is(ResolvableStatus.RESOLVED)); |
| 563 | |
| 564 | // Check grouping is the child of module. |
| 565 | YangGrouping yangGrouping3 = (YangGrouping) node.getChild(); |
| 566 | |
| 567 | ListIterator<YangLeaf> leafIterator; |
| 568 | YangLeaf leafInfo; |
| 569 | leafIterator = yangGrouping3.getListOfLeaf().listIterator(); |
| 570 | leafInfo = leafIterator.next(); |
| 571 | |
| 572 | // Check whether the information in the leaf is correct under grouping. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 573 | assertThat(leafInfo.getName(), is("hello")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 574 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 575 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 576 | |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Checks self resolution when some type uses prefix of self module |
| 581 | * some uses external prefix. |
| 582 | */ |
| 583 | @Test |
| 584 | public void processSelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix() |
| 585 | throws IOException, ParserException { |
| 586 | |
| 587 | YangNode node = manager |
| 588 | .getDataModel("src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang"); |
| 589 | |
| 590 | // Check whether the data model tree returned is of type module. |
| 591 | assertThat((node instanceof YangModule), is(true)); |
| 592 | |
| 593 | // Check whether the node type is set properly to module. |
| 594 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 595 | |
| 596 | // Check whether the module name is set correctly. |
| 597 | YangModule yangNode = (YangModule) node; |
| 598 | assertThat(yangNode.getName(), is("Test")); |
| 599 | |
| 600 | // Check whether container is the sibling of grouping. |
| 601 | YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); |
| 602 | |
| 603 | // Check whether list is the child of container. |
| 604 | YangList yangList = (YangList) yangContainer.getChild(); |
| 605 | |
| 606 | // Check whether uses is the child of list. |
| 607 | assertThat((yangList.getChild() instanceof YangUses), is(true)); |
| 608 | YangUses yangUses1 = (YangUses) yangList.getChild(); |
| 609 | assertThat(yangUses1.getName(), is("FirstClass")); |
| 610 | |
| 611 | // Check whether uses is getting resolved. |
| 612 | assertThat(yangUses1.getResolvableStatus(), |
| 613 | is(ResolvableStatus.RESOLVED)); |
| 614 | |
| 615 | // Check whether grouping is the sibling of uses. |
| 616 | YangGrouping yangGrouping1 = (YangGrouping) yangUses1.getNextSibling(); |
| 617 | assertThat(yangGrouping1.getName(), is("FirstClass")); |
| 618 | |
| 619 | // Check whether uses is the child of grouping which has prefix from other module. |
| 620 | YangUses yangUses2 = (YangUses) yangGrouping1.getChild(); |
| 621 | assertThat(yangUses2.getName(), is("PassingClass")); |
| 622 | |
| 623 | // Check whether uses gets intra-file-resolved. |
| 624 | assertThat(yangUses2.getResolvableStatus(), |
| 625 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); |
| 626 | |
| 627 | // Check whether grouping is the sibling of list. |
| 628 | YangGrouping yangGrouping2 = (YangGrouping) yangList.getNextSibling(); |
| 629 | assertThat(yangGrouping2.getName(), is("PassingClass")); |
| 630 | |
| 631 | // Check uses is the child of that grouping which has prefix of the same module. |
| 632 | YangUses yangUses3 = (YangUses) yangGrouping2.getChild(); |
| 633 | assertThat(yangUses3.getName(), is("Percentage")); |
| 634 | |
| 635 | // Check uses is getting resolved. |
| 636 | assertThat(yangUses3.getResolvableStatus(), |
| 637 | is(ResolvableStatus.RESOLVED)); |
| 638 | |
| 639 | // Check grouping is the child of module. |
| 640 | YangGrouping yangGrouping3 = (YangGrouping) node.getChild(); |
| 641 | ListIterator<YangLeaf> leafIterator; |
| 642 | YangLeaf leafInfo; |
| 643 | leafIterator = yangGrouping3.getListOfLeaf().listIterator(); |
| 644 | leafInfo = leafIterator.next(); |
| 645 | |
| 646 | // Check whether the information in the leaf is correct under grouping. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 647 | assertThat(leafInfo.getName(), is("hello")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 648 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 649 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 650 | } |
| 651 | |
| 652 | } |