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