[ONOS-4348] Yang Bits, Binary and Decimal64
Change-Id: I8e4e54a19a8f9634cbc56a07579a1730174f53f6
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
index 4b2b185..ef25c97 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/BitListenerTest.java
@@ -35,7 +35,7 @@
import java.io.IOException;
import java.util.List;
import java.util.ListIterator;
-import java.util.Set;
+import java.util.Map;
/**
* Test cases for bit listener.
@@ -71,14 +71,38 @@
assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
is("mybits"));
- Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
- } else if (tmp.getBitName().equals("Ten-Mb-only")) {
- assertThat(tmp.getPosition(), is(2));
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Ten-Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
+ .getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
@@ -107,12 +131,38 @@
YangType type = typedef.getTypeList().iterator().next();
assertThat(type.getDataType(), is(YangDataTypes.BITS));
assertThat(type.getDataTypeName(), is("bits"));
- Set<YangBit> bitSet = ((YangBits) type.getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
+
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) type.getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) type.getDataTypeExtendedInfo()).getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
@@ -151,12 +201,38 @@
assertThat(yangType.getDataType(), is(YangDataTypes.BITS));
assertThat(yangType.getDataTypeName(), is("bits"));
- Set<YangBit> bitSet = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
+
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) yangType.getDataTypeExtendedInfo()).getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64ListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64ListenerTest.java
new file mode 100644
index 0000000..ec5b3fc
--- /dev/null
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64ListenerTest.java
@@ -0,0 +1,371 @@
+/*
+ * 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.parser.impl.listeners;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onosproject.yangutils.datamodel.YangDecimal64;
+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.YangNodeType;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.YangRangeInterval;
+import org.onosproject.yangutils.datamodel.YangType;
+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.datamodel.utils.builtindatatype.YangDataTypes;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ListIterator;
+
+/**
+ * Test cases for decimal64 listener.
+ */
+public class Decimal64ListenerTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private final YangUtilsParserManager manager = new YangUtilsParserManager();
+
+ /**
+ * Checks decimal64 statement with fraction-digits.
+ */
+ @Test
+ public void processDecimal64TypeStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeStatement.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(YangNodeType.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("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(((YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo()).getFractionDigit(),
+ is(2));
+ }
+
+ /**
+ * Checks decimal64 statement with range statement.
+ */
+ @Test
+ public void processDecimal64TypeWithRangeStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeWithRangeStatement.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(YangNodeType.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("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(((YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo()).getFractionDigit(),
+ is(8));
+
+ YangRangeRestriction rangeRestriction = ((YangDecimal64<YangRangeRestriction>) leafInfo.getDataType()
+ .getDataTypeExtendedInfo())
+ .getRangeRestrictedExtendedInfo();
+
+ ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
+ .listIterator();
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(-92233720368.54775808));
+ assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(92233720368.54775807));
+ }
+
+ /**
+ * Successful validation of decimal64 statement.
+ */
+ @Test
+ public void processDecimal64ValueSuccessfulValidation() throws IOException, ParserException, DataModelException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeValidation.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(YangNodeType.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();
+ YangDecimal64 decimal64 = (YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ assertThat(leafInfo.getName(), is("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(decimal64.getFractionDigit(), is(18));
+
+ decimal64.setValue(new BigDecimal(-9.223372036854775808));
+ decimal64.validateValue();
+ decimal64.setValue(new BigDecimal(9.223372036854775807));
+ decimal64.validateValue();
+ }
+
+ /**
+ * Failure validation of decimal64 statement.
+ */
+ @Test
+ public void processDecimal64ValueFailureValidation() throws IOException, ParserException, DataModelException {
+ thrown.expect(DataModelException.class);
+ thrown.expectMessage("YANG file error : decimal64 validation failed.");
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeValidation.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(YangNodeType.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();
+ YangDecimal64 decimal64 = (YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo();
+
+ assertThat(leafInfo.getName(), is("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(decimal64.getFractionDigit(), is(18));
+
+ decimal64.setValue(new BigDecimal(-92233720368547758.08));
+ // validation should fail
+ decimal64.validateValue();
+ }
+
+ /**
+ * Validation of invalid maximum value limit of fraction-digits.
+ */
+ @Test
+ public void processDecimal64InvalidMaxFraction() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeInvalidMaxValueFraction.yang");
+ }
+
+ /**
+ * Validation of invalid (0) minimum value limit of fraction-digits.
+ */
+ @Test
+ public void processDecimal64InvalidMinFraction1() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeInvalidMinValueFraction1.yang");
+ }
+
+ /**
+ * Validation of invalid (-1) minimum value limit of fraction-digits.
+ */
+ @Test
+ public void processDecimal64InvalidMinFraction2() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeInvalidMinValueFraction2.yang");
+ }
+
+ /**
+ * Validation of decimal64 range statement.
+ */
+ @Test
+ public void processDecimal64TypeWithMultiValueRangeStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.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(YangNodeType.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("validDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("decimal64"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(((YangDecimal64) leafInfo.getDataType().getDataTypeExtendedInfo()).getFractionDigit(),
+ is(18));
+
+ YangRangeRestriction rangeRestriction = ((YangDecimal64<YangRangeRestriction>) leafInfo.getDataType()
+ .getDataTypeExtendedInfo())
+ .getRangeRestrictedExtendedInfo();
+
+ ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
+ .listIterator();
+ // range "1 .. 3.14 | 10 | 20..max";
+ // check first range 1 .. 3.14
+ YangRangeInterval rangeInterval = rangeListIterator.next();
+ assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(-9.22));
+ assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(7.22));
+ // check second range 10
+ rangeInterval = rangeListIterator.next();
+ assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(8.0));
+ assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(8.0));
+ // check third range 20..max
+ rangeInterval = rangeListIterator.next();
+ assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(9.0));
+ assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(9.223372036854776));
+ }
+
+ /**
+ * Validation of decimal64 with invalid range.
+ */
+ @Test
+ public void processDecimal64InvalidRange() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : decimal64 validation failed.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeInvalidRangeStmnt.yang");
+ }
+
+ /**
+ * Validation of decimal64 without fraction-digits. Fraction-digits must be present for decimal64.
+ */
+ @Test
+ public void processDecimal64WithoutFraction() throws IOException, ParserException, DataModelException {
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : a type decimal64 must have fraction-digits statement.");
+
+ manager.getDataModel("src/test/resources/Decimal64TypeWithoutFraction.yang");
+ }
+
+ /**
+ * Checks decimal64 with typedef statement.
+ */
+ @Test
+ public void processDecimal64TypedefStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64TypedefStatement.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(YangNodeType.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("setFourDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("validDecimal"));
+ YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType();
+ YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo();
+ YangTypeDef typedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
+ assertThat(typedef.getName(), is("validDecimal"));
+
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
+ YangType type = typedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(type.getDataTypeName(), is("decimal64"));
+ YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) typedef.getTypeList().iterator().next();
+ YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo();
+ assertThat(decimal64.getFractionDigit(), is(4));
+ }
+
+ /**
+ * Checks decimal64 with multiple typedef statement.
+ */
+ @Test
+ public void processDecimal64MultiTypedefStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/Decimal64MultiTypedefStatement.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(YangNodeType.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();
+
+ // check leaf type
+ assertThat(leafInfo.getName(), is("setFourDecimal"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("validDecimal"));
+ YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType();
+ assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED));
+ YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo();
+
+ // check previous typedef
+ YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
+ assertThat(prevTypedef.getName(), is("validDecimal"));
+ YangType type = prevTypedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.DERIVED));
+ derivedInfo = (YangDerivedInfo) type.getDataTypeExtendedInfo();
+
+ // check top typedef
+ YangTypeDef topTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
+ assertThat(topTypedef.getName(), is("topDecimal"));
+ type = topTypedef.getTypeList().iterator().next();
+ assertThat(type.getDataType(), is(YangDataTypes.DECIMAL64));
+ assertThat(type.getDataTypeName(), is("decimal64"));
+ YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) type;
+ YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo();
+ assertThat(decimal64.getFractionDigit(), is(4));
+ }
+}
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
index 1f65023..a67aa53 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListenerTest.java
@@ -138,6 +138,37 @@
}
/**
+ * Checks valid length statement as sub-statement of binary statement.
+ */
+ @Test
+ public void processValidBinaryLengthStatement() throws IOException, ParserException {
+
+ YangNode node = manager.getDataModel("src/test/resources/ValidBinaryLengthStatement.yang");
+
+ assertThat((node instanceof YangModule), is(true));
+ assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
+ YangModule yangNode = (YangModule) node;
+ assertThat(yangNode.getName(), is("Test"));
+
+ ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("message"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("binary"));
+ assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.BINARY));
+ YangRangeRestriction lengthRestriction = (YangRangeRestriction) leafInfo
+ .getDataType().getDataTypeExtendedInfo();
+
+ ListIterator<YangRangeInterval> lengthListIterator = lengthRestriction.getAscendingRangeIntervals()
+ .listIterator();
+
+ YangRangeInterval rangeInterval = lengthListIterator.next();
+
+ assertThat(((YangUint64) rangeInterval.getStartValue()).getValue(), is(BigInteger.valueOf(4)));
+ assertThat(((YangUint64) rangeInterval.getEndValue()).getValue(), is(BigInteger.valueOf(4)));
+ }
+
+ /**
* Checks length statement with invalid type.
*/
@Test
diff --git a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PositionListenerTest.java b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PositionListenerTest.java
index 699f530..7b59894 100644
--- a/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PositionListenerTest.java
+++ b/plugin/src/test/java/org/onosproject/yangutils/parser/impl/listeners/PositionListenerTest.java
@@ -31,7 +31,7 @@
import java.io.IOException;
import java.util.ListIterator;
-import java.util.Set;
+import java.util.Map;
/**
* Test cases for position listener.
@@ -67,14 +67,38 @@
assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
is("mybits"));
- Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
- } else if (tmp.getBitName().equals("Ten-Mb-only")) {
- assertThat(tmp.getPosition(), is(2));
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Ten-Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
+ .getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
@@ -106,14 +130,38 @@
assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
is("mybits"));
- Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
- } else if (tmp.getBitName().equals("Ten-Mb-only")) {
- assertThat(tmp.getPosition(), is(2));
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Ten-Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
+ .getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
@@ -145,14 +193,38 @@
assertThat(((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitsName(),
is("mybits"));
- Set<YangBit> bitSet = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitSet();
- for (YangBit tmp : bitSet) {
- if (tmp.getBitName().equals("disable-nagle")) {
- assertThat(tmp.getPosition(), is(0));
- } else if (tmp.getBitName().equals("auto-sense-speed")) {
- assertThat(tmp.getPosition(), is(1));
- } else if (tmp.getBitName().equals("Ten-Mb-only")) {
- assertThat(tmp.getPosition(), is(2));
+ // Check bit name map
+ Map<String, YangBit> bitNameMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo()).getBitNameMap();
+ assertThat(bitNameMap.size(), is(3));
+ for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) {
+ String bitName = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (bitName.equals("disable-nagle")) {
+ assertThat(yangBit.getPosition(), is(0));
+ } else if (bitName.equals("auto-sense-speed")) {
+ assertThat(yangBit.getPosition(), is(1));
+ } else if (bitName.equals("Ten-Mb-only")) {
+ assertThat(yangBit.getPosition(), is(2));
+ } else {
+ throw new IOException("Invalid bit name: " + bitName);
+ }
+ }
+
+ // Check bit position map
+ Map<Integer, YangBit> bitPositionMap = ((YangBits) leafInfo.getDataType().getDataTypeExtendedInfo())
+ .getBitPositionMap();
+ assertThat(bitPositionMap.size(), is(3));
+ for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) {
+ int position = element.getKey();
+ YangBit yangBit = element.getValue();
+ if (position == 0) {
+ assertThat(yangBit.getBitName(), is("disable-nagle"));
+ } else if (position == 1) {
+ assertThat(yangBit.getBitName(), is("auto-sense-speed"));
+ } else if (position == 2) {
+ assertThat(yangBit.getBitName(), is("Ten-Mb-only"));
+ } else {
+ throw new IOException("Invalid bit position: " + position);
}
}
}
diff --git a/plugin/src/test/resources/ContainerSubStatementWhen.yang b/plugin/src/test/resources/ContainerSubStatementWhen.yang
index 644b2ff..7a2674f 100644
--- a/plugin/src/test/resources/ContainerSubStatementWhen.yang
+++ b/plugin/src/test/resources/ContainerSubStatementWhen.yang
@@ -26,7 +26,9 @@
"Interface has time-division multiplex capabilities.";
leaf minimum-lsp-bandwidth {
- type decimal64;
+ type decimal64 {
+ fraction-digits 4;
+ }
}
}
}
diff --git a/plugin/src/test/resources/Decimal64MultiTypedefStatement.yang b/plugin/src/test/resources/Decimal64MultiTypedefStatement.yang
new file mode 100644
index 0000000..fdce08e
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64MultiTypedefStatement.yang
@@ -0,0 +1,19 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ typedef topDecimal {
+ type decimal64 {
+ fraction-digits 4;
+ }
+ }
+
+ typedef validDecimal {
+ type topDecimal;
+ }
+
+ leaf setFourDecimal {
+ type validDecimal;
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeInvalidMaxValueFraction.yang b/plugin/src/test/resources/Decimal64TypeInvalidMaxValueFraction.yang
new file mode 100644
index 0000000..68bd8df
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeInvalidMaxValueFraction.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ leaf invalidDecimal1 {
+ type decimal64 {
+ fraction-digits 19;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction1.yang b/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction1.yang
new file mode 100644
index 0000000..3d7445a
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction1.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ leaf invalidDecimal2 {
+ type decimal64 {
+ fraction-digits 0;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction2.yang b/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction2.yang
new file mode 100644
index 0000000..4e17bbe
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeInvalidMinValueFraction2.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ leaf invalidDecimal3 {
+ type decimal64 {
+ fraction-digits -1;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeInvalidRangeStmnt.yang b/plugin/src/test/resources/Decimal64TypeInvalidRangeStmnt.yang
new file mode 100644
index 0000000..2ac3d94
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeInvalidRangeStmnt.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 18;
+ range "1 .. 20.14";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeStatement.yang b/plugin/src/test/resources/Decimal64TypeStatement.yang
new file mode 100644
index 0000000..9824c12
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeStatement.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 2;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeValidation.yang b/plugin/src/test/resources/Decimal64TypeValidation.yang
new file mode 100644
index 0000000..06bf5b7
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeValidation.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 18;
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.yang b/plugin/src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.yang
new file mode 100644
index 0000000..f657134
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 18;
+ range "-9.22..7.22 | 8 | 9..max";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeWithRangeStatement.yang b/plugin/src/test/resources/Decimal64TypeWithRangeStatement.yang
new file mode 100644
index 0000000..f184927
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeWithRangeStatement.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64 {
+ fraction-digits 8;
+ range "-92233720368.54775808 .. 92233720368.54775807";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypeWithoutFraction.yang b/plugin/src/test/resources/Decimal64TypeWithoutFraction.yang
new file mode 100644
index 0000000..e7b8beb
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypeWithoutFraction.yang
@@ -0,0 +1,8 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf validDecimal {
+ type decimal64;
+ }
+}
diff --git a/plugin/src/test/resources/Decimal64TypedefStatement.yang b/plugin/src/test/resources/Decimal64TypedefStatement.yang
new file mode 100644
index 0000000..66addd2
--- /dev/null
+++ b/plugin/src/test/resources/Decimal64TypedefStatement.yang
@@ -0,0 +1,15 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+
+ typedef validDecimal {
+ type decimal64 {
+ fraction-digits 4;
+ }
+ }
+
+ leaf setFourDecimal {
+ type validDecimal;
+ }
+}
diff --git a/plugin/src/test/resources/ValidBinaryLengthStatement.yang b/plugin/src/test/resources/ValidBinaryLengthStatement.yang
new file mode 100644
index 0000000..7182eb3
--- /dev/null
+++ b/plugin/src/test/resources/ValidBinaryLengthStatement.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf message {
+ type binary {
+ length "4";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/ValidLengthStatementInsideBinary.yang b/plugin/src/test/resources/ValidLengthStatementInsideBinary.yang
new file mode 100644
index 0000000..7182eb3
--- /dev/null
+++ b/plugin/src/test/resources/ValidLengthStatementInsideBinary.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf message {
+ type binary {
+ length "4";
+ }
+ }
+}
diff --git a/plugin/src/test/resources/interfileietf/ietf-te-topology.yang b/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
index b5fd1d9..5b65dff 100644
--- a/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
+++ b/plugin/src/test/resources/interfileietf/ietf-te-topology.yang
@@ -430,8 +430,8 @@
}
leaf unidirectional-packet-loss {
type decimal64 {
- /*fraction-digits 6;
- range "0 .. 50.331642";*/
+ fraction-digits 6;
+ range "0 .. 50.331642";
}
description
"Packet loss as a percentage of the total traffic sent
@@ -440,7 +440,7 @@
}
leaf unidirectional-residual-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Residual bandwidth that subtracts tunnel
@@ -450,7 +450,7 @@
}
leaf unidirectional-available-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Available bandwidth that is defined to be residual
@@ -461,7 +461,7 @@
}
leaf unidirectional-utilized-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Bandwidth utilization that represents the actual
@@ -753,7 +753,7 @@
}
leaf max-link-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Maximum bandwidth that can be seen on this link in this
@@ -765,7 +765,7 @@
}
leaf max-resv-link-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Maximum amount of bandwidth that can be reserved in this
@@ -793,7 +793,7 @@
}
leaf bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Unreserved bandwidth for this level.";
@@ -884,7 +884,7 @@
}
leaf bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Max LSP Bandwidth for this level";
@@ -899,7 +899,7 @@
leaf minimum-lsp-bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Minimum LSP Bandwidth. Units in bytes per second.";
@@ -951,7 +951,7 @@
}
leaf bandwidth {
type decimal64 {
- /*fraction-digits 2;*/
+ fraction-digits 2;
}
description
"Max LSP Bandwidth for this level.";
diff --git a/plugin/src/test/resources/interfileietf/ietf-te-types.yang b/plugin/src/test/resources/interfileietf/ietf-te-types.yang
index ffa1984..4b9d3be 100644
--- a/plugin/src/test/resources/interfileietf/ietf-te-types.yang
+++ b/plugin/src/test/resources/interfileietf/ietf-te-types.yang
@@ -580,7 +580,7 @@
typedef admin-group {
type binary {
-// length 32;
+ length 32;
}
description
"Administrative group/Resource class/Color.";