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