YANG: Junit testcases for restricions resolution

Change-Id: I35b8a579f924af50a5e2192bdac36dc94784198e
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/RestrictionResolutionTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/RestrictionResolutionTest.java
new file mode 100644
index 0000000..4b473f4
--- /dev/null
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/linker/RestrictionResolutionTest.java
@@ -0,0 +1,834 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.linker;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.ListIterator;
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangDerivedInfo;
+import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangModule;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangPatternRestriction;
+import org.onosproject.yangutils.datamodel.YangRangeInterval;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.YangStringRestriction;
+import org.onosproject.yangutils.datamodel.YangTypeDef;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+import org.onosproject.yangutils.utils.builtindatatype.YangInt32;
+import org.onosproject.yangutils.utils.builtindatatype.YangUint64;
+
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.onosproject.yangutils.datamodel.ResolvableStatus.RESOLVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
+import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
+
+/**
+ * Test cases for testing restriction resolution.
+ */
+public final class RestrictionResolutionTest {
+
+    private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+    /**
+     * Checks length restriction in typedef.
+     */
+    @Test
+    public void processLengthRestrictionInTypedef()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInTypedef.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo();
+        YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
+
+        ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
+                .listIterator();
+
+        YangRangeInterval rangeInterval = lengthListIterator.next();
+
+        assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
+        assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100)));
+    }
+
+    /**
+     * Checks length restriction in referred type.
+     */
+    @Test
+    public void processLengthRestrictionInRefType()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInRefType.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(notNullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo();
+        YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
+
+        ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
+                .listIterator();
+
+        YangRangeInterval rangeInterval = lengthListIterator.next();
+
+        assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
+        assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(100)));
+    }
+
+    /**
+     * Checks length restriction in typedef and in type with stricter value.
+     */
+    @Test
+    public void processLengthRestrictionInTypedefAndTypeValid()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInTypedefAndTypeValid.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(notNullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo();
+        YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
+
+        ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
+                .listIterator();
+
+        YangRangeInterval rangeInterval1 = lengthListIterator.next();
+
+        assertThat(((YangUint64) rangeInterval1.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
+        assertThat(((YangUint64) rangeInterval1.getEndValue()).getValue(), is(BigInteger.valueOf(20)));
+
+        YangRangeInterval rangeInterval2 = lengthListIterator.next();
+
+        assertThat(((YangUint64) rangeInterval2.getStartValue()).getValue(), is(BigInteger.valueOf(201)));
+        assertThat(((YangUint64) rangeInterval2.getEndValue()).getValue(), is(BigInteger.valueOf(300)));
+    }
+
+    /**
+     * Checks length restriction in typedef and in type with not stricter value.
+     */
+    @Test(expected = ParserException.class)
+    public void processLengthRestrictionInTypedefAndTypeInValid()
+            throws IOException, ParserException, DataModelException {
+        YangNode node = manager.getDataModel("src/test/resources/LengthRestrictionInTypedefAndTypeInValid.yang");
+    }
+
+    /**
+     * Checks range restriction in typedef.
+     */
+    @Test
+    public void processRangeRestrictionInTypedef()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInTypedef.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo();
+
+        ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
+                .listIterator();
+
+        YangRangeInterval rangeInterval1 = rangeListIterator.next();
+
+        assertThat(((YangInt32) rangeInterval1.getStartValue()).getValue(), is(1));
+        assertThat(((YangInt32) rangeInterval1.getEndValue()).getValue(), is(4));
+
+        YangRangeInterval rangeInterval2 = rangeListIterator.next();
+
+        assertThat(((YangInt32) rangeInterval2.getStartValue()).getValue(), is(10));
+        assertThat(((YangInt32) rangeInterval2.getEndValue()).getValue(), is(20));
+    }
+
+    /**
+     * Checks range restriction in referred type.
+     */
+    @Test
+    public void processRangeRestrictionInRefType()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInRefType.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(notNullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo();
+
+        ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
+                .listIterator();
+
+        YangRangeInterval rangeInterval1 = rangeListIterator.next();
+
+        assertThat(((YangInt32) rangeInterval1.getStartValue()).getValue(), is(1));
+        assertThat(((YangInt32) rangeInterval1.getEndValue()).getValue(), is(4));
+
+        YangRangeInterval rangeInterval2 = rangeListIterator.next();
+
+        assertThat(((YangInt32) rangeInterval2.getStartValue()).getValue(), is(10));
+        assertThat(((YangInt32) rangeInterval2.getEndValue()).getValue(), is(20));
+    }
+
+    /**
+     * Checks range restriction in typedef and stricter in referred type.
+     */
+    @Test
+    public void processRangeRestrictionInRefTypeAndTypedefValid()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInRefTypeAndTypedefValid.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(INT32));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(notNullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo();
+
+        ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
+                .listIterator();
+
+        YangRangeInterval rangeInterval1 = rangeListIterator.next();
+
+        assertThat(((YangInt32) rangeInterval1.getStartValue()).getValue(), is(1));
+        assertThat(((YangInt32) rangeInterval1.getEndValue()).getValue(), is(4));
+
+        YangRangeInterval rangeInterval2 = rangeListIterator.next();
+
+        assertThat(((YangInt32) rangeInterval2.getStartValue()).getValue(), is(10));
+        assertThat(((YangInt32) rangeInterval2.getEndValue()).getValue(), is(20));
+    }
+
+    /**
+     * Checks range restriction in typedef and not stricter in referred type.
+     */
+    @Test(expected = ParserException.class)
+    public void processRangeRestrictionInRefTypeAndTypedefInValid()
+            throws IOException, ParserException, DataModelException {
+        YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInRefTypeAndTypedefInValid.yang");
+    }
+
+    /**
+     * Checks range restriction for string.
+     */
+    @Test(expected = ParserException.class)
+    public void processRangeRestrictionInString()
+            throws IOException, ParserException, DataModelException {
+        YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInString.yang");
+    }
+
+    /**
+     * Checks range restriction for string in referred type.
+     */
+    @Test(expected = ParserException.class)
+    public void processRangeRestrictionInStringInRefType()
+            throws IOException, ParserException, DataModelException {
+        YangNode node = manager.getDataModel("src/test/resources/RangeRestrictionInStringInRefType.yang");
+    }
+
+    /**
+     * Checks pattern restriction in typedef.
+     */
+    @Test
+    public void processPatternRestrictionInTypedef()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/PatternRestrictionInTypedef.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(nullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo();
+        YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction();
+
+        ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator();
+        String pattern1 = patternListIterator.next();
+
+        assertThat(pattern1, is("[a-zA-Z]"));
+    }
+
+    /**
+     * Checks pattern restriction in referred type.
+     */
+    @Test
+    public void processPatternRestrictionInRefType()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/PatternRestrictionInRefType.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(notNullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo();
+        YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction();
+
+        ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator();
+        String pattern1 = patternListIterator.next();
+
+        assertThat(pattern1, is("[a-zA-Z]"));
+    }
+
+    /**
+     * Checks pattern restriction in referred type and typedef.
+     */
+    @Test
+    public void processPatternRestrictionInRefTypeAndTypedef()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/PatternRestrictionInRefTypeAndTypedef.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(notNullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo();
+        YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction();
+
+        ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator();
+        String pattern1 = patternListIterator.next();
+
+        assertThat(pattern1, is("[a-zA-Z]"));
+
+        String pattern2 = patternListIterator.next();
+
+        assertThat(pattern2, is("[0-9]"));
+    }
+
+    /**
+     * Checks multiple pattern restriction in referred type and typedef.
+     */
+    @Test
+    public void processMultiplePatternRestriction()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/MultiplePatternRestrictionInRefTypeAndTypedef.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(notNullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo();
+        YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction();
+
+        ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator();
+        String pattern1 = patternListIterator.next();
+
+        assertThat(pattern1, is("[a-z]"));
+
+        String pattern2 = patternListIterator.next();
+
+        assertThat(pattern2, is("[A-Z]"));
+
+        String pattern3 = patternListIterator.next();
+
+        assertThat(pattern3, is("[0-9]"));
+
+        String pattern4 = patternListIterator.next();
+
+        assertThat(pattern4, is("[\\n]"));
+    }
+
+    /**
+     * Checks multiple pattern and length restriction in referred type and
+     * typedef.
+     */
+    @Test
+    public void processMultiplePatternAndLengthRestriction()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/MultiplePatternAndLengthRestriction.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(notNullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(notNullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo();
+
+        // Check for pattern restriction.
+        YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction();
+        ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator();
+        String pattern1 = patternListIterator.next();
+
+        assertThat(pattern1, is("[a-z]"));
+
+        String pattern2 = patternListIterator.next();
+
+        assertThat(pattern2, is("[A-Z]"));
+
+        String pattern3 = patternListIterator.next();
+
+        assertThat(pattern3, is("[0-9]"));
+
+        String pattern4 = patternListIterator.next();
+
+        assertThat(pattern4, is("[\\n]"));
+
+        // Check for length restriction.
+        YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
+        ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
+                .listIterator();
+
+        YangRangeInterval rangeInterval1 = lengthListIterator.next();
+
+        assertThat(((YangUint64) rangeInterval1.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
+        assertThat(((YangUint64) rangeInterval1.getEndValue()).getValue(), is(BigInteger.valueOf(20)));
+
+        YangRangeInterval rangeInterval2 = lengthListIterator.next();
+
+        assertThat(((YangUint64) rangeInterval2.getStartValue()).getValue(), is(BigInteger.valueOf(201)));
+        assertThat(((YangUint64) rangeInterval2.getEndValue()).getValue(), is(BigInteger.valueOf(300)));
+    }
+
+    /**
+     * Checks multiple pattern and length restriction in referred type and
+     * typedef.
+     */
+    @Test
+    public void processMultiplePatternAndLengthRestrictionValid()
+            throws IOException, ParserException, DataModelException {
+
+        YangNode node = manager.getDataModel("src/test/resources/MultiplePatternAndLengthRestrictionValid.yang");
+
+        // Check whether the data model tree returned is of type module.
+        assertThat(node instanceof YangModule, is(true));
+
+        // Check whether the node type is set properly to module.
+        assertThat(node.getNodeType(), is(MODULE_NODE));
+
+        // Check whether the module name is set correctly.
+        YangModule yangNode = (YangModule) node;
+        assertThat(yangNode.getName(), is("Test"));
+
+        ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+        YangLeaf leafInfo = leafIterator.next();
+
+        assertThat(leafInfo.getName(), is("invalid-interval"));
+        assertThat(leafInfo.getDataType().getDataTypeName(), is("hello"));
+        assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+        assertThat(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef(),
+                is((YangTypeDef) node.getChild()));
+
+        assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+        YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+        // Check for the effective built-in type.
+        assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+        // Check for the restriction.
+        assertThat(derivedInfo.getLengthRestrictionString(), is(notNullValue()));
+        assertThat(derivedInfo.getRangeRestrictionString(), is(nullValue()));
+        assertThat(derivedInfo.getPatternRestriction(), is(notNullValue()));
+        assertThat(derivedInfo.getResolvedExtendedInfo(), is(notNullValue()));
+
+        // Check for the restriction value.
+        YangStringRestriction stringRestriction = (YangStringRestriction) derivedInfo.getResolvedExtendedInfo();
+
+        // Check for pattern restriction.
+        YangPatternRestriction patternRestriction = stringRestriction.getPatternRestriction();
+        ListIterator<String> patternListIterator = patternRestriction.getPatternList().listIterator();
+        String pattern1 = patternListIterator.next();
+
+        assertThat(pattern1, is("[a-z]"));
+
+        String pattern2 = patternListIterator.next();
+
+        assertThat(pattern2, is("[A-Z]"));
+
+        String pattern3 = patternListIterator.next();
+
+        assertThat(pattern3, is("[0-9]"));
+
+        String pattern4 = patternListIterator.next();
+
+        assertThat(pattern4, is("[\\n]"));
+
+        // Check for length restriction.
+        YangRangeRestriction lengthRestriction = stringRestriction.getLengthRestriction();
+        ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
+                .listIterator();
+
+        YangRangeInterval rangeInterval1 = lengthListIterator.next();
+
+        assertThat(((YangUint64) rangeInterval1.getStartValue()).getValue(), is(BigInteger.valueOf(0)));
+        assertThat(((YangUint64) rangeInterval1.getEndValue()).getValue(), is(BigInteger.valueOf(20)));
+
+        YangRangeInterval rangeInterval2 = lengthListIterator.next();
+
+        assertThat(((YangUint64) rangeInterval2.getStartValue()).getValue(), is(BigInteger.valueOf(100)));
+        assertThat(((YangUint64) rangeInterval2.getEndValue()).getValue(),
+                is(new BigInteger("18446744073709551615")));
+    }
+
+    /**
+     * Checks multiple pattern and length restriction in referred type and
+     * typedef invalid scenario.
+     */
+    @Test(expected = ParserException.class)
+    public void processMultiplePatternAndLengthRestrictionInValid()
+            throws IOException, ParserException, DataModelException {
+        YangNode node = manager.getDataModel("src/test/resources/MultiplePatternAndLengthRestrictionInValid.yang");
+    }
+}
diff --git a/utils/yangutils/src/test/resources/LengthRestrictionInRefType.yang b/utils/yangutils/src/test/resources/LengthRestrictionInRefType.yang
new file mode 100644
index 0000000..54684f4
--- /dev/null
+++ b/utils/yangutils/src/test/resources/LengthRestrictionInRefType.yang
@@ -0,0 +1,13 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            length "0..100";
+        }
+    }
+    typedef hello {
+        type string;
+    }
+}
diff --git a/utils/yangutils/src/test/resources/LengthRestrictionInTypedef.yang b/utils/yangutils/src/test/resources/LengthRestrictionInTypedef.yang
new file mode 100644
index 0000000..17baeec
--- /dev/null
+++ b/utils/yangutils/src/test/resources/LengthRestrictionInTypedef.yang
@@ -0,0 +1,13 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello;
+    }
+    typedef hello {
+        type string {
+            length "0..100";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/LengthRestrictionInTypedefAndTypeInValid.yang b/utils/yangutils/src/test/resources/LengthRestrictionInTypedefAndTypeInValid.yang
new file mode 100644
index 0000000..65ed7de
--- /dev/null
+++ b/utils/yangutils/src/test/resources/LengthRestrictionInTypedefAndTypeInValid.yang
@@ -0,0 +1,15 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            length "min..20 | 200..max";
+        }
+    }
+    typedef hello {
+        type string {
+            length "0..100 | 101..200 | 201..300";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/LengthRestrictionInTypedefAndTypeValid.yang b/utils/yangutils/src/test/resources/LengthRestrictionInTypedefAndTypeValid.yang
new file mode 100644
index 0000000..eca2691
--- /dev/null
+++ b/utils/yangutils/src/test/resources/LengthRestrictionInTypedefAndTypeValid.yang
@@ -0,0 +1,15 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            length "min..20 | 201..max";
+        }
+    }
+    typedef hello {
+        type string {
+            length "0..100 | 101..200 | 201..300";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/MultiplePatternAndLengthRestriction.yang b/utils/yangutils/src/test/resources/MultiplePatternAndLengthRestriction.yang
new file mode 100644
index 0000000..d971643
--- /dev/null
+++ b/utils/yangutils/src/test/resources/MultiplePatternAndLengthRestriction.yang
@@ -0,0 +1,19 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            pattern "[a-z]";
+            pattern "[A-Z]";
+            length "min..20 | 201..max";
+        }
+    }
+    typedef hello {
+        type string {
+            pattern "[0-9]";
+            pattern "[\n]";
+            length "0..100 | 101..200 | 201..300";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/MultiplePatternAndLengthRestrictionInValid.yang b/utils/yangutils/src/test/resources/MultiplePatternAndLengthRestrictionInValid.yang
new file mode 100644
index 0000000..7ba3ef9
--- /dev/null
+++ b/utils/yangutils/src/test/resources/MultiplePatternAndLengthRestrictionInValid.yang
@@ -0,0 +1,19 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            pattern "[a-z]";
+            pattern "[A-Z]";
+            length "min..20 | 100..max";
+        }
+    }
+    typedef hello {
+        type string {
+            pattern "[0-9]";
+            pattern "[\n]";
+            length "0..100 | 101..200 | 201..300";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/MultiplePatternAndLengthRestrictionValid.yang b/utils/yangutils/src/test/resources/MultiplePatternAndLengthRestrictionValid.yang
new file mode 100644
index 0000000..161b558
--- /dev/null
+++ b/utils/yangutils/src/test/resources/MultiplePatternAndLengthRestrictionValid.yang
@@ -0,0 +1,18 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            pattern "[a-z]";
+            pattern "[A-Z]";
+            length "min..20 | 100..max";
+        }
+    }
+    typedef hello {
+        type string {
+            pattern "[0-9]";
+            pattern "[\n]";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/MultiplePatternRestrictionInRefTypeAndTypedef.yang b/utils/yangutils/src/test/resources/MultiplePatternRestrictionInRefTypeAndTypedef.yang
new file mode 100644
index 0000000..eaa28c5
--- /dev/null
+++ b/utils/yangutils/src/test/resources/MultiplePatternRestrictionInRefTypeAndTypedef.yang
@@ -0,0 +1,17 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            pattern "[a-z]";
+            pattern "[A-Z]";
+        }
+    }
+    typedef hello {
+        type string {
+            pattern "[0-9]";
+            pattern "[\n]";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/PatternRestrictionInRefType.yang b/utils/yangutils/src/test/resources/PatternRestrictionInRefType.yang
new file mode 100644
index 0000000..189177d
--- /dev/null
+++ b/utils/yangutils/src/test/resources/PatternRestrictionInRefType.yang
@@ -0,0 +1,13 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            pattern "[a-zA-Z]";
+        }
+    }
+    typedef hello {
+        type string;
+    }
+}
diff --git a/utils/yangutils/src/test/resources/PatternRestrictionInRefTypeAndTypedef.yang b/utils/yangutils/src/test/resources/PatternRestrictionInRefTypeAndTypedef.yang
new file mode 100644
index 0000000..e01b224
--- /dev/null
+++ b/utils/yangutils/src/test/resources/PatternRestrictionInRefTypeAndTypedef.yang
@@ -0,0 +1,15 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            pattern "[a-zA-Z]";
+        }
+    }
+    typedef hello {
+        type string {
+            pattern "[0-9]";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/PatternRestrictionInTypedef.yang b/utils/yangutils/src/test/resources/PatternRestrictionInTypedef.yang
new file mode 100644
index 0000000..7875504
--- /dev/null
+++ b/utils/yangutils/src/test/resources/PatternRestrictionInTypedef.yang
@@ -0,0 +1,13 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello;
+    }
+    typedef hello {
+        type string {
+            pattern "[a-zA-Z]";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/RangeRestrictionInRefType.yang b/utils/yangutils/src/test/resources/RangeRestrictionInRefType.yang
new file mode 100644
index 0000000..da396fa
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RangeRestrictionInRefType.yang
@@ -0,0 +1,13 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            range "1..4 | 10..20";
+        }
+    }
+    typedef hello {
+        type int32;
+    }
+}
diff --git a/utils/yangutils/src/test/resources/RangeRestrictionInRefTypeAndTypedefInValid.yang b/utils/yangutils/src/test/resources/RangeRestrictionInRefTypeAndTypedefInValid.yang
new file mode 100644
index 0000000..f45f1ee
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RangeRestrictionInRefTypeAndTypedefInValid.yang
@@ -0,0 +1,15 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            range "min..4 | min..max";
+        }
+    }
+    typedef hello {
+        type int32 {
+            range "1..4 | 10..20";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/RangeRestrictionInRefTypeAndTypedefValid.yang b/utils/yangutils/src/test/resources/RangeRestrictionInRefTypeAndTypedefValid.yang
new file mode 100644
index 0000000..b0af767
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RangeRestrictionInRefTypeAndTypedefValid.yang
@@ -0,0 +1,15 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            range "min..4 | 10..max";
+        }
+    }
+    typedef hello {
+        type int32 {
+            range "1..4 | 10..20";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/RangeRestrictionInString.yang b/utils/yangutils/src/test/resources/RangeRestrictionInString.yang
new file mode 100644
index 0000000..f167230
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RangeRestrictionInString.yang
@@ -0,0 +1,13 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello;
+    }
+    typedef hello {
+        type string {
+            range "1..4 | 10..20";
+        }
+    }
+}
diff --git a/utils/yangutils/src/test/resources/RangeRestrictionInStringInRefType.yang b/utils/yangutils/src/test/resources/RangeRestrictionInStringInRefType.yang
new file mode 100644
index 0000000..c08635f
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RangeRestrictionInStringInRefType.yang
@@ -0,0 +1,13 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello {
+            range "1..4 | 10..20";
+        }
+    }
+    typedef hello {
+        type string;
+    }
+}
diff --git a/utils/yangutils/src/test/resources/RangeRestrictionInTypedef.yang b/utils/yangutils/src/test/resources/RangeRestrictionInTypedef.yang
new file mode 100644
index 0000000..0f53d1f
--- /dev/null
+++ b/utils/yangutils/src/test/resources/RangeRestrictionInTypedef.yang
@@ -0,0 +1,13 @@
+module Test {
+    yang-version 1;
+    namespace http://huawei.com;
+    prefix Ant;
+    leaf invalid-interval {
+        type hello;
+    }
+    typedef hello {
+        type int32 {
+            range "1..4 | 10..20";
+        }
+    }
+}