blob: a4cb0a5d9d11b07dcc760f9f156447e248aaac8d [file] [log] [blame]
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +05303 *
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
17package org.onosproject.yangutils.linker;
18
19import java.io.IOException;
20import java.util.ListIterator;
21import org.junit.Test;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053022import org.onosproject.yangutils.datamodel.YangContainer;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053023import org.onosproject.yangutils.datamodel.YangDerivedInfo;
24import org.onosproject.yangutils.datamodel.YangLeaf;
25import org.onosproject.yangutils.datamodel.YangList;
26import org.onosproject.yangutils.datamodel.YangModule;
27import org.onosproject.yangutils.datamodel.YangNode;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053028import org.onosproject.yangutils.datamodel.YangTypeDef;
29import org.onosproject.yangutils.parser.exceptions.ParserException;
30import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053032import static org.hamcrest.CoreMatchers.nullValue;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053033import static org.hamcrest.MatcherAssert.assertThat;
34import static org.hamcrest.core.Is.is;
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053035import static org.onosproject.yangutils.datamodel.ResolvableStatus.INTRA_FILE_RESOLVED;
36import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
37import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
38import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
39import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
40import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053041
42/**
43 * Test cases for testing "type" intra file linking.
44 */
45public 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 Sd4deb062016-04-15 18:08:57 +053053 public void processSelfResolutionWhenTypeAndTypedefAtRootLevel()
54 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053055
56 YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang");
57
58 // Check whether the data model tree returned is of type module.
Vidyashree Rama7142d9c2016-04-26 15:06:06 +053059 assertThat(node instanceof YangModule, is(true));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053060
61 // Check whether the node type is set properly to module.
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053062 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053063
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 Se4b9b0c2016-04-30 21:09:15 +053071 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053072 assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053073 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053074
75 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
76 is((YangTypeDef) node.getChild()));
77
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053078 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 Agrawald9d6cc82016-03-29 02:17:23 +053090 }
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 Sd4deb062016-04-15 18:08:57 +053097 public void processSelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy()
98 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053099
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 Agrawalcfa1c412016-05-03 00:41:48 +0530107 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530108
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 Se4b9b0c2016-04-30 21:09:15 +0530120 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530121 assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530122 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530123
124 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
125 is((YangTypeDef) node.getChild()));
126
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530127 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 Agrawald9d6cc82016-03-29 02:17:23 +0530139 }
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 Sd4deb062016-04-15 18:08:57 +0530147 public void processSelfFileLinkingTypedefAtRootIsAfterContainerHavingType()
148 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530149
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 Agrawalcfa1c412016-05-03 00:41:48 +0530157 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530158
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 Se4b9b0c2016-04-30 21:09:15 +0530170 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530171 assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530172 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530173
174 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
175 is((YangTypeDef) node.getChild().getNextSibling()));
176
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530177 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 Agrawald9d6cc82016-03-29 02:17:23 +0530189 }
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 Sd4deb062016-04-15 18:08:57 +0530197 public void processSelfFileLinkingTypedefAtMiddleLevelAfterParentHolder()
198 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530199
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 Agrawalcfa1c412016-05-03 00:41:48 +0530207 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530208
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 Se4b9b0c2016-04-30 21:09:15 +0530220 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530221 assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530222 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530223
224 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
225 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
226
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530227 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 Agrawald9d6cc82016-03-29 02:17:23 +0530239 }
240
241 /**
242 * Checks self resolution when typedef hierarchical references are present.
243 */
244 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530245 public void processSelfFileLinkingWithTypdefHierarchicalReference()
246 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530247
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 Agrawalcfa1c412016-05-03 00:41:48 +0530255 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530256
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 Se4b9b0c2016-04-30 21:09:15 +0530268 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530269 assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530270 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530271
272 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
273 is((YangTypeDef) yangList.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530274 assertThat(leafInfo.getDataType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530275 is(RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530276
277 YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
278
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530279 assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530280 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530281 assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530282 is(RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530283
284 YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
285
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530286 assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530287 is((YangTypeDef) node.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530288 assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530289 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 Agrawald9d6cc82016-03-29 02:17:23 +0530301 }
302
303 /**
304 * Checks self resolution when typedef hierarchical references are present
305 * with last type is unresolved.
306 */
307 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530308 public void processSelfFileLinkingWithTypdefHierarchicalRefUnresolved()
309 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530310
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 Agrawalcfa1c412016-05-03 00:41:48 +0530318 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530319
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 Se4b9b0c2016-04-30 21:09:15 +0530331 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530332 assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530333 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530334
335 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
336 is((YangTypeDef) yangList.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530337 assertThat(leafInfo.getDataType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530338 is(INTRA_FILE_RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530339
340 YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
341
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530342 assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530343 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530344 assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530345 is(INTRA_FILE_RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530346
347 YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
348
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530349 assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530350 is((YangTypeDef) node.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530351 assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530352 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 Agrawald9d6cc82016-03-29 02:17:23 +0530364 }
365
366 /**
367 * Checks self resolution when type uses prefix of self module.
368 */
369 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530370 public void processSelfFileLinkingWithTypeWithSelfModulePrefix()
371 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530372
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 Agrawalcfa1c412016-05-03 00:41:48 +0530380 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530381
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 Se4b9b0c2016-04-30 21:09:15 +0530393 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530394 assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530395 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530396
397 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
398 is((YangTypeDef) yangList.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530399 assertThat(leafInfo.getDataType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530400 is(RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530401
402 YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
403
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530404 assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530405 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530406 assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530407 is(RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530408
409 YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
410
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530411 assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530412 is((YangTypeDef) node.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530413 assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530414 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 Agrawald9d6cc82016-03-29 02:17:23 +0530426 }
427
428 /**
429 * Checks self resolution when some type uses prefix of self module
430 * some uses external prefix.
431 */
432 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530433 public void processSelfFileLinkingWithTypeWithSelfAndExternalPrefixMix()
434 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530435
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 Agrawalcfa1c412016-05-03 00:41:48 +0530443 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530444
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 Se4b9b0c2016-04-30 21:09:15 +0530456 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530457 assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530458 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530459
460 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
461 is((YangTypeDef) yangList.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530462 assertThat(leafInfo.getDataType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530463 is(INTRA_FILE_RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530464
465 YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
466
467 YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
468
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530469 assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530470 is((YangTypeDef) node.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530471 assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530472 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 Agrawald9d6cc82016-03-29 02:17:23 +0530484 }
485
486 /**
487 * Check self resolution when type referred typedef is not available in
488 * file.
489 */
490 @Test(expected = ParserException.class)
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530491 public void processSelfResolutionWhenTypeReferredTypedefNotDefined()
492 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530493
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 Sd4deb062016-04-15 18:08:57 +0530503 public void processSelfFileLinkingTypedefNotFound()
504 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530505
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 Sd4deb062016-04-15 18:08:57 +0530513 public void processSelfFileLinkingWithHierarchicalTypeFailureScenario()
514 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530515
516 YangNode node =
517 manager.getDataModel("src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang");
518 }
519}