Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.yangutils.linker; |
| 18 | |
| 19 | import java.io.IOException; |
| 20 | import java.util.ListIterator; |
| 21 | import org.junit.Test; |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.YangContainer; |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
| 24 | import org.onosproject.yangutils.datamodel.YangLeaf; |
| 25 | import org.onosproject.yangutils.datamodel.YangList; |
| 26 | import org.onosproject.yangutils.datamodel.YangModule; |
| 27 | import org.onosproject.yangutils.datamodel.YangNode; |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
| 29 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 30 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 31 | |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 32 | import static org.hamcrest.CoreMatchers.nullValue; |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 33 | import static org.hamcrest.MatcherAssert.assertThat; |
| 34 | import static org.hamcrest.core.Is.is; |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 35 | import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED; |
| 36 | import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED; |
| 37 | import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; |
| 38 | import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; |
| 39 | import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; |
| 40 | import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Test cases for testing "type" intra file linking. |
| 44 | */ |
| 45 | public class IntraFileTypeLinkingTest { |
| 46 | |
| 47 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 48 | |
| 49 | /** |
| 50 | * Checks self resolution when typedef and leaf using type are siblings. |
| 51 | */ |
| 52 | @Test |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 53 | public void processSelfResolutionWhenTypeAndTypedefAtRootLevel() |
| 54 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 55 | |
| 56 | YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang"); |
| 57 | |
| 58 | // Check whether the data model tree returned is of type module. |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 59 | assertThat(node instanceof YangModule, is(true)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 60 | |
| 61 | // Check whether the node type is set properly to module. |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 62 | assertThat(node.getNodeType(), is(MODULE_NODE)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 63 | |
| 64 | // Check whether the module name is set correctly. |
| 65 | YangModule yangNode = (YangModule) node; |
| 66 | assertThat(yangNode.getName(), is("Test")); |
| 67 | |
| 68 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 69 | YangLeaf leafInfo = leafIterator.next(); |
| 70 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 71 | assertThat(leafInfo.getName(), is("invalid-interval")); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 72 | assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 73 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 74 | |
| 75 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 76 | is((YangTypeDef) node.getChild())); |
| 77 | |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 78 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 79 | |
| 80 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 81 | |
| 82 | // Check for the effective built-in type. |
| 83 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 84 | |
| 85 | // Check for the restriction. |
| 86 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 87 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 88 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 89 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Checks self resolution when typedef and leaf using type are at different |
| 94 | * level where typedef is at the root. |
| 95 | */ |
| 96 | @Test |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 97 | public void processSelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy() |
| 98 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 99 | |
| 100 | YangNode node = |
| 101 | manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy.yang"); |
| 102 | |
| 103 | // Check whether the data model tree returned is of type module. |
| 104 | assertThat((node instanceof YangModule), is(true)); |
| 105 | |
| 106 | // Check whether the node type is set properly to module. |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 107 | assertThat(node.getNodeType(), is(MODULE_NODE)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 108 | |
| 109 | // Check whether the module name is set correctly. |
| 110 | YangModule yangNode = (YangModule) node; |
| 111 | assertThat(yangNode.getName(), is("Test")); |
| 112 | |
| 113 | YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); |
| 114 | |
| 115 | YangList yangList = (YangList) yangContainer.getChild(); |
| 116 | |
| 117 | ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); |
| 118 | YangLeaf leafInfo = leafIterator.next(); |
| 119 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 120 | assertThat(leafInfo.getName(), is("invalid-interval")); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 121 | assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 122 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 123 | |
| 124 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 125 | is((YangTypeDef) node.getChild())); |
| 126 | |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 127 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 128 | |
| 129 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 130 | |
| 131 | // Check for the effective built-in type. |
| 132 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 133 | |
| 134 | // Check for the restriction. |
| 135 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 136 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 137 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 138 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Checks self resolution when typedef and leaf using type are at different |
| 143 | * level where typedef is at the root and defined after parent holder |
| 144 | * of type. |
| 145 | */ |
| 146 | @Test |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 147 | public void processSelfFileLinkingTypedefAtRootIsAfterContainerHavingType() |
| 148 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 149 | |
| 150 | YangNode node = |
| 151 | manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtRootIsAfterContainerHavingType.yang"); |
| 152 | |
| 153 | // Check whether the data model tree returned is of type module. |
| 154 | assertThat((node instanceof YangModule), is(true)); |
| 155 | |
| 156 | // Check whether the node type is set properly to module. |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 157 | assertThat(node.getNodeType(), is(MODULE_NODE)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 158 | |
| 159 | // Check whether the module name is set correctly. |
| 160 | YangModule yangNode = (YangModule) node; |
| 161 | assertThat(yangNode.getName(), is("Test")); |
| 162 | |
| 163 | YangContainer yangContainer = (YangContainer) node.getChild(); |
| 164 | |
| 165 | YangList yangList = (YangList) yangContainer.getChild(); |
| 166 | |
| 167 | ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); |
| 168 | YangLeaf leafInfo = leafIterator.next(); |
| 169 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 170 | assertThat(leafInfo.getName(), is("invalid-interval")); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 171 | assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 172 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 173 | |
| 174 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 175 | is((YangTypeDef) node.getChild().getNextSibling())); |
| 176 | |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 177 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 178 | |
| 179 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 180 | |
| 181 | // Check for the effective built-in type. |
| 182 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 183 | |
| 184 | // Check for the restriction. |
| 185 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 186 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 187 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 188 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Checks self resolution when typedef and leaf using type are at different |
| 193 | * level where typedef is at the level of root+1 and defined after parent |
| 194 | * holder of type. |
| 195 | */ |
| 196 | @Test |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 197 | public void processSelfFileLinkingTypedefAtMiddleLevelAfterParentHolder() |
| 198 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 199 | |
| 200 | YangNode node = |
| 201 | manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtMiddleLevelAfterParentHolder.yang"); |
| 202 | |
| 203 | // Check whether the data model tree returned is of type module. |
| 204 | assertThat((node instanceof YangModule), is(true)); |
| 205 | |
| 206 | // Check whether the node type is set properly to module. |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 207 | assertThat(node.getNodeType(), is(MODULE_NODE)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 208 | |
| 209 | // Check whether the module name is set correctly. |
| 210 | YangModule yangNode = (YangModule) node; |
| 211 | assertThat(yangNode.getName(), is("Test")); |
| 212 | |
| 213 | YangContainer yangContainer = (YangContainer) node.getChild(); |
| 214 | |
| 215 | YangList yangList = (YangList) yangContainer.getChild(); |
| 216 | |
| 217 | ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); |
| 218 | YangLeaf leafInfo = leafIterator.next(); |
| 219 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 220 | assertThat(leafInfo.getName(), is("invalid-interval")); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 221 | assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 222 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 223 | |
| 224 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 225 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); |
| 226 | |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 227 | assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); |
| 228 | |
| 229 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 230 | |
| 231 | // Check for the effective built-in type. |
| 232 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); |
| 233 | |
| 234 | // Check for the restriction. |
| 235 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 236 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 237 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 238 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Checks self resolution when typedef hierarchical references are present. |
| 243 | */ |
| 244 | @Test |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 245 | public void processSelfFileLinkingWithTypdefHierarchicalReference() |
| 246 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 247 | |
| 248 | YangNode node = |
| 249 | manager.getDataModel("src/test/resources/SelfFileLinkingWithTypdefHierarchicalReference.yang"); |
| 250 | |
| 251 | // Check whether the data model tree returned is of type module. |
| 252 | assertThat((node instanceof YangModule), is(true)); |
| 253 | |
| 254 | // Check whether the node type is set properly to module. |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 255 | assertThat(node.getNodeType(), is(MODULE_NODE)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 256 | |
| 257 | // Check whether the module name is set correctly. |
| 258 | YangModule yangNode = (YangModule) node; |
| 259 | assertThat(yangNode.getName(), is("Test")); |
| 260 | |
| 261 | YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); |
| 262 | |
| 263 | YangList yangList = (YangList) yangContainer.getChild(); |
| 264 | |
| 265 | ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); |
| 266 | YangLeaf leafInfo = leafIterator.next(); |
| 267 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 268 | assertThat(leafInfo.getName(), is("invalid-interval")); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 269 | assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass")); |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 270 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 271 | |
| 272 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 273 | is((YangTypeDef) yangList.getChild())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 274 | assertThat(leafInfo.getDataType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 275 | is(RESOLVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 276 | |
| 277 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); |
| 278 | |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 279 | assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 280 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 281 | assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 282 | is(RESOLVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 283 | |
| 284 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); |
| 285 | |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 286 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 287 | is((YangTypeDef) node.getChild())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 288 | assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 289 | is(RESOLVED)); |
| 290 | |
| 291 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 292 | |
| 293 | // Check for the effective built-in type. |
| 294 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32)); |
| 295 | |
| 296 | // Check for the restriction. |
| 297 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 298 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 299 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 300 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Checks self resolution when typedef hierarchical references are present |
| 305 | * with last type is unresolved. |
| 306 | */ |
| 307 | @Test |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 308 | public void processSelfFileLinkingWithTypdefHierarchicalRefUnresolved() |
| 309 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 310 | |
| 311 | YangNode node = |
| 312 | manager.getDataModel("src/test/resources/SelfFileLinkingWithTypdefHierarchicalRefUnresolved.yang"); |
| 313 | |
| 314 | // Check whether the data model tree returned is of type module. |
| 315 | assertThat((node instanceof YangModule), is(true)); |
| 316 | |
| 317 | // Check whether the node type is set properly to module. |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 318 | assertThat(node.getNodeType(), is(MODULE_NODE)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 319 | |
| 320 | // Check whether the module name is set correctly. |
| 321 | YangModule yangNode = (YangModule) node; |
| 322 | assertThat(yangNode.getName(), is("Test")); |
| 323 | |
| 324 | YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); |
| 325 | |
| 326 | YangList yangList = (YangList) yangContainer.getChild(); |
| 327 | |
| 328 | ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); |
| 329 | YangLeaf leafInfo = leafIterator.next(); |
| 330 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 331 | assertThat(leafInfo.getName(), is("invalid-interval")); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 332 | assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass")); |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 333 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 334 | |
| 335 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 336 | is((YangTypeDef) yangList.getChild())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 337 | assertThat(leafInfo.getDataType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 338 | is(INTRA_FILE_RESOLVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 339 | |
| 340 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); |
| 341 | |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 342 | assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 343 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 344 | assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 345 | is(INTRA_FILE_RESOLVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 346 | |
| 347 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); |
| 348 | |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 349 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 350 | is((YangTypeDef) node.getChild())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 351 | assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 352 | is(INTRA_FILE_RESOLVED)); |
| 353 | |
| 354 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 355 | |
| 356 | // Check for the effective built-in type. |
| 357 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(nullValue())); |
| 358 | |
| 359 | // Check for the restriction. |
| 360 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 361 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 362 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 363 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Checks self resolution when type uses prefix of self module. |
| 368 | */ |
| 369 | @Test |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 370 | public void processSelfFileLinkingWithTypeWithSelfModulePrefix() |
| 371 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 372 | |
| 373 | YangNode node = |
| 374 | manager.getDataModel("src/test/resources/SelfFileLinkingWithTypeWithSelfModulePrefix.yang"); |
| 375 | |
| 376 | // Check whether the data model tree returned is of type module. |
| 377 | assertThat((node instanceof YangModule), is(true)); |
| 378 | |
| 379 | // Check whether the node type is set properly to module. |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 380 | assertThat(node.getNodeType(), is(MODULE_NODE)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 381 | |
| 382 | // Check whether the module name is set correctly. |
| 383 | YangModule yangNode = (YangModule) node; |
| 384 | assertThat(yangNode.getName(), is("Test")); |
| 385 | |
| 386 | YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); |
| 387 | |
| 388 | YangList yangList = (YangList) yangContainer.getChild(); |
| 389 | |
| 390 | ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); |
| 391 | YangLeaf leafInfo = leafIterator.next(); |
| 392 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 393 | assertThat(leafInfo.getName(), is("invalid-interval")); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 394 | assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass")); |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 395 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 396 | |
| 397 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 398 | is((YangTypeDef) yangList.getChild())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 399 | assertThat(leafInfo.getDataType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 400 | is(RESOLVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 401 | |
| 402 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); |
| 403 | |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 404 | assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 405 | is((YangTypeDef) yangContainer.getChild().getNextSibling())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 406 | assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 407 | is(RESOLVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 408 | |
| 409 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); |
| 410 | |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 411 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 412 | is((YangTypeDef) node.getChild())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 413 | assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 414 | is(RESOLVED)); |
| 415 | |
| 416 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 417 | |
| 418 | // Check for the effective built-in type. |
| 419 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32)); |
| 420 | |
| 421 | // Check for the restriction. |
| 422 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 423 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 424 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 425 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Checks self resolution when some type uses prefix of self module |
| 430 | * some uses external prefix. |
| 431 | */ |
| 432 | @Test |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 433 | public void processSelfFileLinkingWithTypeWithSelfAndExternalPrefixMix() |
| 434 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 435 | |
| 436 | YangNode node = |
| 437 | manager.getDataModel("src/test/resources/SelfFileLinkingWithTypeWithSelfAndExternalPrefixMix.yang"); |
| 438 | |
| 439 | // Check whether the data model tree returned is of type module. |
| 440 | assertThat((node instanceof YangModule), is(true)); |
| 441 | |
| 442 | // Check whether the node type is set properly to module. |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 443 | assertThat(node.getNodeType(), is(MODULE_NODE)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 444 | |
| 445 | // Check whether the module name is set correctly. |
| 446 | YangModule yangNode = (YangModule) node; |
| 447 | assertThat(yangNode.getName(), is("Test")); |
| 448 | |
| 449 | YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling(); |
| 450 | |
| 451 | YangList yangList = (YangList) yangContainer.getChild(); |
| 452 | |
| 453 | ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); |
| 454 | YangLeaf leafInfo = leafIterator.next(); |
| 455 | |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 456 | assertThat(leafInfo.getName(), is("invalid-interval")); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 457 | assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass")); |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 458 | assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 459 | |
| 460 | assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
| 461 | is((YangTypeDef) yangList.getChild())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 462 | assertThat(leafInfo.getDataType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 463 | is(INTRA_FILE_RESOLVED)); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 464 | |
| 465 | YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild(); |
| 466 | |
| 467 | YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling(); |
| 468 | |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 469 | assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(), |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 470 | is((YangTypeDef) node.getChild())); |
Vidyashree Rama | 1396065 | 2016-04-26 15:06:06 +0530 | [diff] [blame] | 471 | assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(), |
Gaurav Agrawal | cc55d48 | 2016-05-03 00:41:48 +0530 | [diff] [blame] | 472 | is(RESOLVED)); |
| 473 | |
| 474 | YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); |
| 475 | |
| 476 | // Check for the effective built-in type. |
| 477 | assertThat(derivedInfo.getEffectiveBuiltInType(), is(nullValue())); |
| 478 | |
| 479 | // Check for the restriction. |
| 480 | assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); |
| 481 | assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); |
| 482 | assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); |
| 483 | assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue())); |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Check self resolution when type referred typedef is not available in |
| 488 | * file. |
| 489 | */ |
| 490 | @Test(expected = ParserException.class) |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 491 | public void processSelfResolutionWhenTypeReferredTypedefNotDefined() |
| 492 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 493 | |
| 494 | YangNode node = |
| 495 | manager.getDataModel("src/test/resources/SelfResolutionWhenTypeReferredTypedefNotDefined.yang"); |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * Checks self resolution when typedef and leaf using type are at different |
| 500 | * level where typedef is is not an ancestor of type. |
| 501 | */ |
| 502 | @Test(expected = ParserException.class) |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 503 | public void processSelfFileLinkingTypedefNotFound() |
| 504 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 505 | |
| 506 | YangNode node = manager.getDataModel("src/test/resources/SelfFileLinkingTypedefNotFound.yang"); |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Checks hierarchical self resolution with self resolution failure scenario. |
| 511 | */ |
| 512 | @Test(expected = ParserException.class) |
Vinod Kumar S | f677daf | 2016-04-15 18:08:57 +0530 | [diff] [blame] | 513 | public void processSelfFileLinkingWithHierarchicalTypeFailureScenario() |
| 514 | throws IOException, ParserException { |
Gaurav Agrawal | 1fbfae1 | 2016-03-29 02:17:23 +0530 | [diff] [blame] | 515 | |
| 516 | YangNode node = |
| 517 | manager.getDataModel("src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang"); |
| 518 | } |
| 519 | } |