Committed by
Gerrit Code Review
YANG: Junit testcases for restricions resolution
Change-Id: I35b8a579f924af50a5e2192bdac36dc94784198e
Showing
18 changed files
with
1086 additions
and
0 deletions
utils/yangutils/src/test/java/org/onosproject/yangutils/linker/RestrictionResolutionTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.yangutils.linker; | ||
18 | + | ||
19 | +import java.io.IOException; | ||
20 | +import java.math.BigInteger; | ||
21 | +import java.util.ListIterator; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onosproject.yangutils.datamodel.YangDerivedInfo; | ||
24 | +import org.onosproject.yangutils.datamodel.YangLeaf; | ||
25 | +import org.onosproject.yangutils.datamodel.YangModule; | ||
26 | +import org.onosproject.yangutils.datamodel.YangNode; | ||
27 | +import org.onosproject.yangutils.datamodel.YangPatternRestriction; | ||
28 | +import org.onosproject.yangutils.datamodel.YangRangeInterval; | ||
29 | +import org.onosproject.yangutils.datamodel.YangRangeRestriction; | ||
30 | +import org.onosproject.yangutils.datamodel.YangStringRestriction; | ||
31 | +import org.onosproject.yangutils.datamodel.YangTypeDef; | ||
32 | +import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | ||
33 | +import org.onosproject.yangutils.parser.exceptions.ParserException; | ||
34 | +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | ||
35 | +import org.onosproject.yangutils.utils.builtindatatype.YangInt32; | ||
36 | +import org.onosproject.yangutils.utils.builtindatatype.YangUint64; | ||
37 | + | ||
38 | +import static org.hamcrest.CoreMatchers.nullValue; | ||
39 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
40 | +import static org.hamcrest.core.Is.is; | ||
41 | +import static org.hamcrest.core.IsNull.notNullValue; | ||
42 | +import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED; | ||
43 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED; | ||
44 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32; | ||
45 | +import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING; | ||
46 | +import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE; | ||
47 | + | ||
48 | +/** | ||
49 | + * Test cases for testing restriction resolution. | ||
50 | + */ | ||
51 | +public final class RestrictionResolutionTest { | ||
52 | + | ||
53 | + private final YangUtilsParserManager manager = new YangUtilsParserManager(); | ||
54 | + | ||
55 | + /** | ||
56 | + * Checks length restriction in typedef. | ||
57 | + */ | ||
58 | + @Test | ||
59 | + public void processLengthRestrictionInTypedef() | ||
60 | + throws IOException, ParserException, DataModelException { | ||
61 | + | ||
62 | + YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInTypedef.yang"); | ||
63 | + | ||
64 | + // Check whether the data model tree returned is of type module. | ||
65 | + assertThat(node instanceof YangModule, is(true)); | ||
66 | + | ||
67 | + // Check whether the node type is set properly to module. | ||
68 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
69 | + | ||
70 | + // Check whether the module name is set correctly. | ||
71 | + YangModule yangNode = (YangModule) node; | ||
72 | + assertThat(yangNode.getName(), is("Test")); | ||
73 | + | ||
74 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
75 | + YangLeaf leafInfo = leafIterator.next(); | ||
76 | + | ||
77 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
78 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
79 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
80 | + | ||
81 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
82 | + is((YangTypeDef) node.getChild())); | ||
83 | + | ||
84 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
85 | + | ||
86 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
87 | + | ||
88 | + // Check for the effective built-in type. | ||
89 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); | ||
90 | + | ||
91 | + // Check for the restriction. | ||
92 | + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); | ||
93 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
94 | + assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); | ||
95 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
96 | + | ||
97 | + // Check for the restriction value. | ||
98 | + YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
99 | + YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction(); | ||
100 | + | ||
101 | + ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals() | ||
102 | + .listIterator(); | ||
103 | + | ||
104 | + YangRangeInterval rangeInterval = lengthListIterator.next(); | ||
105 | + | ||
106 | + assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0))); | ||
107 | + assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100))); | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Checks length restriction in referred type. | ||
112 | + */ | ||
113 | + @Test | ||
114 | + public void processLengthRestrictionInRefType() | ||
115 | + throws IOException, ParserException, DataModelException { | ||
116 | + | ||
117 | + YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInRefType.yang"); | ||
118 | + | ||
119 | + // Check whether the data model tree returned is of type module. | ||
120 | + assertThat(node instanceof YangModule, is(true)); | ||
121 | + | ||
122 | + // Check whether the node type is set properly to module. | ||
123 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
124 | + | ||
125 | + // Check whether the module name is set correctly. | ||
126 | + YangModule yangNode = (YangModule) node; | ||
127 | + assertThat(yangNode.getName(), is("Test")); | ||
128 | + | ||
129 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
130 | + YangLeaf leafInfo = leafIterator.next(); | ||
131 | + | ||
132 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
133 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
134 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
135 | + | ||
136 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
137 | + is((YangTypeDef) node.getChild())); | ||
138 | + | ||
139 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
140 | + | ||
141 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
142 | + | ||
143 | + // Check for the effective built-in type. | ||
144 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); | ||
145 | + | ||
146 | + // Check for the restriction. | ||
147 | + assertThat(derivedInfo.getLengthRestrictionString(), is(notNullValue())); | ||
148 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
149 | + assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); | ||
150 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
151 | + | ||
152 | + // Check for the restriction value. | ||
153 | + YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
154 | + YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction(); | ||
155 | + | ||
156 | + ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals() | ||
157 | + .listIterator(); | ||
158 | + | ||
159 | + YangRangeInterval rangeInterval = lengthListIterator.next(); | ||
160 | + | ||
161 | + assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0))); | ||
162 | + assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100))); | ||
163 | + } | ||
164 | + | ||
165 | + /** | ||
166 | + * Checks length restriction in typedef and in type with stricter value. | ||
167 | + */ | ||
168 | + @Test | ||
169 | + public void processLengthRestrictionInTypedefAndTypeValid() | ||
170 | + throws IOException, ParserException, DataModelException { | ||
171 | + | ||
172 | + YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInTypedefAndTypeValid.yang"); | ||
173 | + | ||
174 | + // Check whether the data model tree returned is of type module. | ||
175 | + assertThat(node instanceof YangModule, is(true)); | ||
176 | + | ||
177 | + // Check whether the node type is set properly to module. | ||
178 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
179 | + | ||
180 | + // Check whether the module name is set correctly. | ||
181 | + YangModule yangNode = (YangModule) node; | ||
182 | + assertThat(yangNode.getName(), is("Test")); | ||
183 | + | ||
184 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
185 | + YangLeaf leafInfo = leafIterator.next(); | ||
186 | + | ||
187 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
188 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
189 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
190 | + | ||
191 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
192 | + is((YangTypeDef) node.getChild())); | ||
193 | + | ||
194 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
195 | + | ||
196 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
197 | + | ||
198 | + // Check for the effective built-in type. | ||
199 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); | ||
200 | + | ||
201 | + // Check for the restriction. | ||
202 | + assertThat(derivedInfo.getLengthRestrictionString(), is(notNullValue())); | ||
203 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
204 | + assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); | ||
205 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
206 | + | ||
207 | + // Check for the restriction value. | ||
208 | + YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
209 | + YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction(); | ||
210 | + | ||
211 | + ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals() | ||
212 | + .listIterator(); | ||
213 | + | ||
214 | + YangRangeInterval rangeInterval1 = lengthListIterator.next(); | ||
215 | + | ||
216 | + assertThat(((YangUint64) rangeInterval1.getStartValue()).getValue(), is(BigInteger.valueOf(0))); | ||
217 | + assertThat(((YangUint64) rangeInterval1.getEndValue()).getValue(), is(BigInteger.valueOf(20))); | ||
218 | + | ||
219 | + YangRangeInterval rangeInterval2 = lengthListIterator.next(); | ||
220 | + | ||
221 | + assertThat(((YangUint64) rangeInterval2.getStartValue()).getValue(), is(BigInteger.valueOf(201))); | ||
222 | + assertThat(((YangUint64) rangeInterval2.getEndValue()).getValue(), is(BigInteger.valueOf(300))); | ||
223 | + } | ||
224 | + | ||
225 | + /** | ||
226 | + * Checks length restriction in typedef and in type with not stricter value. | ||
227 | + */ | ||
228 | + @Test(expected = ParserException.class) | ||
229 | + public void processLengthRestrictionInTypedefAndTypeInValid() | ||
230 | + throws IOException, ParserException, DataModelException { | ||
231 | + YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInTypedefAndTypeInValid.yang"); | ||
232 | + } | ||
233 | + | ||
234 | + /** | ||
235 | + * Checks range restriction in typedef. | ||
236 | + */ | ||
237 | + @Test | ||
238 | + public void processRangeRestrictionInTypedef() | ||
239 | + throws IOException, ParserException, DataModelException { | ||
240 | + | ||
241 | + YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInTypedef.yang"); | ||
242 | + | ||
243 | + // Check whether the data model tree returned is of type module. | ||
244 | + assertThat(node instanceof YangModule, is(true)); | ||
245 | + | ||
246 | + // Check whether the node type is set properly to module. | ||
247 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
248 | + | ||
249 | + // Check whether the module name is set correctly. | ||
250 | + YangModule yangNode = (YangModule) node; | ||
251 | + assertThat(yangNode.getName(), is("Test")); | ||
252 | + | ||
253 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
254 | + YangLeaf leafInfo = leafIterator.next(); | ||
255 | + | ||
256 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
257 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
258 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
259 | + | ||
260 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
261 | + is((YangTypeDef) node.getChild())); | ||
262 | + | ||
263 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
264 | + | ||
265 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
266 | + | ||
267 | + // Check for the effective built-in type. | ||
268 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32)); | ||
269 | + | ||
270 | + // Check for the restriction. | ||
271 | + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); | ||
272 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
273 | + assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); | ||
274 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
275 | + | ||
276 | + // Check for the restriction value. | ||
277 | + YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
278 | + | ||
279 | + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals() | ||
280 | + .listIterator(); | ||
281 | + | ||
282 | + YangRangeInterval rangeInterval1 = rangeListIterator.next(); | ||
283 | + | ||
284 | + assertThat(((YangInt32) rangeInterval1.getStartValue()).getValue(), is(1)); | ||
285 | + assertThat(((YangInt32) rangeInterval1.getEndValue()).getValue(), is(4)); | ||
286 | + | ||
287 | + YangRangeInterval rangeInterval2 = rangeListIterator.next(); | ||
288 | + | ||
289 | + assertThat(((YangInt32) rangeInterval2.getStartValue()).getValue(), is(10)); | ||
290 | + assertThat(((YangInt32) rangeInterval2.getEndValue()).getValue(), is(20)); | ||
291 | + } | ||
292 | + | ||
293 | + /** | ||
294 | + * Checks range restriction in referred type. | ||
295 | + */ | ||
296 | + @Test | ||
297 | + public void processRangeRestrictionInRefType() | ||
298 | + throws IOException, ParserException, DataModelException { | ||
299 | + | ||
300 | + YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInRefType.yang"); | ||
301 | + | ||
302 | + // Check whether the data model tree returned is of type module. | ||
303 | + assertThat(node instanceof YangModule, is(true)); | ||
304 | + | ||
305 | + // Check whether the node type is set properly to module. | ||
306 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
307 | + | ||
308 | + // Check whether the module name is set correctly. | ||
309 | + YangModule yangNode = (YangModule) node; | ||
310 | + assertThat(yangNode.getName(), is("Test")); | ||
311 | + | ||
312 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
313 | + YangLeaf leafInfo = leafIterator.next(); | ||
314 | + | ||
315 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
316 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
317 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
318 | + | ||
319 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
320 | + is((YangTypeDef) node.getChild())); | ||
321 | + | ||
322 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
323 | + | ||
324 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
325 | + | ||
326 | + // Check for the effective built-in type. | ||
327 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32)); | ||
328 | + | ||
329 | + // Check for the restriction. | ||
330 | + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); | ||
331 | + assertThat(derivedInfo.getRangeRestrictionString(), is(notNullValue())); | ||
332 | + assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); | ||
333 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
334 | + | ||
335 | + // Check for the restriction value. | ||
336 | + YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
337 | + | ||
338 | + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals() | ||
339 | + .listIterator(); | ||
340 | + | ||
341 | + YangRangeInterval rangeInterval1 = rangeListIterator.next(); | ||
342 | + | ||
343 | + assertThat(((YangInt32) rangeInterval1.getStartValue()).getValue(), is(1)); | ||
344 | + assertThat(((YangInt32) rangeInterval1.getEndValue()).getValue(), is(4)); | ||
345 | + | ||
346 | + YangRangeInterval rangeInterval2 = rangeListIterator.next(); | ||
347 | + | ||
348 | + assertThat(((YangInt32) rangeInterval2.getStartValue()).getValue(), is(10)); | ||
349 | + assertThat(((YangInt32) rangeInterval2.getEndValue()).getValue(), is(20)); | ||
350 | + } | ||
351 | + | ||
352 | + /** | ||
353 | + * Checks range restriction in typedef and stricter in referred type. | ||
354 | + */ | ||
355 | + @Test | ||
356 | + public void processRangeRestrictionInRefTypeAndTypedefValid() | ||
357 | + throws IOException, ParserException, DataModelException { | ||
358 | + | ||
359 | + YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInRefTypeAndTypedefValid.yang"); | ||
360 | + | ||
361 | + // Check whether the data model tree returned is of type module. | ||
362 | + assertThat(node instanceof YangModule, is(true)); | ||
363 | + | ||
364 | + // Check whether the node type is set properly to module. | ||
365 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
366 | + | ||
367 | + // Check whether the module name is set correctly. | ||
368 | + YangModule yangNode = (YangModule) node; | ||
369 | + assertThat(yangNode.getName(), is("Test")); | ||
370 | + | ||
371 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
372 | + YangLeaf leafInfo = leafIterator.next(); | ||
373 | + | ||
374 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
375 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
376 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
377 | + | ||
378 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
379 | + is((YangTypeDef) node.getChild())); | ||
380 | + | ||
381 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
382 | + | ||
383 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
384 | + | ||
385 | + // Check for the effective built-in type. | ||
386 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32)); | ||
387 | + | ||
388 | + // Check for the restriction. | ||
389 | + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); | ||
390 | + assertThat(derivedInfo.getRangeRestrictionString(), is(notNullValue())); | ||
391 | + assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); | ||
392 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
393 | + | ||
394 | + // Check for the restriction value. | ||
395 | + YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
396 | + | ||
397 | + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals() | ||
398 | + .listIterator(); | ||
399 | + | ||
400 | + YangRangeInterval rangeInterval1 = rangeListIterator.next(); | ||
401 | + | ||
402 | + assertThat(((YangInt32) rangeInterval1.getStartValue()).getValue(), is(1)); | ||
403 | + assertThat(((YangInt32) rangeInterval1.getEndValue()).getValue(), is(4)); | ||
404 | + | ||
405 | + YangRangeInterval rangeInterval2 = rangeListIterator.next(); | ||
406 | + | ||
407 | + assertThat(((YangInt32) rangeInterval2.getStartValue()).getValue(), is(10)); | ||
408 | + assertThat(((YangInt32) rangeInterval2.getEndValue()).getValue(), is(20)); | ||
409 | + } | ||
410 | + | ||
411 | + /** | ||
412 | + * Checks range restriction in typedef and not stricter in referred type. | ||
413 | + */ | ||
414 | + @Test(expected = ParserException.class) | ||
415 | + public void processRangeRestrictionInRefTypeAndTypedefInValid() | ||
416 | + throws IOException, ParserException, DataModelException { | ||
417 | + YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInRefTypeAndTypedefInValid.yang"); | ||
418 | + } | ||
419 | + | ||
420 | + /** | ||
421 | + * Checks range restriction for string. | ||
422 | + */ | ||
423 | + @Test(expected = ParserException.class) | ||
424 | + public void processRangeRestrictionInString() | ||
425 | + throws IOException, ParserException, DataModelException { | ||
426 | + YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInString.yang"); | ||
427 | + } | ||
428 | + | ||
429 | + /** | ||
430 | + * Checks range restriction for string in referred type. | ||
431 | + */ | ||
432 | + @Test(expected = ParserException.class) | ||
433 | + public void processRangeRestrictionInStringInRefType() | ||
434 | + throws IOException, ParserException, DataModelException { | ||
435 | + YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInStringInRefType.yang"); | ||
436 | + } | ||
437 | + | ||
438 | + /** | ||
439 | + * Checks pattern restriction in typedef. | ||
440 | + */ | ||
441 | + @Test | ||
442 | + public void processPatternRestrictionInTypedef() | ||
443 | + throws IOException, ParserException, DataModelException { | ||
444 | + | ||
445 | + YangNode node = manager.getDataModel("src/test/resources/PatternRestrictionInTypedef.yang"); | ||
446 | + | ||
447 | + // Check whether the data model tree returned is of type module. | ||
448 | + assertThat(node instanceof YangModule, is(true)); | ||
449 | + | ||
450 | + // Check whether the node type is set properly to module. | ||
451 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
452 | + | ||
453 | + // Check whether the module name is set correctly. | ||
454 | + YangModule yangNode = (YangModule) node; | ||
455 | + assertThat(yangNode.getName(), is("Test")); | ||
456 | + | ||
457 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
458 | + YangLeaf leafInfo = leafIterator.next(); | ||
459 | + | ||
460 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
461 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
462 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
463 | + | ||
464 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
465 | + is((YangTypeDef) node.getChild())); | ||
466 | + | ||
467 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
468 | + | ||
469 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
470 | + | ||
471 | + // Check for the effective built-in type. | ||
472 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); | ||
473 | + | ||
474 | + // Check for the restriction. | ||
475 | + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); | ||
476 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
477 | + assertThat(derivedInfo.getPatternRestriction(), is(nullValue())); | ||
478 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
479 | + | ||
480 | + // Check for the restriction value. | ||
481 | + YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
482 | + YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction(); | ||
483 | + | ||
484 | + ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator(); | ||
485 | + String pattern1 = patternListIterator.next(); | ||
486 | + | ||
487 | + assertThat(pattern1, is("[a-zA-Z]")); | ||
488 | + } | ||
489 | + | ||
490 | + /** | ||
491 | + * Checks pattern restriction in referred type. | ||
492 | + */ | ||
493 | + @Test | ||
494 | + public void processPatternRestrictionInRefType() | ||
495 | + throws IOException, ParserException, DataModelException { | ||
496 | + | ||
497 | + YangNode node = manager.getDataModel("src/test/resources/PatternRestrictionInRefType.yang"); | ||
498 | + | ||
499 | + // Check whether the data model tree returned is of type module. | ||
500 | + assertThat(node instanceof YangModule, is(true)); | ||
501 | + | ||
502 | + // Check whether the node type is set properly to module. | ||
503 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
504 | + | ||
505 | + // Check whether the module name is set correctly. | ||
506 | + YangModule yangNode = (YangModule) node; | ||
507 | + assertThat(yangNode.getName(), is("Test")); | ||
508 | + | ||
509 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
510 | + YangLeaf leafInfo = leafIterator.next(); | ||
511 | + | ||
512 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
513 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
514 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
515 | + | ||
516 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
517 | + is((YangTypeDef) node.getChild())); | ||
518 | + | ||
519 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
520 | + | ||
521 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
522 | + | ||
523 | + // Check for the effective built-in type. | ||
524 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); | ||
525 | + | ||
526 | + // Check for the restriction. | ||
527 | + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); | ||
528 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
529 | + assertThat(derivedInfo.getPatternRestriction(), is(notNullValue())); | ||
530 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
531 | + | ||
532 | + // Check for the restriction value. | ||
533 | + YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
534 | + YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction(); | ||
535 | + | ||
536 | + ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator(); | ||
537 | + String pattern1 = patternListIterator.next(); | ||
538 | + | ||
539 | + assertThat(pattern1, is("[a-zA-Z]")); | ||
540 | + } | ||
541 | + | ||
542 | + /** | ||
543 | + * Checks pattern restriction in referred type and typedef. | ||
544 | + */ | ||
545 | + @Test | ||
546 | + public void processPatternRestrictionInRefTypeAndTypedef() | ||
547 | + throws IOException, ParserException, DataModelException { | ||
548 | + | ||
549 | + YangNode node = manager.getDataModel("src/test/resources/PatternRestrictionInRefTypeAndTypedef.yang"); | ||
550 | + | ||
551 | + // Check whether the data model tree returned is of type module. | ||
552 | + assertThat(node instanceof YangModule, is(true)); | ||
553 | + | ||
554 | + // Check whether the node type is set properly to module. | ||
555 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
556 | + | ||
557 | + // Check whether the module name is set correctly. | ||
558 | + YangModule yangNode = (YangModule) node; | ||
559 | + assertThat(yangNode.getName(), is("Test")); | ||
560 | + | ||
561 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
562 | + YangLeaf leafInfo = leafIterator.next(); | ||
563 | + | ||
564 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
565 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
566 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
567 | + | ||
568 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
569 | + is((YangTypeDef) node.getChild())); | ||
570 | + | ||
571 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
572 | + | ||
573 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
574 | + | ||
575 | + // Check for the effective built-in type. | ||
576 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); | ||
577 | + | ||
578 | + // Check for the restriction. | ||
579 | + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); | ||
580 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
581 | + assertThat(derivedInfo.getPatternRestriction(), is(notNullValue())); | ||
582 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
583 | + | ||
584 | + // Check for the restriction value. | ||
585 | + YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
586 | + YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction(); | ||
587 | + | ||
588 | + ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator(); | ||
589 | + String pattern1 = patternListIterator.next(); | ||
590 | + | ||
591 | + assertThat(pattern1, is("[a-zA-Z]")); | ||
592 | + | ||
593 | + String pattern2 = patternListIterator.next(); | ||
594 | + | ||
595 | + assertThat(pattern2, is("[0-9]")); | ||
596 | + } | ||
597 | + | ||
598 | + /** | ||
599 | + * Checks multiple pattern restriction in referred type and typedef. | ||
600 | + */ | ||
601 | + @Test | ||
602 | + public void processMultiplePatternRestriction() | ||
603 | + throws IOException, ParserException, DataModelException { | ||
604 | + | ||
605 | + YangNode node = manager.getDataModel("src/test/resources/MultiplePatternRestrictionInRefTypeAndTypedef.yang"); | ||
606 | + | ||
607 | + // Check whether the data model tree returned is of type module. | ||
608 | + assertThat(node instanceof YangModule, is(true)); | ||
609 | + | ||
610 | + // Check whether the node type is set properly to module. | ||
611 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
612 | + | ||
613 | + // Check whether the module name is set correctly. | ||
614 | + YangModule yangNode = (YangModule) node; | ||
615 | + assertThat(yangNode.getName(), is("Test")); | ||
616 | + | ||
617 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
618 | + YangLeaf leafInfo = leafIterator.next(); | ||
619 | + | ||
620 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
621 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
622 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
623 | + | ||
624 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
625 | + is((YangTypeDef) node.getChild())); | ||
626 | + | ||
627 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
628 | + | ||
629 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
630 | + | ||
631 | + // Check for the effective built-in type. | ||
632 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); | ||
633 | + | ||
634 | + // Check for the restriction. | ||
635 | + assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue())); | ||
636 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
637 | + assertThat(derivedInfo.getPatternRestriction(), is(notNullValue())); | ||
638 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
639 | + | ||
640 | + // Check for the restriction value. | ||
641 | + YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
642 | + YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction(); | ||
643 | + | ||
644 | + ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator(); | ||
645 | + String pattern1 = patternListIterator.next(); | ||
646 | + | ||
647 | + assertThat(pattern1, is("[a-z]")); | ||
648 | + | ||
649 | + String pattern2 = patternListIterator.next(); | ||
650 | + | ||
651 | + assertThat(pattern2, is("[A-Z]")); | ||
652 | + | ||
653 | + String pattern3 = patternListIterator.next(); | ||
654 | + | ||
655 | + assertThat(pattern3, is("[0-9]")); | ||
656 | + | ||
657 | + String pattern4 = patternListIterator.next(); | ||
658 | + | ||
659 | + assertThat(pattern4, is("[\\n]")); | ||
660 | + } | ||
661 | + | ||
662 | + /** | ||
663 | + * Checks multiple pattern and length restriction in referred type and | ||
664 | + * typedef. | ||
665 | + */ | ||
666 | + @Test | ||
667 | + public void processMultiplePatternAndLengthRestriction() | ||
668 | + throws IOException, ParserException, DataModelException { | ||
669 | + | ||
670 | + YangNode node = manager.getDataModel("src/test/resources/MultiplePatternAndLengthRestriction.yang"); | ||
671 | + | ||
672 | + // Check whether the data model tree returned is of type module. | ||
673 | + assertThat(node instanceof YangModule, is(true)); | ||
674 | + | ||
675 | + // Check whether the node type is set properly to module. | ||
676 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
677 | + | ||
678 | + // Check whether the module name is set correctly. | ||
679 | + YangModule yangNode = (YangModule) node; | ||
680 | + assertThat(yangNode.getName(), is("Test")); | ||
681 | + | ||
682 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
683 | + YangLeaf leafInfo = leafIterator.next(); | ||
684 | + | ||
685 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
686 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
687 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
688 | + | ||
689 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
690 | + is((YangTypeDef) node.getChild())); | ||
691 | + | ||
692 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
693 | + | ||
694 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
695 | + | ||
696 | + // Check for the effective built-in type. | ||
697 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); | ||
698 | + | ||
699 | + // Check for the restriction. | ||
700 | + assertThat(derivedInfo.getLengthRestrictionString(), is(notNullValue())); | ||
701 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
702 | + assertThat(derivedInfo.getPatternRestriction(), is(notNullValue())); | ||
703 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
704 | + | ||
705 | + // Check for the restriction value. | ||
706 | + YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
707 | + | ||
708 | + // Check for pattern restriction. | ||
709 | + YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction(); | ||
710 | + ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator(); | ||
711 | + String pattern1 = patternListIterator.next(); | ||
712 | + | ||
713 | + assertThat(pattern1, is("[a-z]")); | ||
714 | + | ||
715 | + String pattern2 = patternListIterator.next(); | ||
716 | + | ||
717 | + assertThat(pattern2, is("[A-Z]")); | ||
718 | + | ||
719 | + String pattern3 = patternListIterator.next(); | ||
720 | + | ||
721 | + assertThat(pattern3, is("[0-9]")); | ||
722 | + | ||
723 | + String pattern4 = patternListIterator.next(); | ||
724 | + | ||
725 | + assertThat(pattern4, is("[\\n]")); | ||
726 | + | ||
727 | + // Check for length restriction. | ||
728 | + YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction(); | ||
729 | + ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals() | ||
730 | + .listIterator(); | ||
731 | + | ||
732 | + YangRangeInterval rangeInterval1 = lengthListIterator.next(); | ||
733 | + | ||
734 | + assertThat(((YangUint64) rangeInterval1.getStartValue()).getValue(), is(BigInteger.valueOf(0))); | ||
735 | + assertThat(((YangUint64) rangeInterval1.getEndValue()).getValue(), is(BigInteger.valueOf(20))); | ||
736 | + | ||
737 | + YangRangeInterval rangeInterval2 = lengthListIterator.next(); | ||
738 | + | ||
739 | + assertThat(((YangUint64) rangeInterval2.getStartValue()).getValue(), is(BigInteger.valueOf(201))); | ||
740 | + assertThat(((YangUint64) rangeInterval2.getEndValue()).getValue(), is(BigInteger.valueOf(300))); | ||
741 | + } | ||
742 | + | ||
743 | + /** | ||
744 | + * Checks multiple pattern and length restriction in referred type and | ||
745 | + * typedef. | ||
746 | + */ | ||
747 | + @Test | ||
748 | + public void processMultiplePatternAndLengthRestrictionValid() | ||
749 | + throws IOException, ParserException, DataModelException { | ||
750 | + | ||
751 | + YangNode node = manager.getDataModel("src/test/resources/MultiplePatternAndLengthRestrictionValid.yang"); | ||
752 | + | ||
753 | + // Check whether the data model tree returned is of type module. | ||
754 | + assertThat(node instanceof YangModule, is(true)); | ||
755 | + | ||
756 | + // Check whether the node type is set properly to module. | ||
757 | + assertThat(node.getNodeType(), is(MODULE_NODE)); | ||
758 | + | ||
759 | + // Check whether the module name is set correctly. | ||
760 | + YangModule yangNode = (YangModule) node; | ||
761 | + assertThat(yangNode.getName(), is("Test")); | ||
762 | + | ||
763 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
764 | + YangLeaf leafInfo = leafIterator.next(); | ||
765 | + | ||
766 | + assertThat(leafInfo.getName(), is("invalid-interval")); | ||
767 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("hello")); | ||
768 | + assertThat(leafInfo.getDataType().getDataType(), is(DERIVED)); | ||
769 | + | ||
770 | + assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(), | ||
771 | + is((YangTypeDef) node.getChild())); | ||
772 | + | ||
773 | + assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED)); | ||
774 | + | ||
775 | + YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo(); | ||
776 | + | ||
777 | + // Check for the effective built-in type. | ||
778 | + assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING)); | ||
779 | + | ||
780 | + // Check for the restriction. | ||
781 | + assertThat(derivedInfo.getLengthRestrictionString(), is(notNullValue())); | ||
782 | + assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue())); | ||
783 | + assertThat(derivedInfo.getPatternRestriction(), is(notNullValue())); | ||
784 | + assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue())); | ||
785 | + | ||
786 | + // Check for the restriction value. | ||
787 | + YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
788 | + | ||
789 | + // Check for pattern restriction. | ||
790 | + YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction(); | ||
791 | + ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator(); | ||
792 | + String pattern1 = patternListIterator.next(); | ||
793 | + | ||
794 | + assertThat(pattern1, is("[a-z]")); | ||
795 | + | ||
796 | + String pattern2 = patternListIterator.next(); | ||
797 | + | ||
798 | + assertThat(pattern2, is("[A-Z]")); | ||
799 | + | ||
800 | + String pattern3 = patternListIterator.next(); | ||
801 | + | ||
802 | + assertThat(pattern3, is("[0-9]")); | ||
803 | + | ||
804 | + String pattern4 = patternListIterator.next(); | ||
805 | + | ||
806 | + assertThat(pattern4, is("[\\n]")); | ||
807 | + | ||
808 | + // Check for length restriction. | ||
809 | + YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction(); | ||
810 | + ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals() | ||
811 | + .listIterator(); | ||
812 | + | ||
813 | + YangRangeInterval rangeInterval1 = lengthListIterator.next(); | ||
814 | + | ||
815 | + assertThat(((YangUint64) rangeInterval1.getStartValue()).getValue(), is(BigInteger.valueOf(0))); | ||
816 | + assertThat(((YangUint64) rangeInterval1.getEndValue()).getValue(), is(BigInteger.valueOf(20))); | ||
817 | + | ||
818 | + YangRangeInterval rangeInterval2 = lengthListIterator.next(); | ||
819 | + | ||
820 | + assertThat(((YangUint64) rangeInterval2.getStartValue()).getValue(), is(BigInteger.valueOf(100))); | ||
821 | + assertThat(((YangUint64) rangeInterval2.getEndValue()).getValue(), | ||
822 | + is(new BigInteger("18446744073709551615"))); | ||
823 | + } | ||
824 | + | ||
825 | + /** | ||
826 | + * Checks multiple pattern and length restriction in referred type and | ||
827 | + * typedef invalid scenario. | ||
828 | + */ | ||
829 | + @Test(expected = ParserException.class) | ||
830 | + public void processMultiplePatternAndLengthRestrictionInValid() | ||
831 | + throws IOException, ParserException, DataModelException { | ||
832 | + YangNode node = manager.getDataModel("src/test/resources/MultiplePatternAndLengthRestrictionInValid.yang"); | ||
833 | + } | ||
834 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + leaf invalid-interval { | ||
6 | + type hello { | ||
7 | + pattern "[a-z]"; | ||
8 | + pattern "[A-Z]"; | ||
9 | + length "min..20 | 201..max"; | ||
10 | + } | ||
11 | + } | ||
12 | + typedef hello { | ||
13 | + type string { | ||
14 | + pattern "[0-9]"; | ||
15 | + pattern "[\n]"; | ||
16 | + length "0..100 | 101..200 | 201..300"; | ||
17 | + } | ||
18 | + } | ||
19 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + leaf invalid-interval { | ||
6 | + type hello { | ||
7 | + pattern "[a-z]"; | ||
8 | + pattern "[A-Z]"; | ||
9 | + length "min..20 | 100..max"; | ||
10 | + } | ||
11 | + } | ||
12 | + typedef hello { | ||
13 | + type string { | ||
14 | + pattern "[0-9]"; | ||
15 | + pattern "[\n]"; | ||
16 | + length "0..100 | 101..200 | 201..300"; | ||
17 | + } | ||
18 | + } | ||
19 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + leaf invalid-interval { | ||
6 | + type hello { | ||
7 | + pattern "[a-z]"; | ||
8 | + pattern "[A-Z]"; | ||
9 | + length "min..20 | 100..max"; | ||
10 | + } | ||
11 | + } | ||
12 | + typedef hello { | ||
13 | + type string { | ||
14 | + pattern "[0-9]"; | ||
15 | + pattern "[\n]"; | ||
16 | + } | ||
17 | + } | ||
18 | +} |
-
Please register or login to post a comment