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 | |
| 17 | package org.onosproject.yangutils.linker; |
| 18 | |
| 19 | import java.io.IOException; |
| 20 | import java.util.ListIterator; |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 21 | |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 22 | import org.junit.Rule; |
| 23 | import org.junit.Test; |
| 24 | import org.junit.rules.ExpectedException; |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangContainer; |
| 26 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
| 27 | import org.onosproject.yangutils.datamodel.YangGrouping; |
| 28 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 29 | import org.onosproject.yangutils.datamodel.YangList; |
| 30 | import org.onosproject.yangutils.datamodel.YangModule; |
| 31 | import org.onosproject.yangutils.datamodel.YangNode; |
| 32 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| 33 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
| 34 | import org.onosproject.yangutils.datamodel.YangUses; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 35 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 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 | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 83 | assertThat(leafInfo.getName(), is("hello")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 84 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 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 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 95 | // leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 96 | // leafInfo = leafIterator.next(); |
| 97 | // |
| 98 | // // Check whether the information in the leaf is correct under module. |
| 99 | // assertThat(leafInfo.getName(), is("hello")); |
| 100 | // assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
| 101 | // assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 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 | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 137 | assertThat(leafInfo.getName(), is("treat")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 138 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 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 | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 152 | assertThat(leafInfo.getName(), is("leaf2")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 153 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 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 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 164 | // leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 165 | // leafInfo = leafIterator.next(); |
| 166 | // |
| 167 | // // Check whether the information in the leaf is correct under module. |
| 168 | // assertThat(leafInfo.getName(), is("treat")); |
| 169 | // assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
| 170 | // assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 171 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 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. |
| 183 | // assertThat(leafInfo.getName(), is("leaf2")); |
| 184 | // assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
| 185 | // assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 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 | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 230 | assertThat(leafInfo.getName(), is("invalid-interval")); |
janani b | 4e53f9b | 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 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 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. |
| 256 | // assertThat(leafInfo.getName(), is("invalid-interval")); |
| 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. |
| 285 | // assertThat(leafInfo.getName(), is("invalid-interval")); |
| 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\"")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Checks the failure scenario when uses is referring to its own grouping directly. |
| 294 | */ |
| 295 | @Test |
| 296 | public void processSelfResolutionGroupingReferencingItselfFailureScenerio() |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 297 | throws IOException { |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 298 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 299 | thrown.expect(LinkerException.class); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 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 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 352 | // leafIterator = yangContainer.getListOfLeaf().listIterator(); |
| 353 | // leafInfo = leafIterator.next(); |
| 354 | // |
| 355 | // // Check whether the information in the leaf is correct under design-container. |
| 356 | // assertThat(leafInfo.getName(), is("ink")); |
| 357 | // assertThat(leafInfo.getDataType().getDataTypeName(), is("int32")); |
| 358 | // assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.INT32)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 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 | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 377 | assertThat(leafInfo.getName(), is("newone")); |
janani b | 4e53f9b | 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 | |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 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. |
| 400 | // assertThat(leafInfo.getName(), is("zip-code")); |
| 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. |
| 429 | // assertThat(leafInfo.getName(), is("invalid-interval")); |
| 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. |
| 444 | // assertThat(leafInfo.getName(), is("zip-code")); |
| 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")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 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 | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 520 | assertThat(leafInfo.getName(), is("carry")); |
janani b | 4e53f9b | 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)); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Checks the failure scenario when uses is cannot resolve its grouping. |
| 547 | */ |
| 548 | @Test |
| 549 | public void processSelfResolutionNestedGroupingWithUnresolvedUses() |
| 550 | throws IOException, ParserException { |
| 551 | |
| 552 | thrown.expect(ParserException.class); |
| 553 | thrown.expectMessage( |
Vidyashree Rama | 210c01d | 2016-05-20 16:29:25 +0530 | [diff] [blame] | 554 | "YANG file error: Unable to find base grouping for given uses"); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 555 | |
| 556 | YangNode node = manager |
| 557 | .getDataModel("src/test/resources/SelfResolutionNestedGroupingWithUnresolvedUses.yang"); |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Checks self resolution when typedef hierarchical references are present |
| 562 | * with last type is unresolved. |
| 563 | */ |
| 564 | @Test |
| 565 | public void processSelfFileLinkingWithGroupingHierarchicalRefUnresolved() |
| 566 | throws IOException, ParserException { |
| 567 | |
| 568 | YangNode node = manager |
| 569 | .getDataModel("src/test/resources/SelfFileLinkingWithGroupingHierarchicalRefUnresolved.yang"); |
| 570 | |
| 571 | // Check whether the data model tree returned is of type module. |
| 572 | assertThat((node instanceof YangModule), is(true)); |
| 573 | |
| 574 | // Check whether the node type is set properly to module. |
| 575 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 576 | |
| 577 | // Check whether the module name is set correctly. |
| 578 | YangModule yangNode = (YangModule) node; |
| 579 | assertThat(yangNode.getName(), is("Test")); |
| 580 | |
| 581 | // Check whether container is the sibling of grouping. |
| 582 | assertThat((yangNode.getChild().getNextSibling() instanceof YangContainer), is(true)); |
| 583 | YangContainer containerWithUses = (YangContainer) yangNode.getChild().getNextSibling(); |
| 584 | assertThat(containerWithUses.getName(), is("test")); |
| 585 | |
| 586 | // Check whether uses is the child of container. |
| 587 | assertThat((containerWithUses.getChild() instanceof YangUses), is(true)); |
| 588 | YangUses uses = (YangUses) containerWithUses.getChild(); |
| 589 | assertThat(uses.getName(), is("create")); |
| 590 | |
| 591 | // Check whether uses is getting resolved. |
| 592 | assertThat(uses.getResolvableStatus(), |
| 593 | is(ResolvableStatus.RESOLVED)); |
| 594 | |
| 595 | // Check whether grouping is the child of module. |
| 596 | assertThat((yangNode.getChild() instanceof YangGrouping), is(true)); |
| 597 | YangGrouping groupingWithUses = (YangGrouping) yangNode.getChild(); |
| 598 | assertThat(groupingWithUses.getName(), is("create")); |
| 599 | |
| 600 | // Check whether uses with prefix from from other file, is the child of grouping. |
| 601 | assertThat((groupingWithUses.getChild() instanceof YangUses), is(true)); |
| 602 | YangUses uses1 = (YangUses) groupingWithUses.getChild(); |
| 603 | assertThat(uses1.getName(), is("valid")); |
| 604 | |
| 605 | // Check whether this uses is getting intra-file-resolved. |
| 606 | assertThat(uses1.getResolvableStatus(), |
| 607 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Checks self resolution when uses has prefix of self module. |
| 612 | */ |
| 613 | @Test |
| 614 | public void processSelfFileLinkingWithGroupingWithSelfModulePrefix() |
| 615 | throws IOException, ParserException { |
| 616 | |
| 617 | YangNode node = manager.getDataModel("src/test/resources/SelfFileLinkingWithGroupingWithSelfModulePrefix.yang"); |
| 618 | |
| 619 | // Check whether the data model tree returned is of type module. |
| 620 | assertThat((node instanceof YangModule), is(true)); |
| 621 | |
| 622 | // Check whether the node type is set properly to module. |
| 623 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 624 | |
| 625 | // Check whether the module name is set correctly. |
| 626 | YangModule yangNode = (YangModule) node; |
| 627 | assertThat(yangNode.getName(), is("Test")); |
| 628 | |
| 629 | // Check whether container is the sibling of grouping. |
| 630 | YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); |
| 631 | |
| 632 | // Check whether list is the child of container. |
| 633 | YangList yangList = (YangList) yangContainer.getChild(); |
| 634 | |
| 635 | // Check whether uses is the child of list. |
| 636 | assertThat((yangList.getChild() instanceof YangUses), is(true)); |
| 637 | YangUses yangUses1 = (YangUses) yangList.getChild(); |
| 638 | assertThat(yangUses1.getName(), is("FirstClass")); |
| 639 | |
| 640 | // Check whether uses is getting resolved. |
| 641 | assertThat(yangUses1.getResolvableStatus(), |
| 642 | is(ResolvableStatus.RESOLVED)); |
| 643 | |
| 644 | // Check whether grouping is the sibling of uses. |
| 645 | YangGrouping yangGrouping1 = (YangGrouping) yangUses1.getNextSibling(); |
| 646 | assertThat(yangGrouping1.getName(), is("FirstClass")); |
| 647 | |
| 648 | // Check whether uses is the child of grouping. |
| 649 | YangUses yangUses2 = (YangUses) yangGrouping1.getChild(); |
| 650 | assertThat(yangUses2.getName(), is("PassingClass")); |
| 651 | |
| 652 | // Check the uses gets resolved. |
| 653 | assertThat(yangUses2.getResolvableStatus(), |
| 654 | is(ResolvableStatus.RESOLVED)); |
| 655 | |
| 656 | // Check whether grouping is the sibling of list. |
| 657 | YangGrouping yangGrouping2 = (YangGrouping) yangList.getNextSibling(); |
| 658 | assertThat(yangGrouping2.getName(), is("PassingClass")); |
| 659 | |
| 660 | // Check uses is the child of that grouping which has prefix of the same module. |
| 661 | YangUses yangUses3 = (YangUses) yangGrouping2.getChild(); |
| 662 | assertThat(yangUses3.getName(), is("Percentage")); |
| 663 | |
| 664 | // Check uses is getting resolved. |
| 665 | assertThat(yangUses3.getResolvableStatus(), |
| 666 | is(ResolvableStatus.RESOLVED)); |
| 667 | |
| 668 | // Check grouping is the child of module. |
| 669 | YangGrouping yangGrouping3 = (YangGrouping) node.getChild(); |
| 670 | |
| 671 | ListIterator<YangLeaf> leafIterator; |
| 672 | YangLeaf leafInfo; |
| 673 | leafIterator = yangGrouping3.getListOfLeaf().listIterator(); |
| 674 | leafInfo = leafIterator.next(); |
| 675 | |
| 676 | // Check whether the information in the leaf is correct under grouping. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 677 | assertThat(leafInfo.getName(), is("hello")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 678 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 679 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 680 | |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Checks self resolution when some type uses prefix of self module |
| 685 | * some uses external prefix. |
| 686 | */ |
| 687 | @Test |
| 688 | public void processSelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix() |
| 689 | throws IOException, ParserException { |
| 690 | |
| 691 | YangNode node = manager |
| 692 | .getDataModel("src/test/resources/SelfFileLinkingWithGroupingWithSelfAndExternalPrefixMix.yang"); |
| 693 | |
| 694 | // Check whether the data model tree returned is of type module. |
| 695 | assertThat((node instanceof YangModule), is(true)); |
| 696 | |
| 697 | // Check whether the node type is set properly to module. |
| 698 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 699 | |
| 700 | // Check whether the module name is set correctly. |
| 701 | YangModule yangNode = (YangModule) node; |
| 702 | assertThat(yangNode.getName(), is("Test")); |
| 703 | |
| 704 | // Check whether container is the sibling of grouping. |
| 705 | YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); |
| 706 | |
| 707 | // Check whether list is the child of container. |
| 708 | YangList yangList = (YangList) yangContainer.getChild(); |
| 709 | |
| 710 | // Check whether uses is the child of list. |
| 711 | assertThat((yangList.getChild() instanceof YangUses), is(true)); |
| 712 | YangUses yangUses1 = (YangUses) yangList.getChild(); |
| 713 | assertThat(yangUses1.getName(), is("FirstClass")); |
| 714 | |
| 715 | // Check whether uses is getting resolved. |
| 716 | assertThat(yangUses1.getResolvableStatus(), |
| 717 | is(ResolvableStatus.RESOLVED)); |
| 718 | |
| 719 | // Check whether grouping is the sibling of uses. |
| 720 | YangGrouping yangGrouping1 = (YangGrouping) yangUses1.getNextSibling(); |
| 721 | assertThat(yangGrouping1.getName(), is("FirstClass")); |
| 722 | |
| 723 | // Check whether uses is the child of grouping which has prefix from other module. |
| 724 | YangUses yangUses2 = (YangUses) yangGrouping1.getChild(); |
| 725 | assertThat(yangUses2.getName(), is("PassingClass")); |
| 726 | |
| 727 | // Check whether uses gets intra-file-resolved. |
| 728 | assertThat(yangUses2.getResolvableStatus(), |
| 729 | is(ResolvableStatus.INTRA_FILE_RESOLVED)); |
| 730 | |
| 731 | // Check whether grouping is the sibling of list. |
| 732 | YangGrouping yangGrouping2 = (YangGrouping) yangList.getNextSibling(); |
| 733 | assertThat(yangGrouping2.getName(), is("PassingClass")); |
| 734 | |
| 735 | // Check uses is the child of that grouping which has prefix of the same module. |
| 736 | YangUses yangUses3 = (YangUses) yangGrouping2.getChild(); |
| 737 | assertThat(yangUses3.getName(), is("Percentage")); |
| 738 | |
| 739 | // Check uses is getting resolved. |
| 740 | assertThat(yangUses3.getResolvableStatus(), |
| 741 | is(ResolvableStatus.RESOLVED)); |
| 742 | |
| 743 | // Check grouping is the child of module. |
| 744 | YangGrouping yangGrouping3 = (YangGrouping) node.getChild(); |
| 745 | ListIterator<YangLeaf> leafIterator; |
| 746 | YangLeaf leafInfo; |
| 747 | leafIterator = yangGrouping3.getListOfLeaf().listIterator(); |
| 748 | leafInfo = leafIterator.next(); |
| 749 | |
| 750 | // Check whether the information in the leaf is correct under grouping. |
Vinod Kumar S | e4b9b0c | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 751 | assertThat(leafInfo.getName(), is("hello")); |
Gaurav Agrawal | cfa1c41 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 752 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
janani b | 4e53f9b | 2016-04-26 18:49:20 +0530 | [diff] [blame] | 753 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 754 | } |
| 755 | |
| 756 | } |