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