Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +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 | package org.onosproject.yangutils.plugin.manager; |
| 17 | |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 18 | import java.io.IOException; |
| 19 | import java.util.ListIterator; |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 20 | import org.apache.maven.plugin.MojoExecutionException; |
| 21 | import org.junit.Rule; |
| 22 | import org.junit.Test; |
| 23 | import org.junit.rules.ExpectedException; |
| 24 | import org.onosproject.yangutils.datamodel.YangIdentity; |
| 25 | import org.onosproject.yangutils.datamodel.YangIdentityRef; |
| 26 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 27 | import org.onosproject.yangutils.datamodel.YangLeafList; |
| 28 | import org.onosproject.yangutils.datamodel.YangModule; |
| 29 | import org.onosproject.yangutils.datamodel.YangNode; |
| 30 | import org.onosproject.yangutils.datamodel.YangType; |
| 31 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
| 32 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
| 33 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
| 34 | import org.onosproject.yangutils.linker.exceptions.LinkerException; |
| 35 | import org.onosproject.yangutils.linker.impl.YangLinkerManager; |
| 36 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 37 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
| 38 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 39 | import static org.hamcrest.MatcherAssert.assertThat; |
| 40 | import static org.hamcrest.core.Is.is; |
| 41 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 42 | import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority; |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Test cases for testing inter file linking for identity. |
| 46 | */ |
| 47 | public class InterFileIdentityLinkingTest { |
| 48 | @Rule |
| 49 | public ExpectedException thrown = ExpectedException.none(); |
| 50 | |
| 51 | private final YangUtilManager utilManager = new YangUtilManager(); |
| 52 | private final YangLinkerManager yangLinkerManager = new YangLinkerManager(); |
| 53 | |
| 54 | /** |
| 55 | * Checks inter file feature linking with imported file. |
| 56 | */ |
| 57 | @Test |
| 58 | public void processIdentityInImportedFile() |
| 59 | throws IOException, ParserException, MojoExecutionException { |
| 60 | |
| 61 | String searchDir = "src/test/resources/interfileidentityimport"; |
| 62 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 63 | utilManager.parseYangFileInfoSet(); |
| 64 | utilManager.createYangNodeSet(); |
| 65 | |
| 66 | YangNode selfNode = null; |
| 67 | YangNode refNode1 = null; |
| 68 | YangNode refNode2 = null; |
| 69 | |
| 70 | // Create YANG node set |
| 71 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 72 | |
| 73 | // Add references to import list. |
| 74 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 75 | |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 76 | updateFilePriority(utilManager.getYangNodeSet()); |
| 77 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 78 | // Carry out inter-file linking. |
| 79 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 80 | |
| 81 | for (YangNode rootNode : utilManager.getYangNodeSet()) { |
| 82 | if (rootNode.getName().equals("IdentityIntraFile")) { |
| 83 | selfNode = rootNode; |
| 84 | } else if (rootNode.getName().equals("IdentityInModule")) { |
| 85 | refNode1 = rootNode; |
| 86 | } else { |
| 87 | refNode2 = rootNode; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // Check whether the data model tree returned is of type module. |
| 92 | assertThat(selfNode instanceof YangModule, is(true)); |
| 93 | |
| 94 | // Check whether the node type is set properly to module. |
| 95 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 96 | |
| 97 | // Check whether the module name is set correctly. |
| 98 | YangModule yangNode = (YangModule) selfNode; |
| 99 | assertThat(yangNode.getName(), is("IdentityIntraFile")); |
| 100 | |
| 101 | YangIdentity yangIdentity = (YangIdentity) yangNode.getChild(); |
| 102 | assertThat(yangIdentity.getName(), is("ipv4-address-family")); |
| 103 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 104 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 105 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 106 | |
| 107 | yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling(); |
| 108 | assertThat(yangIdentity.getName(), is("ipv6-address-family")); |
| 109 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 110 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 111 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 112 | |
| 113 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 114 | YangLeaf leafInfo = leafIterator.next(); |
| 115 | |
| 116 | assertThat(leafInfo.getName(), is("tunnel")); |
| 117 | assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref")); |
| 118 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 119 | YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 120 | assertThat(yangIdentityRef.getName(), is("ref-address-family")); |
| 121 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 122 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 123 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 124 | |
| 125 | ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); |
| 126 | YangLeafList leafListInfo = leafListIterator.next(); |
| 127 | |
| 128 | // Check whether the information in the leaf is correct. |
| 129 | assertThat(leafListInfo.getName(), is("network-ref")); |
| 130 | assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref")); |
| 131 | assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 132 | yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo()); |
| 133 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 134 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 135 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 136 | |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Checks inter file feature linking with included file. |
| 141 | */ |
| 142 | @Test |
| 143 | public void processIdentityInIncludedFile() |
| 144 | throws IOException, ParserException, MojoExecutionException { |
| 145 | |
| 146 | String searchDir = "src/test/resources/interfileidentityinlude"; |
| 147 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 148 | utilManager.parseYangFileInfoSet(); |
| 149 | utilManager.createYangNodeSet(); |
| 150 | |
| 151 | YangNode selfNode = null; |
| 152 | YangNode refNode1 = null; |
| 153 | YangNode refNode2 = null; |
| 154 | |
| 155 | // Create YANG node set |
| 156 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 157 | |
| 158 | // Carry out linking of sub module with module. |
| 159 | yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet()); |
| 160 | |
| 161 | // Add references to import list. |
| 162 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 163 | |
| 164 | // Add references to include list. |
| 165 | yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 166 | |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 167 | updateFilePriority(utilManager.getYangNodeSet()); |
| 168 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 169 | // Carry out inter-file linking. |
| 170 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 171 | |
| 172 | for (YangNode rootNode : utilManager.getYangNodeSet()) { |
| 173 | if (rootNode.getName().equals("syslog3")) { |
| 174 | selfNode = rootNode; |
| 175 | } else if (rootNode.getName().equals("syslog4")) { |
| 176 | refNode1 = rootNode; |
| 177 | } else { |
| 178 | refNode2 = rootNode; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | // Check whether the data model tree returned is of type module. |
| 183 | assertThat(selfNode instanceof YangModule, is(true)); |
| 184 | |
| 185 | // Check whether the node type is set properly to module. |
| 186 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 187 | |
| 188 | // Check whether the module name is set correctly. |
| 189 | YangModule yangNode = (YangModule) selfNode; |
| 190 | assertThat(yangNode.getName(), is("syslog3")); |
| 191 | |
| 192 | YangIdentity yangIdentity = (YangIdentity) yangNode.getChild(); |
| 193 | assertThat(yangIdentity.getName(), is("ipv4-address-family")); |
| 194 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 195 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 196 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 197 | |
| 198 | yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling(); |
| 199 | assertThat(yangIdentity.getName(), is("ipv6-address-family")); |
| 200 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 201 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 202 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 203 | |
| 204 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 205 | YangLeaf leafInfo = leafIterator.next(); |
| 206 | |
| 207 | assertThat(leafInfo.getName(), is("tunnel")); |
| 208 | assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref")); |
| 209 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 210 | YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 211 | assertThat(yangIdentityRef.getName(), is("ref-address-family")); |
| 212 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 213 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 214 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 215 | |
| 216 | ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); |
| 217 | YangLeafList leafListInfo = leafListIterator.next(); |
| 218 | |
| 219 | // Check whether the information in the leaf is correct. |
| 220 | assertThat(leafListInfo.getName(), is("network-ref")); |
| 221 | assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref")); |
| 222 | assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 223 | yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo()); |
| 224 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 225 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 226 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Checks inter file feature linking with imported file with dependency. |
| 231 | */ |
| 232 | @Test |
| 233 | public void processIdentityInImportedFileWithDependency() |
| 234 | throws IOException, ParserException, MojoExecutionException { |
| 235 | |
| 236 | String searchDir = "src/test/resources/interfileidentityimportdependency"; |
| 237 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 238 | utilManager.parseYangFileInfoSet(); |
| 239 | utilManager.createYangNodeSet(); |
| 240 | |
| 241 | YangNode selfNode = null; |
| 242 | YangNode refNode1 = null; |
| 243 | YangNode refNode2 = null; |
| 244 | |
| 245 | // Create YANG node set |
| 246 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 247 | |
| 248 | // Add references to import list. |
| 249 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 250 | |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 251 | updateFilePriority(utilManager.getYangNodeSet()); |
| 252 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 253 | // Carry out inter-file linking. |
| 254 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 255 | |
| 256 | for (YangNode rootNode : utilManager.getYangNodeSet()) { |
| 257 | if (rootNode.getName().equals("syslog1")) { |
| 258 | selfNode = rootNode; |
| 259 | } else if (rootNode.getName().equals("syslog2")) { |
| 260 | refNode1 = rootNode; |
| 261 | } else { |
| 262 | refNode2 = rootNode; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | // Check whether the data model tree returned is of type module. |
| 267 | assertThat(selfNode instanceof YangModule, is(true)); |
| 268 | |
| 269 | // Check whether the node type is set properly to module. |
| 270 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 271 | |
| 272 | // Check whether the module name is set correctly. |
| 273 | YangModule yangNode = (YangModule) selfNode; |
| 274 | assertThat(yangNode.getName(), is("syslog1")); |
| 275 | |
| 276 | YangIdentity yangIdentity = (YangIdentity) yangNode.getChild(); |
| 277 | assertThat(yangIdentity.getName(), is("ipv4-address-family")); |
| 278 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 279 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 280 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 281 | |
| 282 | yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling(); |
| 283 | assertThat(yangIdentity.getName(), is("ipv6-address-family")); |
| 284 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 285 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 286 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 287 | |
| 288 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 289 | YangLeaf leafInfo = leafIterator.next(); |
| 290 | |
| 291 | assertThat(leafInfo.getName(), is("tunnel")); |
| 292 | assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref")); |
| 293 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 294 | YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 295 | assertThat(yangIdentityRef.getName(), is("ref-address-family")); |
| 296 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 297 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 298 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 299 | |
| 300 | ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); |
| 301 | YangLeafList leafListInfo = leafListIterator.next(); |
| 302 | |
| 303 | // Check whether the information in the leaf is correct. |
| 304 | assertThat(leafListInfo.getName(), is("network-ref")); |
| 305 | assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref")); |
| 306 | assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 307 | yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo()); |
| 308 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 309 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 310 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 311 | } |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 312 | |
| 313 | /** |
| 314 | * Checks inter file feature linking with included file with dependency. |
| 315 | */ |
| 316 | @Test |
| 317 | public void processIdentityInIncludedFileWithDependency() |
| 318 | throws IOException, ParserException, MojoExecutionException { |
| 319 | |
| 320 | String searchDir = "src/test/resources/interfileidentityincludedependency"; |
| 321 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 322 | utilManager.parseYangFileInfoSet(); |
| 323 | utilManager.createYangNodeSet(); |
| 324 | |
| 325 | YangNode selfNode = null; |
| 326 | YangNode refNode1 = null; |
| 327 | YangNode refNode2 = null; |
| 328 | |
| 329 | // Create YANG node set |
| 330 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 331 | |
| 332 | // Carry out linking of sub module with module. |
| 333 | yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet()); |
| 334 | |
| 335 | // Add references to include list. |
| 336 | yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 337 | |
| 338 | // Add references to import list. |
| 339 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 340 | |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 341 | updateFilePriority(utilManager.getYangNodeSet()); |
| 342 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 343 | // Carry out inter-file linking. |
| 344 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 345 | |
| 346 | for (YangNode rootNode : utilManager.getYangNodeSet()) { |
| 347 | if (rootNode.getName().equals("syslog1")) { |
| 348 | selfNode = rootNode; |
| 349 | } else if (rootNode.getName().equals("syslog2")) { |
| 350 | refNode1 = rootNode; |
| 351 | } else { |
| 352 | refNode2 = rootNode; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | // Check whether the data model tree returned is of type module. |
| 357 | assertThat(selfNode instanceof YangModule, is(true)); |
| 358 | |
| 359 | // Check whether the node type is set properly to module. |
| 360 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 361 | |
| 362 | // Check whether the module name is set correctly. |
| 363 | YangModule yangNode = (YangModule) selfNode; |
| 364 | assertThat(yangNode.getName(), is("syslog1")); |
| 365 | |
| 366 | YangIdentity yangIdentity = (YangIdentity) yangNode.getChild(); |
| 367 | assertThat(yangIdentity.getName(), is("ipv4-address-family")); |
| 368 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 369 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 370 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 371 | |
| 372 | yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling(); |
| 373 | assertThat(yangIdentity.getName(), is("ipv6-address-family")); |
| 374 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 375 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 376 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 377 | |
| 378 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 379 | YangLeaf leafInfo = leafIterator.next(); |
| 380 | |
| 381 | assertThat(leafInfo.getName(), is("tunnel")); |
| 382 | assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref")); |
| 383 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 384 | YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 385 | assertThat(yangIdentityRef.getName(), is("ref-address-family")); |
| 386 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 387 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 388 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 389 | |
| 390 | ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); |
| 391 | YangLeafList leafListInfo = leafListIterator.next(); |
| 392 | |
| 393 | // Check whether the information in the leaf is correct. |
| 394 | assertThat(leafListInfo.getName(), is("network-ref")); |
| 395 | assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref")); |
| 396 | assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 397 | yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo()); |
| 398 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 399 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 400 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Checks inter file feature linking with imported file with dependency |
| 405 | * feature undefined. |
| 406 | */ |
| 407 | @Test |
| 408 | public void processIdentityInImportedFileWithDependencyUndefined() |
| 409 | throws IOException, LinkerException, MojoExecutionException { |
| 410 | thrown.expect(LinkerException.class); |
| 411 | thrown.expectMessage("YANG file error: Unable to find base identity for given base"); |
| 412 | |
| 413 | String searchDir = "src/test/resources/interfileidentityimportdependencyUndefined"; |
| 414 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 415 | utilManager.parseYangFileInfoSet(); |
| 416 | utilManager.createYangNodeSet(); |
| 417 | |
| 418 | YangNode selfNode = null; |
| 419 | YangNode refNode1 = null; |
| 420 | YangNode refNode2 = null; |
| 421 | |
| 422 | // Create YANG node set |
| 423 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 424 | |
| 425 | // Add references to import list. |
| 426 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 427 | |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 428 | updateFilePriority(utilManager.getYangNodeSet()); |
| 429 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 430 | // Carry out inter-file linking. |
| 431 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Checks inter file feature linking with included file with dependency |
| 436 | * feature undefined. |
| 437 | */ |
| 438 | @Test |
| 439 | public void processIdentityInIncludedFileWithDependencyUndefined() |
| 440 | throws IOException, LinkerException, MojoExecutionException { |
| 441 | thrown.expect(LinkerException.class); |
| 442 | thrown.expectMessage("YANG file error: Unable to find base identity for given base"); |
| 443 | |
| 444 | String searchDir = "src/test/resources/interfileidentityincludedependencyUndefined"; |
| 445 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 446 | utilManager.parseYangFileInfoSet(); |
| 447 | utilManager.createYangNodeSet(); |
| 448 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 449 | // Create YANG node set |
| 450 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 451 | |
| 452 | // Carry out linking of sub module with module. |
| 453 | yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet()); |
| 454 | |
| 455 | // Add references to import list. |
| 456 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 457 | |
| 458 | // Add references to include list. |
| 459 | yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
| 460 | |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 461 | // Update the priority for all the files. |
| 462 | updateFilePriority(utilManager.getYangNodeSet()); |
| 463 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 464 | // Carry out inter-file linking. |
| 465 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * Checks inter file feature linking with imported file. |
| 470 | */ |
| 471 | @Test |
| 472 | public void processIdentityTypedefUnresolvedInImportedFile() |
| 473 | throws IOException, ParserException, MojoExecutionException { |
| 474 | |
| 475 | String searchDir = "src/test/resources/interfileidentitytypedef"; |
| 476 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 477 | utilManager.parseYangFileInfoSet(); |
| 478 | utilManager.createYangNodeSet(); |
| 479 | |
| 480 | YangNode selfNode = null; |
| 481 | YangNode refNode1 = null; |
| 482 | YangNode refNode2 = null; |
| 483 | |
| 484 | // Create YANG node set |
| 485 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 486 | |
| 487 | // Add references to import list. |
| 488 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 489 | |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 490 | updateFilePriority(utilManager.getYangNodeSet()); |
| 491 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 492 | // Carry out inter-file linking. |
| 493 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 494 | |
| 495 | for (YangNode rootNode : utilManager.getYangNodeSet()) { |
| 496 | if (rootNode.getName().equals("IdentityIntraFile")) { |
| 497 | selfNode = rootNode; |
| 498 | } else if (rootNode.getName().equals("IdentityInModule")) { |
| 499 | refNode1 = rootNode; |
| 500 | } else { |
| 501 | refNode2 = rootNode; |
| 502 | } |
| 503 | } |
| 504 | // Check whether the data model tree returned is of type module. |
| 505 | assertThat(selfNode instanceof YangModule, is(true)); |
| 506 | |
| 507 | // Check whether the node type is set properly to module. |
| 508 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 509 | |
| 510 | // Check whether the module name is set correctly. |
| 511 | YangModule yangNode = (YangModule) selfNode; |
| 512 | assertThat(yangNode.getName(), is("IdentityIntraFile")); |
| 513 | |
| 514 | YangIdentity yangIdentity = (YangIdentity) yangNode.getChild(); |
| 515 | assertThat(yangIdentity.getName(), is("ipv4-address-family")); |
| 516 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 517 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 518 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 519 | |
| 520 | yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling(); |
| 521 | assertThat(yangIdentity.getName(), is("ipv6-address-family")); |
| 522 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 523 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 524 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 525 | |
| 526 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 527 | YangLeaf leafInfo = leafIterator.next(); |
| 528 | |
| 529 | assertThat(leafInfo.getName(), is("tunnel")); |
| 530 | assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref")); |
| 531 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 532 | YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 533 | assertThat(yangIdentityRef.getName(), is("ref-address-family")); |
| 534 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 535 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 536 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 537 | |
| 538 | ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); |
| 539 | YangLeafList leafListInfo = leafListIterator.next(); |
| 540 | |
| 541 | // Check whether the information in the leaf is correct. |
| 542 | assertThat(leafListInfo.getName(), is("network-ref")); |
| 543 | assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref")); |
| 544 | assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 545 | yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo()); |
| 546 | // Check whether leafref type got resolved. |
| 547 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 548 | |
| 549 | YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling().getNextSibling(); |
| 550 | assertThat(typedef.getName(), is("type15")); |
| 551 | |
| 552 | YangType type = typedef.getTypeList().iterator().next(); |
| 553 | assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 554 | assertThat(type.getDataTypeName(), is("identityref")); |
| 555 | |
| 556 | YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo(); |
| 557 | assertThat(identityRef.getName(), is("ref-address-family")); |
| 558 | assertThat(identityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 559 | assertThat(identityRef.getResolvableStatus(), is(ResolvableStatus.UNRESOLVED)); |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * Checks inter file feature linking with imported file. |
| 564 | */ |
| 565 | @Test |
| 566 | public void processIdentityTypedefInImportedFile() |
| 567 | throws IOException, ParserException, MojoExecutionException { |
| 568 | |
| 569 | String searchDir = "src/test/resources/interfileidentitytypedef"; |
| 570 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 571 | utilManager.parseYangFileInfoSet(); |
| 572 | utilManager.createYangNodeSet(); |
| 573 | |
| 574 | YangNode selfNode = null; |
| 575 | YangNode refNode1 = null; |
| 576 | YangNode refNode2 = null; |
| 577 | |
| 578 | // Create YANG node set |
| 579 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
| 580 | |
| 581 | // Add references to import list. |
| 582 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
| 583 | |
Vidyashree Rama | 07c26bb | 2016-07-28 17:33:15 +0530 | [diff] [blame^] | 584 | updateFilePriority(utilManager.getYangNodeSet()); |
| 585 | |
Shankara-Huawei | df7b9ca | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 586 | // Carry out inter-file linking. |
| 587 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
| 588 | |
| 589 | for (YangNode rootNode : utilManager.getYangNodeSet()) { |
| 590 | if (rootNode.getName().equals("IdentityTypedef")) { |
| 591 | selfNode = rootNode; |
| 592 | } else if (rootNode.getName().equals("IdentityInModule")) { |
| 593 | refNode1 = rootNode; |
| 594 | } else { |
| 595 | refNode2 = rootNode; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | // Check whether the data model tree returned is of type module. |
| 600 | assertThat(selfNode instanceof YangModule, is(true)); |
| 601 | |
| 602 | // Check whether the node type is set properly to module. |
| 603 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 604 | |
| 605 | // Check whether the module name is set correctly. |
| 606 | YangModule yangNode = (YangModule) selfNode; |
| 607 | assertThat(yangNode.getName(), is("IdentityTypedef")); |
| 608 | |
| 609 | YangIdentity yangIdentity = (YangIdentity) yangNode.getChild(); |
| 610 | assertThat(yangIdentity.getName(), is("ipv4-address-family")); |
| 611 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 612 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 613 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 614 | |
| 615 | yangIdentity = (YangIdentity) yangNode.getChild().getNextSibling(); |
| 616 | assertThat(yangIdentity.getName(), is("ipv6-address-family")); |
| 617 | assertThat(yangIdentity.getBaseNode().getBaseIdentifier().getName(), is("ref-address-family")); |
| 618 | assertThat(yangIdentity.getBaseNode().getReferredIdentity().getName(), is("ref-address-family")); |
| 619 | assertThat(yangIdentity.getBaseNode().getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 620 | |
| 621 | YangTypeDef typedef = (YangTypeDef) yangNode.getChild().getNextSibling().getNextSibling(); |
| 622 | assertThat(typedef.getName(), is("type15")); |
| 623 | |
| 624 | YangType type = typedef.getTypeList().iterator().next(); |
| 625 | assertThat(type.getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 626 | assertThat(type.getDataTypeName(), is("identityref")); |
| 627 | |
| 628 | YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo(); |
| 629 | assertThat(identityRef.getName(), is("ref-address-family")); |
| 630 | assertThat(identityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 631 | |
| 632 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 633 | YangLeaf leafInfo = leafIterator.next(); |
| 634 | |
| 635 | assertThat(leafInfo.getName(), is("tunnel")); |
| 636 | assertThat(leafInfo.getDataType().getDataTypeName(), is("identityref")); |
| 637 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 638 | YangIdentityRef yangIdentityRef = (YangIdentityRef) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 639 | assertThat(yangIdentityRef.getName(), is("ref-address-family")); |
| 640 | assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family")); |
| 641 | assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family")); |
| 642 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 643 | |
| 644 | ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); |
| 645 | YangLeafList leafListInfo = leafListIterator.next(); |
| 646 | |
| 647 | // Check whether the information in the leaf is correct. |
| 648 | assertThat(leafListInfo.getName(), is("network-ref")); |
| 649 | assertThat(leafListInfo.getDataType().getDataTypeName(), is("identityref")); |
| 650 | assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.IDENTITYREF)); |
| 651 | yangIdentityRef = (YangIdentityRef) (leafListInfo.getDataType().getDataTypeExtendedInfo()); |
| 652 | // Check whether leafref type got resolved. |
| 653 | assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED)); |
| 654 | } |
| 655 | } |