Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +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 | |
Gaurav Agrawal | c5f6327 | 2016-06-16 13:09:53 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.plugin.manager; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 18 | |
| 19 | import java.io.IOException; |
| 20 | import java.util.Iterator; |
| 21 | import java.util.ListIterator; |
| 22 | import org.apache.maven.plugin.MojoExecutionException; |
| 23 | import org.junit.Test; |
Gaurav Agrawal | 72cd1b7 | 2016-06-30 13:28:14 +0530 | [diff] [blame^] | 24 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
| 26 | import org.onosproject.yangutils.datamodel.YangGrouping; |
| 27 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 28 | import org.onosproject.yangutils.datamodel.YangModule; |
| 29 | import org.onosproject.yangutils.datamodel.YangNode; |
| 30 | import org.onosproject.yangutils.datamodel.YangNodeType; |
| 31 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
| 32 | import org.onosproject.yangutils.datamodel.YangUses; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.datamodel.utils.ResolvableStatus; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.linker.impl.YangLinkerManager; |
| 35 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 36 | import org.onosproject.yangutils.utils.io.impl.YangFileScanner; |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 37 | import org.onosproject.yangutils.utils.io.impl.YangPluginConfig; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 38 | |
| 39 | import static org.hamcrest.CoreMatchers.nullValue; |
| 40 | import static org.hamcrest.MatcherAssert.assertThat; |
| 41 | import static org.hamcrest.core.Is.is; |
Gaurav Agrawal | 72cd1b7 | 2016-06-30 13:28:14 +0530 | [diff] [blame^] | 42 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED; |
| 43 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 44 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; |
Bharat saraswal | 96dfef0 | 2016-06-16 00:29:12 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED; |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * Test cases for testing inter file linking. |
| 50 | */ |
| 51 | public class InterFileLinkingTest { |
| 52 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 53 | private final YangUtilManager utilManager = new YangUtilManager(); |
| 54 | private final YangLinkerManager yangLinkerManager = new YangLinkerManager(); |
| 55 | |
| 56 | /** |
| 57 | * Checks inter file type linking. |
| 58 | */ |
| 59 | @Test |
| 60 | public void processInterFileTypeLinking() |
| 61 | throws IOException, ParserException, MojoExecutionException { |
| 62 | |
| 63 | String searchDir = "src/test/resources/interfiletype"; |
| 64 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 65 | utilManager.parseYangFileInfoSet(); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 66 | utilManager.createYangNodeSet(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 67 | |
| 68 | YangNode refNode = null; |
| 69 | YangNode selfNode = null; |
| 70 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 71 | // Create YANG node set |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 72 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 73 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 74 | // Add references to import list. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 75 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 76 | |
| 77 | // Carry out inter-file linking. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 78 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 79 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 80 | Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 81 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 82 | YangNode rootNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 83 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 84 | if (rootNode.getName().equals("module1")) { |
| 85 | selfNode = rootNode; |
| 86 | refNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 87 | } else { |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 88 | refNode = rootNode; |
| 89 | selfNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | // Check whether the data model tree returned is of type module. |
| 93 | assertThat(selfNode instanceof YangModule, is(true)); |
| 94 | |
| 95 | // Check whether the node type is set properly to module. |
| 96 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 97 | |
| 98 | // Check whether the module name is set correctly. |
| 99 | YangModule yangNode = (YangModule) selfNode; |
| 100 | assertThat(yangNode.getName(), is("module1")); |
| 101 | |
| 102 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 103 | YangLeaf leafInfo = leafIterator.next(); |
| 104 | |
| 105 | assertThat(leafInfo.getName(), is("invalid-interval")); |
| 106 | assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); |
| 107 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
| 108 | |
| 109 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 110 | is((YangTypeDef) refNode.getChild())); |
| 111 | |
| 112 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 113 | |
| 114 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 115 | |
| 116 | // Check for the effective built-in type. |
| 117 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 118 | |
| 119 | // Check for the restriction. |
| 120 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 121 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 122 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 123 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Checks inter file uses linking. |
| 128 | */ |
| 129 | @Test |
| 130 | public void processInterFileUsesLinking() |
| 131 | throws IOException, ParserException, MojoExecutionException { |
| 132 | |
| 133 | String searchDir = "src/test/resources/interfileuses"; |
| 134 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 135 | utilManager.parseYangFileInfoSet(); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 136 | utilManager.createYangNodeSet(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 137 | |
| 138 | YangNode refNode = null; |
| 139 | YangNode selfNode = null; |
| 140 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 141 | // Create YANG node set |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 142 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 143 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 144 | // Add references to import list. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 145 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 146 | |
| 147 | // Carry out inter-file linking. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 148 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 149 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 150 | Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 151 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 152 | YangNode rootNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 153 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 154 | if (rootNode.getName().equals("module1")) { |
| 155 | selfNode = rootNode; |
| 156 | refNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 157 | } else { |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 158 | refNode = rootNode; |
| 159 | selfNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | // Check whether the data model tree returned is of type module. |
| 163 | assertThat((selfNode instanceof YangModule), is(true)); |
| 164 | |
| 165 | // Check whether the node type is set properly to module. |
| 166 | assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 167 | |
| 168 | // Check whether the module name is set correctly. |
| 169 | YangModule yangNode = (YangModule) selfNode; |
| 170 | assertThat(yangNode.getName(), is("module1")); |
| 171 | |
| 172 | ListIterator<YangLeaf> leafIterator; |
| 173 | YangLeaf leafInfo; |
| 174 | |
| 175 | // Check whether grouping is the sibling of module's child. |
| 176 | assertThat((refNode.getChild() instanceof YangGrouping), is(true)); |
| 177 | |
| 178 | YangGrouping grouping = (YangGrouping) refNode.getChild(); |
| 179 | leafIterator = grouping.getListOfLeaf().listIterator(); |
| 180 | leafInfo = leafIterator.next(); |
| 181 | |
| 182 | // Check whether the information in the leaf is correct under grouping. |
| 183 | assertThat(leafInfo.getName(), is("hello")); |
| 184 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
| 185 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 186 | |
| 187 | // Check whether uses is module's child. |
| 188 | assertThat((yangNode.getChild() instanceof YangUses), is(true)); |
| 189 | YangUses uses = (YangUses) yangNode.getChild(); |
| 190 | |
| 191 | // Check whether uses get resolved. |
| 192 | assertThat(uses.getResolvableStatus(), |
| 193 | is(ResolvableStatus.RESOLVED)); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Checks inter file type linking with include list. |
| 198 | */ |
| 199 | @Test |
| 200 | public void processInterFileTypeLinkingWithIncludeList() |
| 201 | throws IOException, ParserException, MojoExecutionException { |
| 202 | |
| 203 | String searchDir = "src/test/resources/interfiletypewithinclude"; |
| 204 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 205 | utilManager.parseYangFileInfoSet(); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 206 | utilManager.createYangNodeSet(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 207 | |
| 208 | YangNode refNode = null; |
| 209 | YangNode selfNode = null; |
| 210 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 211 | // Create YANG node set |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 212 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 213 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 214 | // Carry out linking of sub module with module. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 215 | yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 216 | |
| 217 | // Add reference to include list. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 218 | yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 219 | |
| 220 | // Carry out inter-file linking. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 221 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 222 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 223 | Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 224 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 225 | YangNode rootNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 226 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 227 | if (rootNode.getName().equals("module1")) { |
| 228 | selfNode = rootNode; |
| 229 | refNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 230 | } else { |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 231 | refNode = rootNode; |
| 232 | selfNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | // Check whether the data model tree returned is of type module. |
| 236 | assertThat(selfNode instanceof YangModule, is(true)); |
| 237 | |
| 238 | // Check whether the node type is set properly to module. |
| 239 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 240 | |
| 241 | // Check whether the module name is set correctly. |
| 242 | YangModule yangNode = (YangModule) selfNode; |
| 243 | assertThat(yangNode.getName(), is("module1")); |
| 244 | |
| 245 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 246 | YangLeaf leafInfo = leafIterator.next(); |
| 247 | |
| 248 | assertThat(leafInfo.getName(), is("invalid-interval")); |
| 249 | assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); |
| 250 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
| 251 | |
| 252 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 253 | is((YangTypeDef) refNode.getChild())); |
| 254 | |
| 255 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 256 | |
| 257 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 258 | |
| 259 | // Check for the effective built-in type. |
| 260 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 261 | |
| 262 | // Check for the restriction. |
| 263 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 264 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 265 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 266 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Checks inter file uses linking with include list. |
| 271 | */ |
| 272 | @Test |
| 273 | public void processInterFileUsesLinkingWithInclude() |
| 274 | throws IOException, ParserException, MojoExecutionException { |
| 275 | |
| 276 | String searchDir = "src/test/resources/interfileuseswithinclude"; |
| 277 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 278 | utilManager.parseYangFileInfoSet(); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 279 | utilManager.createYangNodeSet(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 280 | |
| 281 | YangNode refNode = null; |
| 282 | YangNode selfNode = null; |
| 283 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 284 | // Create YANG node set |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 285 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 286 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 287 | // Carry out linking of sub module with module. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 288 | yangLinkerManager.linkSubModulesToParentModule(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 289 | |
| 290 | // Add reference to include list. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 291 | yangLinkerManager.addRefToYangFilesIncludeList(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 292 | |
| 293 | // Carry out inter-file linking. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 294 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 295 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 296 | Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 297 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 298 | YangNode rootNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 299 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 300 | if (rootNode.getName().equals("module1")) { |
| 301 | selfNode = rootNode; |
| 302 | refNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 303 | } else { |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 304 | refNode = rootNode; |
| 305 | selfNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | // Check whether the data model tree returned is of type module. |
| 309 | assertThat((selfNode instanceof YangModule), is(true)); |
| 310 | |
| 311 | // Check whether the node type is set properly to module. |
| 312 | assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 313 | |
| 314 | // Check whether the module name is set correctly. |
| 315 | YangModule yangNode = (YangModule) selfNode; |
| 316 | assertThat(yangNode.getName(), is("module1")); |
| 317 | |
| 318 | ListIterator<YangLeaf> leafIterator; |
| 319 | YangLeaf leafInfo; |
| 320 | |
| 321 | // Check whether grouping is the sibling of module's child. |
| 322 | assertThat((refNode.getChild() instanceof YangGrouping), is(true)); |
| 323 | |
| 324 | YangGrouping grouping = (YangGrouping) refNode.getChild(); |
| 325 | leafIterator = grouping.getListOfLeaf().listIterator(); |
| 326 | leafInfo = leafIterator.next(); |
| 327 | |
| 328 | // Check whether the information in the leaf is correct under grouping. |
| 329 | assertThat(leafInfo.getName(), is("hello")); |
| 330 | assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
| 331 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING)); |
| 332 | |
| 333 | // Check whether uses is module's child. |
| 334 | assertThat((yangNode.getChild() instanceof YangUses), is(true)); |
| 335 | YangUses uses = (YangUses) yangNode.getChild(); |
| 336 | |
| 337 | // Check whether uses get resolved. |
| 338 | assertThat(uses.getResolvableStatus(), |
| 339 | is(ResolvableStatus.RESOLVED)); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Checks inter file type linking with revision. |
| 344 | */ |
| 345 | @Test |
| 346 | public void processInterFileTypeLinkingWithRevision() |
| 347 | throws IOException, ParserException, MojoExecutionException { |
| 348 | |
| 349 | String searchDir = "src/test/resources/interfiletypewithrevision"; |
| 350 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 351 | utilManager.parseYangFileInfoSet(); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 352 | utilManager.createYangNodeSet(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 353 | |
| 354 | YangNode refNode = null; |
| 355 | YangNode selfNode = null; |
| 356 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 357 | // Create YANG node set |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 358 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 359 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 360 | // Add references to import list. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 361 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 362 | |
| 363 | // Carry out inter-file linking. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 364 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 365 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 366 | Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 367 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 368 | YangNode rootNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 369 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 370 | if (rootNode.getName().equals("module1")) { |
| 371 | selfNode = rootNode; |
| 372 | refNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 373 | } else { |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 374 | refNode = rootNode; |
| 375 | selfNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | // Check whether the data model tree returned is of type module. |
| 379 | assertThat(selfNode instanceof YangModule, is(true)); |
| 380 | |
| 381 | // Check whether the node type is set properly to module. |
| 382 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 383 | |
| 384 | // Check whether the module name is set correctly. |
| 385 | YangModule yangNode = (YangModule) selfNode; |
| 386 | assertThat(yangNode.getName(), is("module1")); |
| 387 | |
| 388 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 389 | YangLeaf leafInfo = leafIterator.next(); |
| 390 | |
| 391 | assertThat(leafInfo.getName(), is("invalid-interval")); |
| 392 | assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); |
| 393 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
| 394 | |
| 395 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 396 | is((YangTypeDef) refNode.getChild())); |
| 397 | |
| 398 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 399 | |
| 400 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 401 | |
| 402 | // Check for the effective built-in type. |
| 403 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 404 | |
| 405 | // Check for the restriction. |
| 406 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 407 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 408 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 409 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Checks inter file type linking with revision in name. |
| 414 | */ |
| 415 | @Test |
| 416 | public void processInterFileTypeLinkingWithRevisionInName() |
| 417 | throws IOException, ParserException, MojoExecutionException { |
| 418 | |
| 419 | String searchDir = "src/test/resources/interfiletypewithrevisioninname"; |
| 420 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 421 | utilManager.parseYangFileInfoSet(); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 422 | utilManager.createYangNodeSet(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 423 | |
| 424 | YangNode refNode = null; |
| 425 | YangNode selfNode = null; |
| 426 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 427 | // Create YANG node set |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 428 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 429 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 430 | // Add references to import list. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 431 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 432 | |
| 433 | // Carry out inter-file linking. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 434 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 435 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 436 | Iterator<YangNode> yangNodeIterator = utilManager.getYangNodeSet().iterator(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 437 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 438 | YangNode rootNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 439 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 440 | if (rootNode.getName().equals("module1")) { |
| 441 | selfNode = rootNode; |
| 442 | refNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 443 | } else { |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 444 | refNode = rootNode; |
| 445 | selfNode = yangNodeIterator.next(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | // Check whether the data model tree returned is of type module. |
| 449 | assertThat(selfNode instanceof YangModule, is(true)); |
| 450 | |
| 451 | // Check whether the node type is set properly to module. |
| 452 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 453 | |
| 454 | // Check whether the module name is set correctly. |
| 455 | YangModule yangNode = (YangModule) selfNode; |
| 456 | assertThat(yangNode.getName(), is("module1")); |
| 457 | |
| 458 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 459 | YangLeaf leafInfo = leafIterator.next(); |
| 460 | |
| 461 | assertThat(leafInfo.getName(), is("invalid-interval")); |
| 462 | assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); |
| 463 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
| 464 | |
| 465 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 466 | is((YangTypeDef) refNode.getChild())); |
| 467 | |
| 468 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 469 | |
| 470 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 471 | |
| 472 | // Check for the effective built-in type. |
| 473 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 474 | |
| 475 | // Check for the restriction. |
| 476 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 477 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 478 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 479 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Checks hierarchical inter file type linking. |
| 484 | */ |
| 485 | @Test |
| 486 | public void processHierarchicalInterFileTypeLinking() |
| 487 | throws IOException, ParserException, MojoExecutionException { |
| 488 | |
| 489 | String searchDir = "src/test/resources/hierarchicalinterfiletype"; |
| 490 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 491 | utilManager.parseYangFileInfoSet(); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 492 | utilManager.createYangNodeSet(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 493 | |
| 494 | YangNode refNode1 = null; |
| 495 | YangNode refNode2 = null; |
| 496 | YangNode selfNode = null; |
| 497 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 498 | // Create YANG node set |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 499 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 500 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 501 | // Add references to import list. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 502 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 503 | |
| 504 | // Carry out inter-file linking. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 505 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 506 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 507 | for (YangNode rootNode : utilManager.getYangNodeSet()) { |
| 508 | if (rootNode.getName().equals("ietf-network-topology")) { |
| 509 | selfNode = rootNode; |
| 510 | } else if (rootNode.getName().equals("ietf-network")) { |
| 511 | refNode1 = rootNode; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 512 | } else { |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 513 | refNode2 = rootNode; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
| 517 | // Check whether the data model tree returned is of type module. |
| 518 | assertThat(selfNode instanceof YangModule, is(true)); |
| 519 | |
| 520 | // Check whether the node type is set properly to module. |
| 521 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 522 | |
| 523 | // Check whether the module name is set correctly. |
| 524 | YangModule yangNode = (YangModule) selfNode; |
| 525 | assertThat(yangNode.getName(), is("ietf-network-topology")); |
| 526 | |
| 527 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 528 | YangLeaf leafInfo = leafIterator.next(); |
| 529 | |
| 530 | assertThat(leafInfo.getName(), is("source-node")); |
| 531 | assertThat(leafInfo.getDataType().getDataTypeName(), is("node-id")); |
| 532 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
| 533 | |
| 534 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 535 | is((YangTypeDef) refNode1.getChild())); |
| 536 | |
| 537 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 538 | |
| 539 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 540 | |
| 541 | // Check for the effective built-in type. |
| 542 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 543 | |
| 544 | // Check for the restriction. |
| 545 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 546 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 547 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 548 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * Checks hierarchical intra with inter file type linking. |
| 553 | */ |
| 554 | @Test |
| 555 | public void processHierarchicalIntraWithInterFileTypeLinking() |
| 556 | throws IOException, ParserException, MojoExecutionException { |
| 557 | |
| 558 | String searchDir = "src/test/resources/hierarchicalintrawithinterfiletype"; |
| 559 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 560 | utilManager.parseYangFileInfoSet(); |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 561 | utilManager.createYangNodeSet(); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 562 | |
| 563 | YangNode refNode1 = null; |
| 564 | YangNode selfNode = null; |
| 565 | |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 566 | // Create YANG node set |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 567 | yangLinkerManager.createYangNodeSet(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 95b416c | 2016-06-07 14:00:26 +0530 | [diff] [blame] | 568 | |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 569 | // Add references to import list. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 570 | yangLinkerManager.addRefToYangFilesImportList(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 571 | |
| 572 | // Carry out inter-file linking. |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 573 | yangLinkerManager.processInterFileLinking(utilManager.getYangNodeSet()); |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 574 | |
Gaurav Agrawal | 8a5af14 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 575 | for (YangNode rootNode : utilManager.getYangNodeSet()) { |
| 576 | if (rootNode.getName().equals("ietf-network")) { |
| 577 | selfNode = rootNode; |
| 578 | } else if (rootNode.getName().equals("ietf-inet-types")) { |
| 579 | refNode1 = rootNode; |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
| 583 | // Check whether the data model tree returned is of type module. |
| 584 | assertThat(selfNode instanceof YangModule, is(true)); |
| 585 | |
| 586 | // Check whether the node type is set properly to module. |
| 587 | assertThat(selfNode.getNodeType(), is(MODULE_NODE)); |
| 588 | |
| 589 | // Check whether the module name is set correctly. |
| 590 | YangModule yangNode = (YangModule) selfNode; |
| 591 | assertThat(yangNode.getName(), is("ietf-network")); |
| 592 | |
| 593 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 594 | YangLeaf leafInfo = leafIterator.next(); |
| 595 | |
| 596 | assertThat(leafInfo.getName(), is("node-ref")); |
| 597 | assertThat(leafInfo.getDataType().getDataTypeName(), is("node-id")); |
| 598 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
| 599 | |
| 600 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 601 | is((YangTypeDef) selfNode.getChild())); |
| 602 | |
| 603 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 604 | |
| 605 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 606 | |
| 607 | // Check for the effective built-in type. |
| 608 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 609 | |
| 610 | // Check for the restriction. |
| 611 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 612 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 613 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 614 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
| 615 | } |
VinodKumarS-Huawei | 2ee9e7e | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 616 | |
| 617 | /** |
| 618 | * Checks hierarchical intra with inter file type linking. |
| 619 | */ |
| 620 | @Test |
| 621 | public void interFileWithUsesReferringType() |
| 622 | throws IOException, ParserException, MojoExecutionException { |
| 623 | |
| 624 | String searchDir = "src/test/resources/interfilewithusesreferringtype"; |
| 625 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 626 | utilManager.parseYangFileInfoSet(); |
| 627 | utilManager.resolveDependenciesUsingLinker(); |
| 628 | |
| 629 | String userDir = System.getProperty("user.dir"); |
| 630 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 631 | yangPluginConfig.setCodeGenDir("target/interfilewithusesreferringtype/"); |
| 632 | |
| 633 | utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig); |
| 634 | |
| 635 | deleteDirectory(userDir + "/target/interfilewithusesreferringtype/"); |
| 636 | |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * Checks hierarchical intra with inter file type linking. |
| 641 | */ |
| 642 | @Test |
| 643 | public void file1UsesFile2TypeDefFile3Type() |
| 644 | throws IOException, ParserException, MojoExecutionException { |
| 645 | |
| 646 | String searchDir = "src/test/resources/file1UsesFile2TypeDefFile3Type"; |
| 647 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 648 | utilManager.parseYangFileInfoSet(); |
| 649 | utilManager.resolveDependenciesUsingLinker(); |
| 650 | |
| 651 | String userDir = System.getProperty("user.dir"); |
| 652 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 653 | yangPluginConfig.setCodeGenDir("target/file1UsesFile2TypeDefFile3Type/"); |
| 654 | |
| 655 | utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig); |
| 656 | |
| 657 | deleteDirectory(userDir + "/target/file1UsesFile2TypeDefFile3Type/"); |
| 658 | |
| 659 | } |
| 660 | |
| 661 | |
| 662 | /** |
| 663 | * Checks hierarchical intra with inter file type linking. |
| 664 | */ |
| 665 | @Test |
| 666 | public void interFileIetf() |
| 667 | throws IOException, ParserException, MojoExecutionException { |
| 668 | |
| 669 | String searchDir = "src/test/resources/interfileietf"; |
| 670 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 671 | utilManager.parseYangFileInfoSet(); |
| 672 | utilManager.resolveDependenciesUsingLinker(); |
| 673 | |
| 674 | String userDir = System.getProperty("user.dir"); |
| 675 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 676 | yangPluginConfig.setCodeGenDir("target/interfileietf/"); |
| 677 | |
| 678 | utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig); |
| 679 | |
| 680 | deleteDirectory(userDir + "/target/interfileietf/"); |
| 681 | |
| 682 | } |
| 683 | |
| 684 | |
| 685 | /** |
| 686 | * Checks hierarchical intra with inter file type linking. |
| 687 | */ |
| 688 | @Test |
| 689 | public void usesInContainer() |
| 690 | throws IOException, ParserException, MojoExecutionException { |
| 691 | |
| 692 | String searchDir = "src/test/resources/usesInContainer"; |
| 693 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 694 | utilManager.parseYangFileInfoSet(); |
| 695 | utilManager.resolveDependenciesUsingLinker(); |
| 696 | |
| 697 | String userDir = System.getProperty("user.dir"); |
| 698 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 699 | yangPluginConfig.setCodeGenDir("target/usesInContainer/"); |
| 700 | |
| 701 | utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig); |
| 702 | |
| 703 | deleteDirectory(userDir + "/target/usesInContainer/"); |
| 704 | |
| 705 | } |
| 706 | |
| 707 | |
| 708 | /** |
| 709 | * Checks hierarchical intra with inter file type linking. |
| 710 | */ |
| 711 | @Test |
| 712 | public void groupingNodeSameAsModule() |
| 713 | throws IOException, ParserException, MojoExecutionException { |
| 714 | |
| 715 | String searchDir = "src/test/resources/groupingNodeSameAsModule"; |
| 716 | utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir)); |
| 717 | utilManager.parseYangFileInfoSet(); |
| 718 | utilManager.resolveDependenciesUsingLinker(); |
| 719 | |
| 720 | String userDir = System.getProperty("user.dir"); |
| 721 | YangPluginConfig yangPluginConfig = new YangPluginConfig(); |
| 722 | yangPluginConfig.setCodeGenDir("target/groupingNodeSameAsModule/"); |
| 723 | |
| 724 | utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig); |
| 725 | |
| 726 | deleteDirectory(userDir + "/target/groupingNodeSameAsModule/"); |
| 727 | |
| 728 | } |
Gaurav Agrawal | 0d43bb5 | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 729 | } |