blob: a9fcdd28494f0b4a9780756c5a50ed3ad942e5ee [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
Gaurav Agrawalc5f63272016-06-16 13:09:53 +053017package org.onosproject.yangutils.plugin.manager;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053018
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;
Gaurav Agrawal95b416c2016-06-07 14:00:26 +053029import org.onosproject.yangutils.linker.exceptions.LinkerException;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053030import org.onosproject.yangutils.parser.exceptions.ParserException;
31import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
32
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053033import static org.hamcrest.CoreMatchers.nullValue;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053034import static org.hamcrest.MatcherAssert.assertThat;
35import static org.hamcrest.core.Is.is;
Gaurav Agrawal72cd1b72016-06-30 13:28:14 +053036import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
37import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
38import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
39import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053040import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
Bharat saraswal96dfef02016-06-16 00:29:12 +053041import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
42import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053043
44/**
45 * Test cases for testing "type" intra file linking.
46 */
47public class IntraFileTypeLinkingTest {
48
49 private final YangUtilsParserManager manager = new YangUtilsParserManager();
50
51 /**
52 * Checks self resolution when typedef and leaf using type are siblings.
53 */
54 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053055 public void processSelfResolutionWhenTypeAndTypedefAtRootLevel()
56 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053057
58 YangNode node = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevel.yang");
59
60 // Check whether the data model tree returned is of type module.
Vidyashree Rama7142d9c2016-04-26 15:06:06 +053061 assertThat(node instanceof YangModule, is(true));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053062
63 // Check whether the node type is set properly to module.
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053064 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053065
66 // Check whether the module name is set correctly.
67 YangModule yangNode = (YangModule) node;
68 assertThat(yangNode.getName(), is("Test"));
69
70 ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
71 YangLeaf leafInfo = leafIterator.next();
72
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +053073 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053074 assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053075 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053076
77 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
78 is((YangTypeDef) node.getChild()));
79
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +053080 assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
81
82 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
83
84 // Check for the effective built-in type.
85 assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
86
87 // Check for the restriction.
88 assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
89 assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
90 assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
91 assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +053092 }
93
94 /**
95 * Checks self resolution when typedef and leaf using type are at different
96 * level where typedef is at the root.
97 */
98 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +053099 public void processSelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy()
100 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530101
102 YangNode node =
103 manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtRootTypeTwoLevelInHierarchy.yang");
104
105 // Check whether the data model tree returned is of type module.
106 assertThat((node instanceof YangModule), is(true));
107
108 // Check whether the node type is set properly to module.
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530109 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530110
111 // Check whether the module name is set correctly.
112 YangModule yangNode = (YangModule) node;
113 assertThat(yangNode.getName(), is("Test"));
114
115 YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
116
117 YangList yangList = (YangList) yangContainer.getChild();
118
119 ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
120 YangLeaf leafInfo = leafIterator.next();
121
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530122 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530123 assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530124 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530125
126 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
127 is((YangTypeDef) node.getChild()));
128
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530129 assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
130
131 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
132
133 // Check for the effective built-in type.
134 assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
135
136 // Check for the restriction.
137 assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
138 assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
139 assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
140 assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530141 }
142
143 /**
144 * Checks self resolution when typedef and leaf using type are at different
145 * level where typedef is at the root and defined after parent holder
146 * of type.
147 */
148 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530149 public void processSelfFileLinkingTypedefAtRootIsAfterContainerHavingType()
150 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530151
152 YangNode node =
153 manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtRootIsAfterContainerHavingType.yang");
154
155 // Check whether the data model tree returned is of type module.
156 assertThat((node instanceof YangModule), is(true));
157
158 // Check whether the node type is set properly to module.
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530159 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530160
161 // Check whether the module name is set correctly.
162 YangModule yangNode = (YangModule) node;
163 assertThat(yangNode.getName(), is("Test"));
164
165 YangContainer yangContainer = (YangContainer) node.getChild();
166
167 YangList yangList = (YangList) yangContainer.getChild();
168
169 ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
170 YangLeaf leafInfo = leafIterator.next();
171
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530172 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530173 assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530174 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530175
176 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
177 is((YangTypeDef) node.getChild().getNextSibling()));
178
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530179 assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
180
181 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
182
183 // Check for the effective built-in type.
184 assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
185
186 // Check for the restriction.
187 assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
188 assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
189 assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
190 assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530191 }
192
193 /**
194 * Checks self resolution when typedef and leaf using type are at different
195 * level where typedef is at the level of root+1 and defined after parent
196 * holder of type.
197 */
198 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530199 public void processSelfFileLinkingTypedefAtMiddleLevelAfterParentHolder()
200 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530201
202 YangNode node =
203 manager.getDataModel("src/test/resources/SelfFileLinkingTypedefAtMiddleLevelAfterParentHolder.yang");
204
205 // Check whether the data model tree returned is of type module.
206 assertThat((node instanceof YangModule), is(true));
207
208 // Check whether the node type is set properly to module.
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530209 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530210
211 // Check whether the module name is set correctly.
212 YangModule yangNode = (YangModule) node;
213 assertThat(yangNode.getName(), is("Test"));
214
215 YangContainer yangContainer = (YangContainer) node.getChild();
216
217 YangList yangList = (YangList) yangContainer.getChild();
218
219 ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
220 YangLeaf leafInfo = leafIterator.next();
221
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530222 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530223 assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530224 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530225
226 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
227 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
228
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530229 assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
230
231 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
232
233 // Check for the effective built-in type.
234 assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
235
236 // Check for the restriction.
237 assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
238 assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
239 assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
240 assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530241 }
242
243 /**
244 * Checks self resolution when typedef hierarchical references are present.
245 */
246 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530247 public void processSelfFileLinkingWithTypdefHierarchicalReference()
248 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530249
250 YangNode node =
251 manager.getDataModel("src/test/resources/SelfFileLinkingWithTypdefHierarchicalReference.yang");
252
253 // Check whether the data model tree returned is of type module.
254 assertThat((node instanceof YangModule), is(true));
255
256 // Check whether the node type is set properly to module.
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530257 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530258
259 // Check whether the module name is set correctly.
260 YangModule yangNode = (YangModule) node;
261 assertThat(yangNode.getName(), is("Test"));
262
263 YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
264
265 YangList yangList = (YangList) yangContainer.getChild();
266
267 ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
268 YangLeaf leafInfo = leafIterator.next();
269
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530270 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530271 assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530272 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530273
274 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
275 is((YangTypeDef) yangList.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530276 assertThat(leafInfo.getDataType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530277 is(RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530278
279 YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
280
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530281 assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530282 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530283 assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530284 is(RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530285
286 YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
287
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530288 assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530289 is((YangTypeDef) node.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530290 assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530291 is(RESOLVED));
292
293 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
294
295 // Check for the effective built-in type.
296 assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32));
297
298 // Check for the restriction.
299 assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
300 assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
301 assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
302 assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530303 }
304
305 /**
306 * Checks self resolution when typedef hierarchical references are present
307 * with last type is unresolved.
308 */
309 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530310 public void processSelfFileLinkingWithTypdefHierarchicalRefUnresolved()
311 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530312
313 YangNode node =
314 manager.getDataModel("src/test/resources/SelfFileLinkingWithTypdefHierarchicalRefUnresolved.yang");
315
316 // Check whether the data model tree returned is of type module.
317 assertThat((node instanceof YangModule), is(true));
318
319 // Check whether the node type is set properly to module.
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530320 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530321
322 // Check whether the module name is set correctly.
323 YangModule yangNode = (YangModule) node;
324 assertThat(yangNode.getName(), is("Test"));
325
326 YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
327
328 YangList yangList = (YangList) yangContainer.getChild();
329
330 ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
331 YangLeaf leafInfo = leafIterator.next();
332
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530333 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530334 assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530335 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530336
337 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
338 is((YangTypeDef) yangList.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530339 assertThat(leafInfo.getDataType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530340 is(INTRA_FILE_RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530341
342 YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
343
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530344 assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530345 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530346 assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530347 is(INTRA_FILE_RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530348
349 YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
350
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530351 assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530352 is((YangTypeDef) node.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530353 assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530354 is(INTRA_FILE_RESOLVED));
355
356 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
357
358 // Check for the effective built-in type.
359 assertThat(derivedInfo.getEffectiveBuiltInType(), is(nullValue()));
360
361 // Check for the restriction.
362 assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
363 assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
364 assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
365 assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530366 }
367
368 /**
369 * Checks self resolution when type uses prefix of self module.
370 */
371 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530372 public void processSelfFileLinkingWithTypeWithSelfModulePrefix()
373 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530374
375 YangNode node =
376 manager.getDataModel("src/test/resources/SelfFileLinkingWithTypeWithSelfModulePrefix.yang");
377
378 // Check whether the data model tree returned is of type module.
379 assertThat((node instanceof YangModule), is(true));
380
381 // Check whether the node type is set properly to module.
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530382 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530383
384 // Check whether the module name is set correctly.
385 YangModule yangNode = (YangModule) node;
386 assertThat(yangNode.getName(), is("Test"));
387
388 YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
389
390 YangList yangList = (YangList) yangContainer.getChild();
391
392 ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
393 YangLeaf leafInfo = leafIterator.next();
394
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530395 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530396 assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530397 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530398
399 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
400 is((YangTypeDef) yangList.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530401 assertThat(leafInfo.getDataType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530402 is(RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530403
404 YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
405
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530406 assertThat(((YangDerivedInfo<?>) typeDef1.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530407 is((YangTypeDef) yangContainer.getChild().getNextSibling()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530408 assertThat(typeDef1.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530409 is(RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530410
411 YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
412
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530413 assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530414 is((YangTypeDef) node.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530415 assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530416 is(RESOLVED));
417
418 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
419
420 // Check for the effective built-in type.
421 assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32));
422
423 // Check for the restriction.
424 assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
425 assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
426 assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
427 assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530428 }
429
430 /**
431 * Checks self resolution when some type uses prefix of self module
432 * some uses external prefix.
433 */
434 @Test
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530435 public void processSelfFileLinkingWithTypeWithSelfAndExternalPrefixMix()
436 throws IOException, ParserException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530437
438 YangNode node =
439 manager.getDataModel("src/test/resources/SelfFileLinkingWithTypeWithSelfAndExternalPrefixMix.yang");
440
441 // Check whether the data model tree returned is of type module.
442 assertThat((node instanceof YangModule), is(true));
443
444 // Check whether the node type is set properly to module.
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530445 assertThat(node.getNodeType(), is(MODULE_NODE));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530446
447 // Check whether the module name is set correctly.
448 YangModule yangNode = (YangModule) node;
449 assertThat(yangNode.getName(), is("Test"));
450
451 YangContainer yangContainer = (YangContainer) node.getChild().getNextSibling();
452
453 YangList yangList = (YangList) yangContainer.getChild();
454
455 ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
456 YangLeaf leafInfo = leafIterator.next();
457
Vinod Kumar Se4b9b0c2016-04-30 21:09:15 +0530458 assertThat(leafInfo.getName(), is("invalid-interval"));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530459 assertThat(leafInfo.getDataType().getDataTypeName(), is("FirstClass"));
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530460 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530461
462 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
463 is((YangTypeDef) yangList.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530464 assertThat(leafInfo.getDataType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530465 is(INTRA_FILE_RESOLVED));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530466
467 YangTypeDef typeDef1 = (YangTypeDef) yangList.getChild();
468
469 YangTypeDef typeDef2 = (YangTypeDef) yangContainer.getChild().getNextSibling();
470
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530471 assertThat(((YangDerivedInfo<?>) typeDef2.getTypeDefBaseType().getDataTypeExtendedInfo()).getReferredTypeDef(),
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530472 is((YangTypeDef) node.getChild()));
Vidyashree Rama7142d9c2016-04-26 15:06:06 +0530473 assertThat(typeDef2.getTypeDefBaseType().getResolvableStatus(),
Gaurav Agrawalcfa1c412016-05-03 00:41:48 +0530474 is(RESOLVED));
475
476 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
477
478 // Check for the effective built-in type.
479 assertThat(derivedInfo.getEffectiveBuiltInType(), is(nullValue()));
480
481 // Check for the restriction.
482 assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
483 assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
484 assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
485 assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530486 }
487
488 /**
489 * Check self resolution when type referred typedef is not available in
490 * file.
491 */
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530492 @Test(expected = LinkerException.class)
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530493 public void processSelfResolutionWhenTypeReferredTypedefNotDefined()
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530494 throws IOException, LinkerException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530495
496 YangNode node =
497 manager.getDataModel("src/test/resources/SelfResolutionWhenTypeReferredTypedefNotDefined.yang");
498 }
499
500 /**
501 * Checks self resolution when typedef and leaf using type are at different
502 * level where typedef is is not an ancestor of type.
503 */
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530504 @Test(expected = LinkerException.class)
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530505 public void processSelfFileLinkingTypedefNotFound()
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530506 throws IOException, LinkerException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530507
508 YangNode node = manager.getDataModel("src/test/resources/SelfFileLinkingTypedefNotFound.yang");
509 }
510
511 /**
512 * Checks hierarchical self resolution with self resolution failure scenario.
513 */
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530514 @Test(expected = LinkerException.class)
Vinod Kumar Sd4deb062016-04-15 18:08:57 +0530515 public void processSelfFileLinkingWithHierarchicalTypeFailureScenario()
Gaurav Agrawal95b416c2016-06-07 14:00:26 +0530516 throws IOException, LinkerException {
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530517
518 YangNode node =
519 manager.getDataModel("src/test/resources/SelfFileLinkingWithHierarchicalTypeFailureScenario.yang");
520 }
Gaurav Agrawal0d43bb52016-05-17 18:06:38 +0530521
522 /**
523 * Checks self resolution when typedef and leaf using type are siblings for binary type.
524 */
525 @Test
526 public void processSelfResolutionWhenTypeAndTypedefAtRootLevelForBinary()
527 throws IOException, ParserException {
528
529 YangNode node
530 = manager.getDataModel("src/test/resources/SelfResolutionWhenTypeAndTypedefAtRootLevelForBinary.yang");
531
532 // Check whether the data model tree returned is of type module.
533 assertThat(node instanceof YangModule, is(true));
534
535 // Check whether the node type is set properly to module.
536 assertThat(node.getNodeType(), is(MODULE_NODE));
537
538 // Check whether the module name is set correctly.
539 YangModule yangNode = (YangModule) node;
540 assertThat(yangNode.getName(), is("ospf"));
541
542 ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
543 YangLeaf leafInfo = leafIterator.next();
544
545 assertThat(leafInfo.getName(), is("typedef14"));
546 assertThat(leafInfo.getDataType().getDataTypeName(), is("type14"));
547 assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
548
549 assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
550 is((YangTypeDef) node.getChild()));
551
552 assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
553
554 YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
555
556 // Check for the effective built-in type.
557 assertThat(derivedInfo.getEffectiveBuiltInType(), is(BINARY));
558
559 // Check for the restriction.
560 assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
561 assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
562 assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
563 assertThat(derivedInfo.getResolvedExtendedInfo(), is(nullValue()));
564 }
Gaurav Agrawald9d6cc82016-03-29 02:17:23 +0530565}