Mahesh Poojary S
Committed by Patrick Liu

[ONOS-4938] Defect fix: range interval

Change-Id: I3229d35fb7c80da3bcf150d52ed7e7eba72bb4c8
...@@ -165,7 +165,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>> ...@@ -165,7 +165,7 @@ public class YangRangeRestriction<T extends YangBuiltInDataTypeInfo<T>>
165 165
166 T curMaxvalue = getMaxRestrictedvalue(); 166 T curMaxvalue = getMaxRestrictedvalue();
167 167
168 - if (newInterval.getStartValue().compareTo(curMaxvalue) != 1) { 168 + if (newInterval.getStartValue().compareTo(curMaxvalue) < 1) {
169 throw new DataModelException( 169 throw new DataModelException(
170 "New added range interval is lesser than the old interval(s)"); 170 "New added range interval is lesser than the old interval(s)");
171 } 171 }
......
...@@ -289,7 +289,10 @@ public class YangType<T> ...@@ -289,7 +289,10 @@ public class YangType<T>
289 if (getDataTypeExtendedInfo() == null) { 289 if (getDataTypeExtendedInfo() == null) {
290 getDataObjectFromString(value, getDataType()); 290 getDataObjectFromString(value, getDataType());
291 } else { 291 } else {
292 - ((YangRangeRestriction) getDataTypeExtendedInfo()).isValidValueString(value); 292 + if (!((YangRangeRestriction) getDataTypeExtendedInfo()).isValidValueString(value)) {
293 + throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
294 + getDataType());
295 + }
293 } 296 }
294 break; 297 break;
295 } 298 }
...@@ -308,14 +311,14 @@ public class YangType<T> ...@@ -308,14 +311,14 @@ public class YangType<T>
308 && ((YangStringRestriction) getDataTypeExtendedInfo()) 311 && ((YangStringRestriction) getDataTypeExtendedInfo())
309 .isValidStringOnPatternRestriction(value))) { 312 .isValidStringOnPatternRestriction(value))) {
310 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + 313 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
311 - "string"); 314 + getDataType());
312 } 315 }
313 break; 316 break;
314 } 317 }
315 case BOOLEAN: 318 case BOOLEAN:
316 if (!(value.equals(DataModelUtils.TRUE) || value.equals(DataModelUtils.FALSE))) { 319 if (!(value.equals(DataModelUtils.TRUE) || value.equals(DataModelUtils.FALSE))) {
317 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + 320 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
318 - "boolean"); 321 + getDataType());
319 } 322 }
320 break; 323 break;
321 case ENUMERATION: { 324 case ENUMERATION: {
...@@ -331,7 +334,7 @@ public class YangType<T> ...@@ -331,7 +334,7 @@ public class YangType<T>
331 334
332 if (!isValidated) { 335 if (!isValidated) {
333 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + 336 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
334 - "union"); 337 + getDataType());
335 } 338 }
336 break; 339 break;
337 } 340 }
...@@ -339,14 +342,14 @@ public class YangType<T> ...@@ -339,14 +342,14 @@ public class YangType<T>
339 YangBits bits = (YangBits) getDataTypeExtendedInfo(); 342 YangBits bits = (YangBits) getDataTypeExtendedInfo();
340 if (bits.fromString(value) == null) { 343 if (bits.fromString(value) == null) {
341 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + 344 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
342 - "bits"); 345 + getDataType());
343 } 346 }
344 break; 347 break;
345 } 348 }
346 case BINARY: { 349 case BINARY: {
347 if (!isValidBinary(value, (YangRangeRestriction) getDataTypeExtendedInfo())) { 350 if (!isValidBinary(value, (YangRangeRestriction) getDataTypeExtendedInfo())) {
348 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + 351 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
349 - "binary"); 352 + getDataType());
350 } 353 }
351 break; 354 break;
352 } 355 }
...@@ -360,8 +363,11 @@ public class YangType<T> ...@@ -360,8 +363,11 @@ public class YangType<T>
360 break; 363 break;
361 } 364 }
362 case EMPTY: { 365 case EMPTY: {
366 + if (value.length() > 0) {
363 throw new DataTypeException("YANG file error : Input value \"" + value 367 throw new DataTypeException("YANG file error : Input value \"" + value
364 - + "\" is not a allowed for a data type " + "empty"); 368 + + "\" is not allowed for a data type " + getDataType());
369 + }
370 + break;
365 } 371 }
366 case UNION: { 372 case UNION: {
367 ListIterator<YangType<?>> listIterator = ((YangUnion) getDataTypeExtendedInfo()).getTypeList() 373 ListIterator<YangType<?>> listIterator = ((YangUnion) getDataTypeExtendedInfo()).getTypeList()
...@@ -380,7 +386,7 @@ public class YangType<T> ...@@ -380,7 +386,7 @@ public class YangType<T>
380 386
381 if (!isValidated) { 387 if (!isValidated) {
382 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + 388 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
383 - "union"); 389 + getDataType());
384 } 390 }
385 break; 391 break;
386 } 392 }
...@@ -399,7 +405,7 @@ public class YangType<T> ...@@ -399,7 +405,7 @@ public class YangType<T>
399 if (!((YangRangeRestriction) ((YangDerivedInfo) getDataTypeExtendedInfo()) 405 if (!((YangRangeRestriction) ((YangDerivedInfo) getDataTypeExtendedInfo())
400 .getResolvedExtendedInfo()).isValidValueString(value)) { 406 .getResolvedExtendedInfo()).isValidValueString(value)) {
401 throw new DataTypeException("YANG file error : Input value \"" + value 407 throw new DataTypeException("YANG file error : Input value \"" + value
402 - + "\" is not a valid " + dataType.toString()); 408 + + "\" is not a valid " + dataType);
403 } 409 }
404 } 410 }
405 } else if (dataType == YangDataTypes.STRING) { 411 } else if (dataType == YangDataTypes.STRING) {
...@@ -410,20 +416,20 @@ public class YangType<T> ...@@ -410,20 +416,20 @@ public class YangType<T>
410 if (!(stringRestriction.isValidStringOnLengthRestriction(value) && 416 if (!(stringRestriction.isValidStringOnLengthRestriction(value) &&
411 stringRestriction.isValidStringOnPatternRestriction(value))) { 417 stringRestriction.isValidStringOnPatternRestriction(value))) {
412 throw new DataTypeException("YANG file error : Input value \"" + value 418 throw new DataTypeException("YANG file error : Input value \"" + value
413 - + "\" is not a valid " + dataType.toString()); 419 + + "\" is not a valid " + dataType);
414 } 420 }
415 } 421 }
416 } else if (dataType == YangDataTypes.BITS) { 422 } else if (dataType == YangDataTypes.BITS) {
417 YangBits bits = (YangBits) getDataTypeExtendedInfo(); 423 YangBits bits = (YangBits) getDataTypeExtendedInfo();
418 if (bits.fromString(value) == null) { 424 if (bits.fromString(value) == null) {
419 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + 425 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
420 - "bits"); 426 + dataType);
421 } 427 }
422 } else if (dataType == YangDataTypes.BINARY) { 428 } else if (dataType == YangDataTypes.BINARY) {
423 if (!isValidBinary(value, (YangRangeRestriction) ((YangDerivedInfo) 429 if (!isValidBinary(value, (YangRangeRestriction) ((YangDerivedInfo)
424 getDataTypeExtendedInfo()).getResolvedExtendedInfo())) { 430 getDataTypeExtendedInfo()).getResolvedExtendedInfo())) {
425 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " + 431 throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
426 - dataType.toString()); 432 + dataType);
427 } 433 }
428 } else if (dataType == YangDataTypes.DECIMAL64) { 434 } else if (dataType == YangDataTypes.DECIMAL64) {
429 YangDerivedInfo derivedInfo = (YangDerivedInfo) getDataTypeExtendedInfo(); 435 YangDerivedInfo derivedInfo = (YangDerivedInfo) getDataTypeExtendedInfo();
...@@ -438,8 +444,8 @@ public class YangType<T> ...@@ -438,8 +444,8 @@ public class YangType<T>
438 break; 444 break;
439 } 445 }
440 default: { 446 default: {
441 - throw new DataTypeException("YANG file error : Input value \"" + value + "\" is for unsupported " + 447 + throw new DataTypeException("YANG file error : Input value \"" + value + "\" received for " +
442 - "data type."); 448 + "unsupported data type " + getDataType());
443 } 449 }
444 } 450 }
445 } 451 }
......
...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.datamodel.utils.builtindatatype; ...@@ -18,7 +18,6 @@ package org.onosproject.yangutils.datamodel.utils.builtindatatype;
18 18
19 import java.io.Serializable; 19 import java.io.Serializable;
20 import java.math.BigInteger; 20 import java.math.BigInteger;
21 -import java.util.regex.Pattern;
22 21
23 /** 22 /**
24 * Handles the YANG's Uint16 data type processing. 23 * Handles the YANG's Uint16 data type processing.
...@@ -40,11 +39,6 @@ public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64>, Serializ ...@@ -40,11 +39,6 @@ public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64>, Serializ
40 private static final String MAX_KEYWORD = "max"; 39 private static final String MAX_KEYWORD = "max";
41 40
42 /** 41 /**
43 - * YANG's Integer value pattern.
44 - */
45 - private static final Pattern NON_NEGATIVE_INTEGER_PATTERN = Pattern.compile("[0-9]+");
46 -
47 - /**
48 * Valid minimum value of YANG's Uint64. 42 * Valid minimum value of YANG's Uint64.
49 */ 43 */
50 public static final BigInteger MIN_VALUE = BigInteger.valueOf(0); 44 public static final BigInteger MIN_VALUE = BigInteger.valueOf(0);
...@@ -71,12 +65,14 @@ public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64>, Serializ ...@@ -71,12 +65,14 @@ public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64>, Serializ
71 value = MIN_VALUE; 65 value = MIN_VALUE;
72 } else if (valueInString.matches(MAX_KEYWORD)) { 66 } else if (valueInString.matches(MAX_KEYWORD)) {
73 value = MAX_VALUE; 67 value = MAX_VALUE;
74 - } else if (NON_NEGATIVE_INTEGER_PATTERN.matcher(valueInString).matches()) {
75 - value = new BigInteger(valueInString);
76 } else { 68 } else {
69 + try {
70 + value = new BigInteger(valueInString);
71 + } catch (Exception e) {
77 throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " + 72 throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
78 "uint64."); 73 "uint64.");
79 } 74 }
75 + }
80 76
81 if (value.compareTo(MIN_VALUE) < 0) { 77 if (value.compareTo(MIN_VALUE) < 0) {
82 throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value " 78 throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
......
...@@ -180,6 +180,17 @@ public class DefaultListenerTest { ...@@ -180,6 +180,17 @@ public class DefaultListenerTest {
180 } 180 }
181 181
182 /** 182 /**
183 + * Validates default invalid value in typedef.
184 + */
185 + @Test
186 + public void processDefaultInvalidValueInTypedef() throws IOException, ParserException {
187 + thrown.expect(DataTypeException.class);
188 + thrown.expectMessage("YANG file error : Input value \"0\" is not a valid INT32");
189 +
190 + manager.getDataModel("src/test/resources/default/DefaultInvalidValueWithRangeInTypedef.yang");
191 + }
192 +
193 + /**
183 * Validates default value decimal64 in leaf. 194 * Validates default value decimal64 in leaf.
184 */ 195 */
185 @Test 196 @Test
...@@ -250,7 +261,7 @@ public class DefaultListenerTest { ...@@ -250,7 +261,7 @@ public class DefaultListenerTest {
250 @Test 261 @Test
251 public void processDefaultInvalidValueStringInLeaf() throws IOException, ParserException { 262 public void processDefaultInvalidValueStringInLeaf() throws IOException, ParserException {
252 thrown.expect(DataTypeException.class); 263 thrown.expect(DataTypeException.class);
253 - thrown.expectMessage("YANG file error : Input value \"2bB2bB\" is not a valid string"); 264 + thrown.expectMessage("YANG file error : Input value \"2bB2bB\" is not a valid STRING");
254 265
255 manager.getDataModel("src/test/resources/default/DefaultInvalidValueStringInLeaf.yang"); 266 manager.getDataModel("src/test/resources/default/DefaultInvalidValueStringInLeaf.yang");
256 } 267 }
...@@ -288,7 +299,7 @@ public class DefaultListenerTest { ...@@ -288,7 +299,7 @@ public class DefaultListenerTest {
288 @Test 299 @Test
289 public void processDefaultInvalidValueBooleanInLeaf() throws IOException, ParserException { 300 public void processDefaultInvalidValueBooleanInLeaf() throws IOException, ParserException {
290 thrown.expect(DataTypeException.class); 301 thrown.expect(DataTypeException.class);
291 - thrown.expectMessage("YANG file error : Input value \"yes\" is not a valid boolean"); 302 + thrown.expectMessage("YANG file error : Input value \"yes\" is not a valid BOOLEAN");
292 303
293 manager.getDataModel("src/test/resources/default/DefaultInvalidValueBooleanInLeaf.yang"); 304 manager.getDataModel("src/test/resources/default/DefaultInvalidValueBooleanInLeaf.yang");
294 } 305 }
...@@ -326,7 +337,7 @@ public class DefaultListenerTest { ...@@ -326,7 +337,7 @@ public class DefaultListenerTest {
326 @Test 337 @Test
327 public void processDefaultInvalidValueEnumberationInLeaf() throws IOException, ParserException { 338 public void processDefaultInvalidValueEnumberationInLeaf() throws IOException, ParserException {
328 thrown.expect(DataTypeException.class); 339 thrown.expect(DataTypeException.class);
329 - thrown.expectMessage("YANG file error : Input value \"xyz\" is not a valid union"); 340 + thrown.expectMessage("YANG file error : Input value \"xyz\" is not a valid ENUMERATION");
330 341
331 manager.getDataModel("src/test/resources/default/DefaultInvalidValueEnumerationInLeaf.yang"); 342 manager.getDataModel("src/test/resources/default/DefaultInvalidValueEnumerationInLeaf.yang");
332 } 343 }
...@@ -364,7 +375,7 @@ public class DefaultListenerTest { ...@@ -364,7 +375,7 @@ public class DefaultListenerTest {
364 @Test 375 @Test
365 public void processDefaultInvalidValueBitsInLeaf() throws IOException, ParserException { 376 public void processDefaultInvalidValueBitsInLeaf() throws IOException, ParserException {
366 thrown.expect(DataTypeException.class); 377 thrown.expect(DataTypeException.class);
367 - thrown.expectMessage("YANG file error : Input value \"xyz\" is not a valid bits"); 378 + thrown.expectMessage("YANG file error : Input value \"xyz\" is not a valid BITS");
368 379
369 manager.getDataModel("src/test/resources/default/DefaultInvalidValueBitsInLeaf.yang"); 380 manager.getDataModel("src/test/resources/default/DefaultInvalidValueBitsInLeaf.yang");
370 } 381 }
...@@ -402,7 +413,7 @@ public class DefaultListenerTest { ...@@ -402,7 +413,7 @@ public class DefaultListenerTest {
402 @Test 413 @Test
403 public void processDefaultInvlaidValueBinaryInLeaf() throws IOException, ParserException { 414 public void processDefaultInvlaidValueBinaryInLeaf() throws IOException, ParserException {
404 thrown.expect(DataTypeException.class); 415 thrown.expect(DataTypeException.class);
405 - thrown.expectMessage("YANG file error : Input value \"000\" is not a valid binary"); 416 + thrown.expectMessage("YANG file error : Input value \"000\" is not a valid BINARY");
406 417
407 manager.getDataModel("src/test/resources/default/DefaultInvalidValueBinaryInLeaf.yang"); 418 manager.getDataModel("src/test/resources/default/DefaultInvalidValueBinaryInLeaf.yang");
408 } 419 }
...@@ -413,7 +424,7 @@ public class DefaultListenerTest { ...@@ -413,7 +424,7 @@ public class DefaultListenerTest {
413 @Test 424 @Test
414 public void processDefaultValueEmptyInLeaf() throws IOException, ParserException { 425 public void processDefaultValueEmptyInLeaf() throws IOException, ParserException {
415 thrown.expect(DataTypeException.class); 426 thrown.expect(DataTypeException.class);
416 - thrown.expectMessage("YANG file error : Input value \"something\" is not a allowed for a data type empty"); 427 + thrown.expectMessage("YANG file error : Input value \"something\" is not allowed for a data type EMPTY");
417 428
418 manager.getDataModel("src/test/resources/default/DefaultValueEmptyInLeaf.yang"); 429 manager.getDataModel("src/test/resources/default/DefaultValueEmptyInLeaf.yang");
419 } 430 }
...@@ -451,7 +462,7 @@ public class DefaultListenerTest { ...@@ -451,7 +462,7 @@ public class DefaultListenerTest {
451 @Test 462 @Test
452 public void processDefaultInvalidValueUnionInLeaf() throws IOException, ParserException { 463 public void processDefaultInvalidValueUnionInLeaf() throws IOException, ParserException {
453 thrown.expect(DataTypeException.class); 464 thrown.expect(DataTypeException.class);
454 - thrown.expectMessage("YANG file error : Input value \"xyz\" is not a valid union"); 465 + thrown.expectMessage("YANG file error : Input value \"xyz\" is not a valid UNION");
455 466
456 manager.getDataModel("src/test/resources/default/DefaultInvalidValueUnionInLeaf.yang"); 467 manager.getDataModel("src/test/resources/default/DefaultInvalidValueUnionInLeaf.yang");
457 } 468 }
......
...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.plugin.manager; ...@@ -19,6 +19,7 @@ package org.onosproject.yangutils.plugin.manager;
19 import java.io.IOException; 19 import java.io.IOException;
20 import java.math.BigInteger; 20 import java.math.BigInteger;
21 import java.util.ListIterator; 21 import java.util.ListIterator;
22 +
22 import org.junit.Test; 23 import org.junit.Test;
23 import org.onosproject.yangutils.datamodel.YangDerivedInfo; 24 import org.onosproject.yangutils.datamodel.YangDerivedInfo;
24 import org.onosproject.yangutils.datamodel.YangLeaf; 25 import org.onosproject.yangutils.datamodel.YangLeaf;
...@@ -28,8 +29,11 @@ import org.onosproject.yangutils.datamodel.YangPatternRestriction; ...@@ -28,8 +29,11 @@ import org.onosproject.yangutils.datamodel.YangPatternRestriction;
28 import org.onosproject.yangutils.datamodel.YangRangeInterval; 29 import org.onosproject.yangutils.datamodel.YangRangeInterval;
29 import org.onosproject.yangutils.datamodel.YangRangeRestriction; 30 import org.onosproject.yangutils.datamodel.YangRangeRestriction;
30 import org.onosproject.yangutils.datamodel.YangStringRestriction; 31 import org.onosproject.yangutils.datamodel.YangStringRestriction;
32 +import org.onosproject.yangutils.datamodel.YangType;
31 import org.onosproject.yangutils.datamodel.YangTypeDef; 33 import org.onosproject.yangutils.datamodel.YangTypeDef;
32 import org.onosproject.yangutils.datamodel.exceptions.DataModelException; 34 import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
35 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
36 +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangInt16;
33 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangInt32; 37 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangInt32;
34 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64; 38 import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
35 import org.onosproject.yangutils.linker.exceptions.LinkerException; 39 import org.onosproject.yangutils.linker.exceptions.LinkerException;
...@@ -292,6 +296,79 @@ public final class RestrictionResolutionTest { ...@@ -292,6 +296,79 @@ public final class RestrictionResolutionTest {
292 } 296 }
293 297
294 /** 298 /**
299 + * Checks range restriction in referred typedef.
300 + */
301 + @Test
302 + public void processRangeRestrictionInRefTypedef()
303 + throws IOException, ParserException, DataModelException {
304 +
305 + YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInRefTypedef.yang");
306 +
307 + // Check whether the data model tree returned is of type module.
308 + assertThat(node instanceof YangModule, is(true));
309 +
310 + // Check whether the node type is set properly to module.
311 + assertThat(node.getNodeType(), is(MODULE_NODE));
312 +
313 + // Check whether the module name is set correctly.
314 + YangModule yangNode = (YangModule) node;
315 + assertThat(yangNode.getName(), is("Test"));
316 +
317 + // check top typedef
318 + YangTypeDef topTypedef = (YangTypeDef) yangNode.getChild();
319 + assertThat(topTypedef.getName(), is("Num3"));
320 + YangType type = topTypedef.getTypeList().iterator().next();
321 + assertThat(type.getDataType(), is(YangDataTypes.INT16));
322 + assertThat(type.getDataTypeName(), is("int16"));
323 +
324 + // Check for the restriction value.
325 + YangRangeRestriction rangeRestriction = (YangRangeRestriction) type.getDataTypeExtendedInfo();
326 + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
327 + .listIterator();
328 + YangRangeInterval rangeInterval1 = rangeListIterator.next();
329 + assertThat((int) ((YangInt16) rangeInterval1.getStartValue()).getValue(), is(-32000));
330 + assertThat((int) ((YangInt16) rangeInterval1.getEndValue()).getValue(), is(4));
331 +
332 + YangRangeInterval rangeInterval2 = rangeListIterator.next();
333 + assertThat((int) ((YangInt16) rangeInterval2.getStartValue()).getValue(), is(32767));
334 + assertThat((int) ((YangInt16) rangeInterval2.getEndValue()).getValue(), is(32767));
335 +
336 + // check referred typedef
337 + YangTypeDef refTypedef = (YangTypeDef) topTypedef.getNextSibling();
338 + assertThat(refTypedef.getName(), is("Num6"));
339 + YangType refType = refTypedef.getTypeList().iterator().next();
340 + assertThat(refType.getDataType(), is(YangDataTypes.DERIVED));
341 + assertThat(refType.getDataTypeName(), is("Num3"));
342 + YangDerivedInfo<YangRangeRestriction> derivedInfo =
343 + (YangDerivedInfo<YangRangeRestriction>) refType.getDataTypeExtendedInfo();
344 +
345 + // Check for the restriction value.
346 + rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo();
347 + rangeListIterator = rangeRestriction.getAscendingRangeIntervals().listIterator();
348 + rangeInterval1 = rangeListIterator.next();
349 + assertThat((int) ((YangInt16) rangeInterval1.getStartValue()).getValue(), is(-3));
350 + assertThat((int) ((YangInt16) rangeInterval1.getEndValue()).getValue(), is(-3));
351 +
352 + rangeInterval2 = rangeListIterator.next();
353 + assertThat((int) ((YangInt16) rangeInterval2.getStartValue()).getValue(), is(-2));
354 + assertThat((int) ((YangInt16) rangeInterval2.getEndValue()).getValue(), is(2));
355 +
356 + YangRangeInterval rangeInterval3 = rangeListIterator.next();
357 + assertThat((int) ((YangInt16) rangeInterval3.getStartValue()).getValue(), is(3));
358 + assertThat((int) ((YangInt16) rangeInterval3.getEndValue()).getValue(), is(3));
359 + }
360 +
361 + /**
362 + * Checks invalid range restriction in referred typedef.
363 + */
364 + @Test(expected = LinkerException.class)
365 + public void processInvalidRangeRestrictionInRefTypedef()
366 + throws IOException, ParserException, DataModelException {
367 +
368 + manager.getDataModel("src/test/resources/RangeRestrictionInvalidInRefTypedef.yang");
369 + }
370 +
371 + /**
295 * Checks range restriction in referred type. 372 * Checks range restriction in referred type.
296 */ 373 */
297 @Test 374 @Test
......
1 +module Test {
2 + namespace "urn:ietf:params:xml:ns:yang:yt3";
3 + prefix "yt3";
4 +
5 + organization
6 + "YANG Language Design Team";
7 +
8 + contact
9 + "Andy Bierman";
10 +
11 + description
12 + "YANG test module 3.";
13 +
14 + revision 2007-12-04 {
15 + description "Initial revision.";
16 + }
17 +
18 + typedef Num3 {
19 + units seconds;
20 + type int16 {
21 + range "-32000 .. 4 | max";
22 + }
23 + description "test 3";
24 + }
25 +
26 + typedef Num6 {
27 + description "test 6";
28 + type Num3 {
29 + range "-3 | -2 .. +2 | 3";
30 + }
31 + default 0;
32 + }
33 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + namespace "urn:ietf:params:xml:ns:yang:yt3";
3 + prefix "yt3";
4 +
5 + organization
6 + "YANG Language Design Team";
7 +
8 + contact
9 + "Andy Bierman";
10 +
11 + description
12 + "YANG test module 3.";
13 +
14 + revision 2007-12-04 {
15 + description "Initial revision.";
16 + }
17 +
18 + typedef Num3 {
19 + units seconds;
20 + type int16 {
21 + range "-3 | -2 .. +2 | 3";
22 + }
23 + description "test 3";
24 + }
25 +
26 + typedef Num6 {
27 + description "test 6";
28 + type Num3 {
29 + range "-32000 .. 4 | max" ;
30 + }
31 + default 0;
32 + }
33 +}
...\ No newline at end of file ...\ No newline at end of file
1 +module Test {
2 + yang-version 1;
3 + namespace http://huawei.com;
4 + prefix Ant;
5 + typedef hello {
6 + type int32 {
7 + range "1..4 | 10..20";
8 + }
9 + default "0";
10 + }
11 +}