Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * 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, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.yangutils.plugin.manager; |
| 18 | |
| 19 | import java.io.IOException; |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.apache.maven.plugin.MojoExecutionException; |
| 23 | import org.junit.Test; |
| 24 | import org.onosproject.yangutils.datamodel.ResolvableType; |
| 25 | import org.onosproject.yangutils.datamodel.YangAugment; |
| 26 | import org.onosproject.yangutils.datamodel.YangNode; |
| 27 | import org.onosproject.yangutils.datamodel.YangReferenceResolver; |
| 28 | import org.onosproject.yangutils.datamodel.YangResolutionInfo; |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 29 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.linker.impl.YangLinkerManager; |
| 31 | import org.onosproject.yangutils.linker.impl.YangXpathLinker; |
| 32 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
| 33 | |
| 34 | import static org.hamcrest.MatcherAssert.assertThat; |
| 35 | import static org.hamcrest.core.Is.is; |
| 36 | |
| 37 | /** |
| 38 | * Unit test cases for x-path linker. |
| 39 | */ |
| 40 | public class YangXpathLinkerTest { |
| 41 | |
| 42 | private YangUtilManager utilManager = new YangUtilManager(); |
| 43 | private YangXpathLinker linker = new YangXpathLinker(); |
| 44 | private YangLinkerManager linkerManager = new YangLinkerManager(); |
| 45 | private static final String INTRA_FILE_PATH = "src/test/resources/xPathLinker/IntraFile/"; |
| 46 | private static final String INTER_FILE_PATH = "src/test/resources/xPathLinker/InterFile/"; |
| 47 | |
| 48 | /** |
| 49 | * Unit test case for intra file linking for single level container. |
| 50 | * |
| 51 | * @throws IOException when fails to do IO operations |
| 52 | * @throws MojoExecutionException |
| 53 | */ |
| 54 | @Test |
| 55 | public void processIntraFileLinkingSingleLevel() throws IOException, MojoExecutionException { |
| 56 | |
| 57 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingle/")); |
| 58 | utilManager.parseYangFileInfoSet(); |
| 59 | utilManager.createYangNodeSet(); |
| 60 | utilManager.resolveDependenciesUsingLinker(); |
| 61 | |
| 62 | YangNode targetNode = null; |
| 63 | String targetNodeName = null; |
| 64 | |
| 65 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 66 | YangReferenceResolver ref = (YangReferenceResolver) node; |
| 67 | List<YangResolutionInfo> infos = ref.getUnresolvedResolutionList(ResolvableType.YANG_AUGMENT); |
| 68 | YangResolutionInfo info = infos.get(0); |
| 69 | |
| 70 | YangAugment augment = (YangAugment) info.getEntityToResolveInfo().getEntityToResolve(); |
| 71 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 72 | .getName(); |
| 73 | targetNode = augment.getAugmentedNode(); |
| 74 | |
| 75 | } |
| 76 | |
| 77 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Unit test case for intra file linking for multiple level container. |
| 82 | * |
| 83 | * @throws IOException when fails to do IO operations |
| 84 | */ |
| 85 | @Test |
| 86 | public void processIntraFileLinkingMultipleLevel() throws IOException { |
| 87 | |
| 88 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMulti/")); |
| 89 | utilManager.parseYangFileInfoSet(); |
| 90 | utilManager.createYangNodeSet(); |
| 91 | |
| 92 | YangNode targetNode = null; |
| 93 | String targetNodeName = null; |
| 94 | |
| 95 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 96 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 97 | |
| 98 | for (YangAugment augment : augments) { |
| 99 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 100 | .getName(); |
| 101 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Unit test case for intra file linking for single level augment. |
| 110 | * |
| 111 | * @throws IOException when fails to do IO operations |
| 112 | */ |
| 113 | @Test |
| 114 | public void processIntraFileLinkingInAugmentSingleLevel() throws IOException { |
| 115 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleAugment/")); |
| 116 | utilManager.parseYangFileInfoSet(); |
| 117 | utilManager.createYangNodeSet(); |
| 118 | |
| 119 | YangNode targetNode = null; |
| 120 | String targetNodeName = null; |
| 121 | |
| 122 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 123 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 124 | |
| 125 | for (YangAugment augment : augments) { |
| 126 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 127 | .getName(); |
| 128 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Unit test case for intra file linking for multiple level augment. |
| 137 | * |
| 138 | * @throws IOException when fails to do IO operations |
| 139 | */ |
| 140 | @Test |
| 141 | public void processIntraFileLinkingInAugmentMultiLevel() throws IOException { |
| 142 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiAugment/")); |
| 143 | utilManager.parseYangFileInfoSet(); |
| 144 | utilManager.createYangNodeSet(); |
| 145 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 146 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 147 | linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 148 | linkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 149 | |
| 150 | YangNode targetNode = null; |
| 151 | String targetNodeName = null; |
| 152 | |
| 153 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 154 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 155 | |
| 156 | for (YangAugment augment : augments) { |
| 157 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 158 | .getName(); |
| 159 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 164 | |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Unit test case for intra file linking for multiple level submodule. |
| 169 | * |
| 170 | * @throws IOException when fails to do IO operations |
| 171 | */ |
| 172 | @Test |
| 173 | public void processIntraFileLinkingInSubModuleSingleLevel() throws IOException { |
| 174 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleSubModule/")); |
| 175 | utilManager.parseYangFileInfoSet(); |
| 176 | utilManager.createYangNodeSet(); |
| 177 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 178 | linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet()); |
| 179 | linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 180 | |
| 181 | YangNode targetNode = null; |
| 182 | String targetNodeName = null; |
| 183 | |
| 184 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 185 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 186 | |
| 187 | for (YangAugment augment : augments) { |
| 188 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 189 | .getName(); |
| 190 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Unit test case for intra file linking for multiple level submodule. |
| 199 | * |
| 200 | * @throws IOException when fails to do IO operations |
| 201 | */ |
| 202 | @Test |
| 203 | public void processIntraFileLinkingInSubModuleMultiLevel() throws IOException { |
| 204 | |
| 205 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiSubModule/")); |
| 206 | utilManager.parseYangFileInfoSet(); |
| 207 | utilManager.createYangNodeSet(); |
| 208 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 209 | linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet()); |
| 210 | linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 211 | |
| 212 | YangNode targetNode = null; |
| 213 | String targetNodeName = null; |
| 214 | |
| 215 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 216 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 217 | |
| 218 | for (YangAugment augment : augments) { |
| 219 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 220 | .getName(); |
| 221 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Unit test case for intra file linking for single level uses. |
| 230 | * |
| 231 | * @throws IOException when fails to do IO operations |
| 232 | */ |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 233 | @Test(expected = LinkerException.class) |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 234 | public void processIntraFileLinkingInUsesSingleLevel() throws IOException { |
| 235 | |
| 236 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/")); |
| 237 | utilManager.parseYangFileInfoSet(); |
| 238 | utilManager.createYangNodeSet(); |
| 239 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 240 | linkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 241 | |
| 242 | YangNode targetNode = null; |
| 243 | String targetNodeName = null; |
| 244 | |
| 245 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 246 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 247 | |
| 248 | for (YangAugment augment : augments) { |
| 249 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 250 | .getName(); |
| 251 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Unit test case for intra file linking for multi level uses. |
| 260 | * |
| 261 | * @throws IOException when fails to do IO operations |
| 262 | */ |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 263 | @Test(expected = LinkerException.class) |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 264 | public void processIntraFileLinkingInUsesMultiLevel() throws IOException { |
| 265 | |
| 266 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/")); |
| 267 | utilManager.parseYangFileInfoSet(); |
| 268 | utilManager.createYangNodeSet(); |
| 269 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 270 | linkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 271 | |
| 272 | YangNode targetNode = null; |
| 273 | String targetNodeName = null; |
| 274 | |
| 275 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 276 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 277 | |
| 278 | for (YangAugment augment : augments) { |
| 279 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 280 | .getName(); |
| 281 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Unit test case for inter file linking for single level container. |
| 290 | * |
| 291 | * @throws IOException when fails to do IO operations |
| 292 | */ |
| 293 | @Test |
| 294 | public void processInterFileLinkingSingleLevel() throws IOException { |
| 295 | |
| 296 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingle/")); |
| 297 | utilManager.parseYangFileInfoSet(); |
| 298 | utilManager.createYangNodeSet(); |
| 299 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 300 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 301 | |
| 302 | YangNode targetNode = null; |
| 303 | String targetNodeName = null; |
| 304 | |
| 305 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 306 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 307 | |
| 308 | for (YangAugment augment : augments) { |
| 309 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 310 | .getName(); |
| 311 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * Unit test case for inter file linking for multi level container. |
| 320 | * |
| 321 | * @throws IOException when fails to do IO operations |
| 322 | */ |
| 323 | @Test |
| 324 | public void processInterFileLinkingMultipleLevel() throws IOException { |
| 325 | |
| 326 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMulti/")); |
| 327 | utilManager.parseYangFileInfoSet(); |
| 328 | utilManager.createYangNodeSet(); |
| 329 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 330 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 331 | |
| 332 | YangNode targetNode = null; |
| 333 | String targetNodeName = null; |
| 334 | |
| 335 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 336 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 337 | |
| 338 | for (YangAugment augment : augments) { |
| 339 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 340 | .getName(); |
| 341 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Unit test case for inter file linking for single level augment. |
| 350 | * |
| 351 | * @throws IOException when fails to do IO operations |
| 352 | */ |
| 353 | @Test |
| 354 | public void processInterFileLinkingInAugmentSingleLevel() throws IOException { |
| 355 | |
| 356 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleAugment/")); |
| 357 | utilManager.parseYangFileInfoSet(); |
| 358 | utilManager.createYangNodeSet(); |
| 359 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 360 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 361 | |
| 362 | YangNode targetNode = null; |
| 363 | String targetNodeName = null; |
| 364 | |
| 365 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 366 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 367 | |
| 368 | for (YangAugment augment : augments) { |
| 369 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 370 | .getName(); |
| 371 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Unit test case for inter file linking for multi level augment. |
| 380 | * |
| 381 | * @throws IOException when fails to do IO operations |
| 382 | */ |
| 383 | @Test |
| 384 | public void processInterFileLinkingInAugmentMultiLevel() throws IOException { |
| 385 | |
| 386 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiAugment/")); |
| 387 | utilManager.parseYangFileInfoSet(); |
| 388 | utilManager.createYangNodeSet(); |
| 389 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 390 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 391 | |
| 392 | YangNode targetNode = null; |
| 393 | String targetNodeName = null; |
| 394 | |
| 395 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 396 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 397 | |
| 398 | for (YangAugment augment : augments) { |
| 399 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 400 | .getName(); |
| 401 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 406 | } |
| 407 | |
| 408 | /** |
| 409 | * Unit test case for multipler inter file linking for single level augment. |
| 410 | * |
| 411 | * @throws IOException when fails to do IO operations |
| 412 | */ |
| 413 | @Test |
| 414 | public void processMultiInterFileLinkingInAugmentSingleLevel() throws IOException { |
| 415 | |
| 416 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugment/")); |
| 417 | utilManager.parseYangFileInfoSet(); |
| 418 | utilManager.createYangNodeSet(); |
| 419 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 420 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 421 | |
| 422 | YangNode targetNode = null; |
| 423 | String targetNodeName = null; |
| 424 | |
| 425 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 426 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 427 | |
| 428 | for (YangAugment augment : augments) { |
| 429 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 430 | .getName(); |
| 431 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Unit test case for multiple inter file linking for multi level augment. |
| 440 | * |
| 441 | * @throws IOException when fails to do IO operations |
| 442 | */ |
| 443 | @Test |
| 444 | public void processMultiInterFileLinkingInAugmentMultiLevel() throws IOException { |
| 445 | |
| 446 | utilManager |
| 447 | .createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugmentMulti/")); |
| 448 | utilManager.parseYangFileInfoSet(); |
| 449 | utilManager.createYangNodeSet(); |
| 450 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 451 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 452 | |
| 453 | YangNode targetNode = null; |
| 454 | String targetNodeName = null; |
| 455 | |
| 456 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 457 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 458 | |
| 459 | for (YangAugment augment : augments) { |
| 460 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 461 | .getName(); |
| 462 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Unit test case for inter file linking for single level submodule. |
| 471 | * |
| 472 | * @throws IOException when fails to do IO operations |
| 473 | */ |
| 474 | @Test |
| 475 | public void processInterFileLinkingInSubModuleSingleLevel() throws IOException { |
| 476 | |
| 477 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleSubModule/")); |
| 478 | utilManager.parseYangFileInfoSet(); |
| 479 | utilManager.createYangNodeSet(); |
| 480 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 481 | linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet()); |
| 482 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 483 | linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 484 | |
| 485 | YangNode targetNode = null; |
| 486 | String targetNodeName = null; |
| 487 | |
| 488 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 489 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 490 | |
| 491 | for (YangAugment augment : augments) { |
| 492 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 493 | .getName(); |
| 494 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Unit test case for inter file linking for multi level submodule. |
| 503 | * |
| 504 | * @throws IOException when fails to do IO operations |
| 505 | */ |
| 506 | @Test |
| 507 | public void processInterFileLinkingInSubModuleMultiLevel() throws IOException { |
| 508 | |
| 509 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiSubModule/")); |
| 510 | utilManager.parseYangFileInfoSet(); |
| 511 | utilManager.createYangNodeSet(); |
| 512 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 513 | linkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet()); |
| 514 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 515 | linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 516 | linkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 517 | YangNode targetNode = null; |
| 518 | String targetNodeName = null; |
| 519 | |
| 520 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 521 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 522 | |
| 523 | for (YangAugment augment : augments) { |
| 524 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 525 | .getName(); |
| 526 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Unit test case for inter file linking for multi level uses inside augment. |
| 535 | * |
| 536 | * @throws IOException when fails to do IO operations |
| 537 | */ |
| 538 | @Test |
| 539 | public void processInterFileLinkingInUsesInAugment() throws IOException { |
| 540 | |
| 541 | /* FIXME: when uses cloning is done test it. |
| 542 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleUses/")); |
| 543 | utilManager.parseYangFileInfoSet(); |
| 544 | utilManager.createYangNodeSet(); |
| 545 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 546 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 547 | linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 548 | linkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 549 | |
| 550 | YangNode targetNode = null; |
| 551 | String targetNodeName = null; |
| 552 | |
| 553 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 554 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 555 | |
| 556 | for (YangAugment augment : augments) { |
| 557 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1) |
| 558 | .getNodeIdentifier().getName(); |
| 559 | targetNode = linker.processXpathLinking(augment.getTargetNode(), node); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 564 | */ |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Unit test case for inter file linking for multi level uses. |
| 569 | * |
| 570 | * @throws IOException when fails to do IO operations |
| 571 | */ |
Vidyashree Rama | 405d2e6 | 2016-07-08 20:45:41 +0530 | [diff] [blame^] | 572 | @Test(expected = LinkerException.class) |
Bharat saraswal | b1170bd | 2016-07-14 13:26:18 +0530 | [diff] [blame] | 573 | public void processInterFileLinkingInUsesMultiLevel() throws IOException { |
| 574 | |
| 575 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiUses/")); |
| 576 | utilManager.parseYangFileInfoSet(); |
| 577 | utilManager.createYangNodeSet(); |
| 578 | linkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 579 | linkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 580 | linkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 581 | linkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 582 | |
| 583 | YangNode targetNode = null; |
| 584 | String targetNodeName = null; |
| 585 | |
| 586 | for (YangNode node : utilManager.getYangNodeSet()) { |
| 587 | List<YangAugment> augments = linker.getListOfYangAugment(node); |
| 588 | |
| 589 | for (YangAugment augment : augments) { |
| 590 | targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier() |
| 591 | .getName(); |
| 592 | targetNode = linker.processAugmentXpathLinking(augment.getTargetNode(), node); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | assertThat(true, is(targetNode.getName().equals(targetNodeName))); |
| 597 | } |
| 598 | |
| 599 | } |