Mahesh Poojary Huawei
Committed by Patrick Liu

[ONOS-4838] Decimal64 Range Restrictions Modification

Change-Id: I4d79c0da5ef400a188bfc5a85830e1187602e698
Showing 25 changed files with 693 additions and 38 deletions
......@@ -478,9 +478,7 @@ public class YangDerivedInfo<T>
return RESOLVED;
}
} else if (getEffectiveBuiltInType() == DECIMAL64) {
if ((refDerivedInfo.getResolvedExtendedInfo() == null) ||
(((YangDecimal64) refDerivedInfo.getResolvedExtendedInfo())
.getRangeRestrictedExtendedInfo() == null)) {
if (refDerivedInfo.getResolvedExtendedInfo() == null) {
resolveRangeRestriction(null);
/*
* Return the resolution status as resolved, if it's not;
......@@ -489,13 +487,12 @@ public class YangDerivedInfo<T>
*/
return RESOLVED;
} else {
if (!(((YangDecimal64) refDerivedInfo.getResolvedExtendedInfo())
.getRangeRestrictedExtendedInfo() instanceof YangRangeRestriction)) {
if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) {
throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " +
"type.");
}
resolveRangeRestriction((YangRangeRestriction) ((YangDecimal64) refDerivedInfo
.getResolvedExtendedInfo()).getRangeRestrictedExtendedInfo());
resolveRangeRestriction((YangRangeRestriction) refDerivedInfo
.getResolvedExtendedInfo());
/*
* Return the resolution status as resolved, if it's not
* resolve range/string restriction will throw exception in
......
......@@ -1613,7 +1613,6 @@ public class TempJavaFragmentFiles {
addBitsetImport(imports, false);
}
insertDataIntoJavaFile(getOpParamClassJavaFileHandle(), getJavaClassDefClose());
}
}
/*
......
......@@ -22,15 +22,19 @@ import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
......@@ -70,6 +74,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
......@@ -111,6 +117,9 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafListgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getisFilterContentMatch;
import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.BINARY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.BITS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
......@@ -122,6 +131,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRIN
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER;
import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_IMPORT_BASE64_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
......@@ -150,10 +164,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.MERGE;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.CREATE;
import static org.onosproject.yangutils.utils.UtilConstants.REMOVE;
import static org.onosproject.yangutils.utils.UtilConstants.DELETE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
......@@ -830,8 +847,15 @@ public final class JavaFileGenerator {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
// import
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
YangTypeDef typeDef = (YangTypeDef) curNode;
List<YangType<?>> types = typeDef.getTypeList();
YangType type = types.get(0);
if (type.getDataType().equals(YangDataTypes.BINARY)) {
imports.add(IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_IMPORT_BASE64_CLASS);
}
initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path, pluginConfig);
......@@ -899,9 +923,39 @@ public final class JavaFileGenerator {
/**
* To string method.
*/
methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK,
if (type.getDataType().equals(YangDataTypes.BINARY)) {
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase(BINARY_STRING));
JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, BINARY_STRING, null, false,
false);
String attributeName = attr.getAttributeName();
String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC
+ SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ RETURN + SPACE + BASE64 + PERIOD + GET_ENCODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS + attributeName + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
methods.add(bitsToStringMethod);
} else if (type.getDataType().equals(YangDataTypes.BITS)) {
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase(BITS_STRING));
JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, BITS_STRING,
null, false, false);
String attributeName = attr.getAttributeName();
String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC
+ SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ RETURN + SPACE + attributeName + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
+ NEW_LINE;
methods.add(bitsToStringMethod);
} else {
methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(),
path) + getToStringMethodClose());
}
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
/**
......
......@@ -59,6 +59,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
......@@ -74,10 +75,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.DECODE;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
......@@ -89,11 +91,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.FOR;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.GET;
import static org.onosproject.yangutils.utils.UtilConstants.GET_BYTES;
import static org.onosproject.yangutils.utils.UtilConstants.GET_DECODER;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
......@@ -170,6 +173,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.FILTER_CONTENT_MATCH
import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE;
import static org.onosproject.yangutils.utils.UtilConstants.NOT;
import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE;
import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
......@@ -188,11 +197,15 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
/**
* Represents generator for methods of generated files based on the file type.
*/
public final class MethodsGenerator {
private static final String BITS_STRING_ARRAY_VAR = "bitsTemp";
private static final String BIT_TEMP_VAR = "bitTemp";
private static final String FOR_TYPE = " for type ";
/**
* Creates an instance of method generator.
......@@ -1085,14 +1098,39 @@ public final class MethodsGenerator {
JavaAttributeInfo fromStringAttributeInfo) {
String targetDataType = getReturnType(attr);
if (fromStringAttributeInfo.getAttributeType().getDataType() == BINARY) {
return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
+ PERIOD + GET_BYTES + OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
if (fromStringAttributeInfo.getAttributeType().getDataType() == BITS) {
String lines = targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + NEW + SPACE + targetDataType
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
+ PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + OPEN_CURLY_BRACKET + SINGLE_QUOTE
+ COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
+ PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + CLOSE_CURLY_BRACKET + SINGLE_QUOTE
+ COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME
+ PERIOD + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
lines += TWELVE_SPACE_INDENTATION + STRING_DATA_TYPE + SQUARE_BRACKETS + SPACE + BITS_STRING_ARRAY_VAR
+ SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD + SPLIT_STRING + OPEN_PARENTHESIS
+ QUOTES + COMMA + QUOTES + COMMA + SPACE + ZERO + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
lines += TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
+ BIT_TEMP_VAR + SPACE + COLON + SPACE + BITS_STRING_ARRAY_VAR + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
lines += SIXTEEN_SPACE_INDENTATION + BIT_TEMP_VAR + SPACE + EQUAL + SPACE + BIT_TEMP_VAR + PERIOD
+ TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
lines += SIXTEEN_SPACE_INDENTATION + TMP_VAL + PERIOD + SET_METHOD_PREFIX + OPEN_PARENTHESIS
+ INTEGER_WRAPPER + PERIOD + PARSE_INT + OPEN_PARENTHESIS + BIT_TEMP_VAR + CLOSE_PARENTHESIS
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
lines += TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
return lines;
} else if (attr.getAttributeType().getDataType() == BINARY) {
return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + BASE64 + PERIOD
+ GET_DECODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + DECODE + OPEN_PARENTHESIS
+ FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
} else {
String parseFromStringMethod = getParseFromStringMethod(targetDataType,
fromStringAttributeInfo.getAttributeType());
return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
+ OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS;
+ OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
}
}
......@@ -1350,15 +1388,15 @@ public final class MethodsGenerator {
for (String str : enumList) {
value = enumMap.get(str);
method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLAN + NEW_LINE
method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLON + NEW_LINE
+ SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD
+ str + SEMI_COLAN + NEW_LINE;
}
method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLAN + NEW_LINE + SIXTEEN_SPACE_INDENTATION
method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION
+ RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
+ NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig)
return getJavaDoc(OF_METHOD, getCapitalCase(className) + FOR_TYPE + attrName, false, pluginConfig)
+ method;
}
......
......@@ -237,6 +237,31 @@ public final class UtilConstants {
public static final String PARSE_LONG = "parseLong";
/**
* Static attribute for base64.
*/
public static final String BASE64 = "Base64";
/**
* Static attribute for getEncoder.
*/
public static final String GET_ENCODER = "getEncoder";
/**
* Static attribute for encodeToString.
*/
public static final String ENCODE_TO_STRING = "encodeToString";
/**
* Static attribute for getDecoder.
*/
public static final String GET_DECODER = "getDecoder";
/**
* Static attribute for decode.
*/
public static final String DECODE = "decode";
/**
* Static attribute for omit null value.
*/
public static final String OMIT_NULL_VALUE_STRING = "omitNullValues()";
......@@ -322,6 +347,16 @@ public final class UtilConstants {
public static final String IDENTITYREF = "identityref";
/**
* Static attribute for binary string.
*/
public static final String BINARY_STRING = "binary";
/**
* Static attribute for bits string.
*/
public static final String BITS_STRING = "bits";
/**
* Static attribute for output variable of rpc.
*/
public static final String RPC_INPUT_VAR_NAME = "inputVar";
......@@ -342,11 +377,21 @@ public final class UtilConstants {
public static final String ADD = "+";
/**
* Static attribute for single quote.
*/
public static final String SINGLE_QUOTE = "\'";
/**
* Static attribute for quotes.
*/
public static final String QUOTES = "\"";
/**
* Static attribute for zero.
*/
public static final String ZERO = "0";
/**
* Static attribute for ampersand.
*/
public static final String AND = "&";
......@@ -412,6 +457,21 @@ public final class UtilConstants {
public static final String ADD_STRING = "add";
/**
* Static attribute for string replace syntax.
*/
public static final String REPLACE_STRING = "replace";
/**
* Static attribute for string trim syntax.
*/
public static final String TRIM_STRING = "trim";
/**
* Static attribute for string split syntax.
*/
public static final String SPLIT_STRING = "split";
/**
* Static attribute for from syntax.
*/
public static final String FROM_STRING_METHOD_NAME = "fromString";
......@@ -457,6 +517,11 @@ public final class UtilConstants {
public static final String IF = "if";
/**
* Static attribute for "for" syntax.
*/
public static final String FOR = "for";
/**
* Static attribute for of.
*/
public static final String OF = "of";
......@@ -1103,6 +1168,11 @@ public final class UtilConstants {
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
/**
* Static attribute for java utilities import base64 class.
*/
public static final String JAVA_UTIL_IMPORT_BASE64_CLASS = "Base64;\n";
/**
* Static attribute for AugmentedInfo class import package.
*/
public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.datamodel";
......
......@@ -21,6 +21,7 @@ import static org.hamcrest.core.Is.is;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangBit;
import org.onosproject.yangutils.datamodel.YangBits;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangModule;
......@@ -168,6 +169,117 @@ public class BitListenerTest {
}
/**
* Checks bit statement with typedef with referred leaf.
*/
@Test
public void processBitTypedefReferredLeafStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/BitTypedefReferredLeafStatement.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"));
YangTypeDef typedef = (YangTypeDef) yangNode.getChild();
assertThat(typedef.getName(), is("topBits"));
YangType type = typedef.getTypeList().iterator().next();
assertThat(type.getDataType(), is(YangDataTypes.BITS));
assertThat(type.getDataTypeName(), is("bits"));
// 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);
}
}
// Check leaf reffered typedef
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("myBits"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("topBits"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED));
YangType<YangDerivedInfo> typeDerived = (YangType<YangDerivedInfo>) leafInfo.getDataType();
YangDerivedInfo derivedInfo = (YangDerivedInfo) typeDerived.getDataTypeExtendedInfo();
YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
assertThat(prevTypedef.getName(), is("topBits"));
YangType topType = prevTypedef.getTypeList().iterator().next();
assertThat(topType.getDataType(), is(YangDataTypes.BITS));
assertThat(topType.getDataTypeName(), is("bits"));
YangType<YangBits> typeBits = (YangType<YangBits>) topType;
YangBits bits = typeBits.getDataTypeExtendedInfo();
// Check bit name map
bitNameMap = bits.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
bitPositionMap = bits.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);
}
}
}
/**
* Checks bit statement with union.
*/
@Test
......
......@@ -33,6 +33,7 @@ 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.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
......@@ -56,7 +57,7 @@ public class Decimal64ListenerTest {
@Test
public void processDecimal64TypeStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeStatement.yang");
YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeStatement.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
......@@ -84,7 +85,7 @@ public class Decimal64ListenerTest {
@Test
public void processDecimal64TypeWithRangeStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeWithRangeStatement.yang");
YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeWithRangeStatement.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
......@@ -122,7 +123,7 @@ public class Decimal64ListenerTest {
@Test
public void processDecimal64ValueSuccessfulValidation() throws IOException, ParserException, DataModelException {
YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeValidation.yang");
YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeValidation.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
......@@ -157,7 +158,7 @@ public class Decimal64ListenerTest {
thrown.expect(DataModelException.class);
thrown.expectMessage("YANG file error : decimal64 validation failed.");
YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeValidation.yang");
YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeValidation.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
......@@ -191,7 +192,7 @@ public class Decimal64ListenerTest {
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");
manager.getDataModel("src/test/resources/decimal64/Decimal64TypeInvalidMaxValueFraction.yang");
}
/**
......@@ -202,7 +203,7 @@ public class Decimal64ListenerTest {
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");
manager.getDataModel("src/test/resources/decimal64/Decimal64TypeInvalidMinValueFraction1.yang");
}
/**
......@@ -213,7 +214,7 @@ public class Decimal64ListenerTest {
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");
manager.getDataModel("src/test/resources/decimal64/Decimal64TypeInvalidMinValueFraction2.yang");
}
/**
......@@ -222,7 +223,7 @@ public class Decimal64ListenerTest {
@Test
public void processDecimal64TypeWithMultiValueRangeStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.yang");
YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeWithMultiValueRangeStmnt.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
......@@ -272,7 +273,7 @@ public class Decimal64ListenerTest {
thrown.expect(ParserException.class);
thrown.expectMessage("YANG file error : decimal64 validation failed.");
manager.getDataModel("src/test/resources/Decimal64TypeInvalidRangeStmnt.yang");
manager.getDataModel("src/test/resources/decimal64/Decimal64TypeInvalidRangeStmnt.yang");
}
/**
......@@ -283,7 +284,7 @@ public class Decimal64ListenerTest {
thrown.expect(ParserException.class);
thrown.expectMessage("YANG file error : a type decimal64 must have fraction-digits statement.");
manager.getDataModel("src/test/resources/Decimal64TypeWithoutFraction.yang");
manager.getDataModel("src/test/resources/decimal64/Decimal64TypeWithoutFraction.yang");
}
/**
......@@ -292,7 +293,7 @@ public class Decimal64ListenerTest {
@Test
public void processDecimal64TypedefStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/Decimal64TypedefStatement.yang");
YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypedefStatement.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
......@@ -329,7 +330,7 @@ public class Decimal64ListenerTest {
@Test
public void processDecimal64MultiTypedefStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/Decimal64MultiTypedefStatement.yang");
YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefStatement.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
......@@ -345,15 +346,264 @@ public class Decimal64ListenerTest {
YangLeaf leafInfo = leafIterator.next();
// check leaf type
assertThat(leafInfo.getName(), is("setFourDecimal"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("validDecimal"));
assertThat(leafInfo.getName(), is("lowerDecimal"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal"));
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("midDecimal"));
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));
}
/**
* Checks decimal64 with multiple typedef with single range statement.
* Range value in typedef statement.
*/
@Test
public void processDecimal64MultiTypedefRangeStatement() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefRangeStatement.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("lowerDecimal"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal"));
YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType();
assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED));
YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo();
// Check range restriction
YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo();
ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
.listIterator();
YangRangeInterval rangeInterval = rangeListIterator.next();
assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0));
assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0));
// check previous typedef
YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
assertThat(prevTypedef.getName(), is("midDecimal"));
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));
// Check range restriction
rangeRestriction = (YangRangeRestriction) decimal64.getRangeRestrictedExtendedInfo();
rangeListIterator = rangeRestriction.getAscendingRangeIntervals().listIterator();
rangeInterval = rangeListIterator.next();
assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0));
assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0));
}
/**
* Checks decimal64 with multiple typedef with single range statement.
* Range value in leaf statement.
*/
@Test
public void processDecimal64MultiTypedefRangeInLeafStatement() throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefRangeInLeafStatement.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("lowerDecimal"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal"));
YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType();
assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED));
YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo();
// Check range restriction
YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo();
ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
.listIterator();
YangRangeInterval rangeInterval = rangeListIterator.next();
assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0));
assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0));
// check previous typedef
YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
assertThat(prevTypedef.getName(), is("midDecimal"));
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));
}
/**
* Checks decimal64 with multiple typedef with multiple range statement.
* Having more restricted range at leaf.
*/
@Test
public void processDecimal64MultiTypedefMultipleRangeStatement() throws IOException, ParserException {
YangNode node = manager
.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefMultiRangeStatement.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("lowerDecimal"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal"));
YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType();
assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED));
YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo();
// Check range restriction
YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo();
ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
.listIterator();
YangRangeInterval rangeInterval = rangeListIterator.next();
assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(4.0));
assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(11.0));
// check previous typedef
YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
assertThat(prevTypedef.getName(), is("midDecimal"));
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));
// Check range restriction
rangeRestriction = (YangRangeRestriction) decimal64.getRangeRestrictedExtendedInfo();
rangeListIterator = rangeRestriction.getAscendingRangeIntervals().listIterator();
rangeInterval = rangeListIterator.next();
assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0));
assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0));
}
/**
* Checks decimal64 with multiple typedef with multiple range statement.
* But having more restricted range at top of typedef.
*/
@Test
public void processDecimal64MultiTypedefMultiInvalidRangeStatement() throws IOException, LinkerException {
thrown.expect(LinkerException.class);
thrown.expectMessage(" Range interval doesn't fall within the referred restriction ranges");
manager.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefMultiInvalidRangeStatement.yang");
}
/**
* Checks decimal64 with multiple typedef with max range statement.
*/
@Test
public void processDecimal64MultiTypedefWithMaxRange() throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefWithMaxRange.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("lowerDecimal"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal"));
YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType();
assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED));
YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo();
// Check range restriction
YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo();
ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals()
.listIterator();
YangRangeInterval rangeInterval = rangeListIterator.next();
assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(4.0));
assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0));
// check previous typedef
YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef();
assertThat(prevTypedef.getName(), is("validDecimal"));
assertThat(prevTypedef.getName(), is("midDecimal"));
YangType type = prevTypedef.getTypeList().iterator().next();
assertThat(type.getDataType(), is(YangDataTypes.DERIVED));
derivedInfo = (YangDerivedInfo) type.getDataTypeExtendedInfo();
......@@ -367,5 +617,12 @@ public class Decimal64ListenerTest {
YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) type;
YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo();
assertThat(decimal64.getFractionDigit(), is(4));
// Check range restriction
rangeRestriction = (YangRangeRestriction) decimal64.getRangeRestrictedExtendedInfo();
rangeListIterator = rangeRestriction.getAscendingRangeIntervals().listIterator();
rangeInterval = rangeListIterator.next();
assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0));
assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0));
}
}
......
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef topBits {
type bits {
bit disable-nagle {
position 0;
}
bit auto-sense-speed {
position 1;
}
bit Mb-only {
position 2;
}
}
}
leaf myBits {
type topBits;
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef topDecimal {
type decimal64 {
fraction-digits 4;
range 4..11;
}
}
typedef midDecimal {
type topDecimal;
}
leaf lowerDecimal {
type midDecimal {
range 1..12;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef topDecimal {
type decimal64 {
fraction-digits 4;
range 1..12;
}
}
typedef midDecimal {
type topDecimal;
}
leaf lowerDecimal {
type midDecimal {
range 4..11;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef topDecimal {
type decimal64 {
fraction-digits 4;
}
}
typedef midDecimal {
type topDecimal;
}
leaf lowerDecimal {
type midDecimal {
range 1..12;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef topDecimal {
type decimal64 {
fraction-digits 4;
range 1..12;
}
}
typedef midDecimal {
type topDecimal;
}
leaf lowerDecimal {
type midDecimal;
}
}
......@@ -9,11 +9,11 @@ module Test {
}
}
typedef validDecimal {
typedef midDecimal {
type topDecimal;
}
leaf setFourDecimal {
type validDecimal;
leaf lowerDecimal {
type midDecimal;
}
}
......
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
typedef topDecimal {
type decimal64 {
fraction-digits 4;
range 1..12;
}
}
typedef midDecimal {
type topDecimal;
}
leaf lowerDecimal {
type midDecimal {
range 4..max;
}
}
}
......@@ -1723,7 +1723,6 @@
uses tet:te-link-state-derived;
}
augment "/te-link-event/te-link-attributes/underlay" {
description "Add state attributes to te-link underlay.";
uses te-link-state-underlay-attributes;
......