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