Committed by
Patrick Liu
[ONOS-4838] Decimal64 Range Restrictions Modification
Change-Id: I4d79c0da5ef400a188bfc5a85830e1187602e698
Showing
25 changed files
with
692 additions
and
37 deletions
... | @@ -478,9 +478,7 @@ public class YangDerivedInfo<T> | ... | @@ -478,9 +478,7 @@ public class YangDerivedInfo<T> |
478 | return RESOLVED; | 478 | return RESOLVED; |
479 | } | 479 | } |
480 | } else if (getEffectiveBuiltInType() == DECIMAL64) { | 480 | } else if (getEffectiveBuiltInType() == DECIMAL64) { |
481 | - if ((refDerivedInfo.getResolvedExtendedInfo() == null) || | 481 | + if (refDerivedInfo.getResolvedExtendedInfo() == null) { |
482 | - (((YangDecimal64) refDerivedInfo.getResolvedExtendedInfo()) | ||
483 | - .getRangeRestrictedExtendedInfo() == null)) { | ||
484 | resolveRangeRestriction(null); | 482 | resolveRangeRestriction(null); |
485 | /* | 483 | /* |
486 | * Return the resolution status as resolved, if it's not; | 484 | * Return the resolution status as resolved, if it's not; |
... | @@ -489,13 +487,12 @@ public class YangDerivedInfo<T> | ... | @@ -489,13 +487,12 @@ public class YangDerivedInfo<T> |
489 | */ | 487 | */ |
490 | return RESOLVED; | 488 | return RESOLVED; |
491 | } else { | 489 | } else { |
492 | - if (!(((YangDecimal64) refDerivedInfo.getResolvedExtendedInfo()) | 490 | + if (!(refDerivedInfo.getResolvedExtendedInfo() instanceof YangRangeRestriction)) { |
493 | - .getRangeRestrictedExtendedInfo() instanceof YangRangeRestriction)) { | ||
494 | throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " + | 491 | throw new DataModelException("Linker error: Referred typedef restriction info is of invalid " + |
495 | "type."); | 492 | "type."); |
496 | } | 493 | } |
497 | - resolveRangeRestriction((YangRangeRestriction) ((YangDecimal64) refDerivedInfo | 494 | + resolveRangeRestriction((YangRangeRestriction) refDerivedInfo |
498 | - .getResolvedExtendedInfo()).getRangeRestrictedExtendedInfo()); | 495 | + .getResolvedExtendedInfo()); |
499 | /* | 496 | /* |
500 | * Return the resolution status as resolved, if it's not | 497 | * Return the resolution status as resolved, if it's not |
501 | * resolve range/string restriction will throw exception in | 498 | * resolve range/string restriction will throw exception in | ... | ... |
... | @@ -1613,7 +1613,6 @@ public class TempJavaFragmentFiles { | ... | @@ -1613,7 +1613,6 @@ public class TempJavaFragmentFiles { |
1613 | addBitsetImport(imports, false); | 1613 | addBitsetImport(imports, false); |
1614 | } | 1614 | } |
1615 | insertDataIntoJavaFile(getOpParamClassJavaFileHandle(), getJavaClassDefClose()); | 1615 | insertDataIntoJavaFile(getOpParamClassJavaFileHandle(), getJavaClassDefClose()); |
1616 | - | ||
1617 | } | 1616 | } |
1618 | } | 1617 | } |
1619 | /* | 1618 | /* | ... | ... |
... | @@ -22,15 +22,19 @@ import java.util.ArrayList; | ... | @@ -22,15 +22,19 @@ import java.util.ArrayList; |
22 | import java.util.List; | 22 | import java.util.List; |
23 | 23 | ||
24 | import org.onosproject.yangutils.datamodel.YangAugment; | 24 | import org.onosproject.yangutils.datamodel.YangAugment; |
25 | +import org.onosproject.yangutils.datamodel.YangAugmentableNode; | ||
25 | import org.onosproject.yangutils.datamodel.YangLeaf; | 26 | import org.onosproject.yangutils.datamodel.YangLeaf; |
26 | import org.onosproject.yangutils.datamodel.YangLeafList; | 27 | import org.onosproject.yangutils.datamodel.YangLeafList; |
27 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; | 28 | import org.onosproject.yangutils.datamodel.YangLeavesHolder; |
28 | -import org.onosproject.yangutils.datamodel.YangAugmentableNode; | ||
29 | import org.onosproject.yangutils.datamodel.YangNode; | 29 | import org.onosproject.yangutils.datamodel.YangNode; |
30 | +import org.onosproject.yangutils.datamodel.YangTypeDef; | ||
31 | +import org.onosproject.yangutils.datamodel.YangType; | ||
32 | +import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | ||
30 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; | 33 | import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo; |
31 | import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo; | 34 | import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo; |
32 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; | 35 | import org.onosproject.yangutils.translator.tojava.JavaFileInfo; |
33 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; | 36 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
37 | +import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo; | ||
34 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; | 38 | import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer; |
35 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; | 39 | import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles; |
36 | import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; | 40 | import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles; |
... | @@ -70,6 +74,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. | ... | @@ -70,6 +74,8 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType. |
70 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; | 74 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK; |
71 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; | 75 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK; |
72 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; | 76 | import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK; |
77 | +import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData; | ||
78 | +import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode; | ||
73 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget; | 79 | import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget; |
74 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute; | 80 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute; |
75 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute; | 81 | import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute; |
... | @@ -111,6 +117,9 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator | ... | @@ -111,6 +117,9 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator |
111 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafListgetter; | 117 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafListgetter; |
112 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafgetter; | 118 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafgetter; |
113 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getisFilterContentMatch; | 119 | import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getisFilterContentMatch; |
120 | +import static org.onosproject.yangutils.utils.UtilConstants.BASE64; | ||
121 | +import static org.onosproject.yangutils.utils.UtilConstants.BINARY_STRING; | ||
122 | +import static org.onosproject.yangutils.utils.UtilConstants.BITS_STRING; | ||
114 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; | 123 | import static org.onosproject.yangutils.utils.UtilConstants.BUILDER; |
115 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 124 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
116 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | 125 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
... | @@ -122,6 +131,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRIN | ... | @@ -122,6 +131,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRIN |
122 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; | 131 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING; |
123 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX; | 132 | import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX; |
124 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 133 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
134 | +import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER; | ||
135 | +import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING; | ||
136 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG; | ||
137 | +import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_IMPORT_BASE64_CLASS; | ||
138 | +import static org.onosproject.yangutils.utils.UtilConstants.IMPORT; | ||
125 | import static org.onosproject.yangutils.utils.UtilConstants.INT; | 139 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
126 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT; | 140 | import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT; |
127 | import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; | 141 | import static org.onosproject.yangutils.utils.UtilConstants.MANAGER; |
... | @@ -150,10 +164,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.ENUM; | ... | @@ -150,10 +164,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.ENUM; |
150 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; | 164 | import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET; |
151 | import static org.onosproject.yangutils.utils.UtilConstants.MERGE; | 165 | import static org.onosproject.yangutils.utils.UtilConstants.MERGE; |
152 | import static org.onosproject.yangutils.utils.UtilConstants.REPLACE; | 166 | import static org.onosproject.yangutils.utils.UtilConstants.REPLACE; |
167 | +import static org.onosproject.yangutils.utils.UtilConstants.RETURN; | ||
153 | import static org.onosproject.yangutils.utils.UtilConstants.CREATE; | 168 | import static org.onosproject.yangutils.utils.UtilConstants.CREATE; |
154 | import static org.onosproject.yangutils.utils.UtilConstants.REMOVE; | 169 | import static org.onosproject.yangutils.utils.UtilConstants.REMOVE; |
155 | import static org.onosproject.yangutils.utils.UtilConstants.DELETE; | 170 | import static org.onosproject.yangutils.utils.UtilConstants.DELETE; |
156 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; | 171 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
172 | +import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; | ||
173 | +import static org.onosproject.yangutils.utils.UtilConstants.TO; | ||
157 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; | 174 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD; |
158 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; | 175 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR; |
159 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; | 176 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc; |
... | @@ -830,8 +847,15 @@ public final class JavaFileGenerator { | ... | @@ -830,8 +847,15 @@ public final class JavaFileGenerator { |
830 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); | 847 | JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo(); |
831 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); | 848 | YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig(); |
832 | 849 | ||
850 | + // import | ||
833 | String className = getCapitalCase(javaFileInfo.getJavaName()); | 851 | String className = getCapitalCase(javaFileInfo.getJavaName()); |
834 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); | 852 | String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath(); |
853 | + YangTypeDef typeDef = (YangTypeDef) curNode; | ||
854 | + List<YangType<?>> types = typeDef.getTypeList(); | ||
855 | + YangType type = types.get(0); | ||
856 | + if (type.getDataType().equals(YangDataTypes.BINARY)) { | ||
857 | + imports.add(IMPORT + JAVA_UTIL_OBJECTS_IMPORT_PKG + PERIOD + JAVA_UTIL_IMPORT_BASE64_CLASS); | ||
858 | + } | ||
835 | 859 | ||
836 | initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path, pluginConfig); | 860 | initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS, imports, path, pluginConfig); |
837 | 861 | ||
... | @@ -899,9 +923,39 @@ public final class JavaFileGenerator { | ... | @@ -899,9 +923,39 @@ public final class JavaFileGenerator { |
899 | /** | 923 | /** |
900 | * To string method. | 924 | * To string method. |
901 | */ | 925 | */ |
926 | + if (type.getDataType().equals(YangDataTypes.BINARY)) { | ||
927 | + JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, | ||
928 | + getCapitalCase(BINARY_STRING)); | ||
929 | + | ||
930 | + JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, BINARY_STRING, null, false, | ||
931 | + false); | ||
932 | + String attributeName = attr.getAttributeName(); | ||
933 | + String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC | ||
934 | + + SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS | ||
935 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
936 | + + RETURN + SPACE + BASE64 + PERIOD + GET_ENCODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS | ||
937 | + + PERIOD + ENCODE_TO_STRING + OPEN_PARENTHESIS + attributeName + CLOSE_PARENTHESIS | ||
938 | + + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE; | ||
939 | + methods.add(bitsToStringMethod); | ||
940 | + } else if (type.getDataType().equals(YangDataTypes.BITS)) { | ||
941 | + JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode, | ||
942 | + getCapitalCase(BITS_STRING)); | ||
943 | + | ||
944 | + JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, BITS_STRING, | ||
945 | + null, false, false); | ||
946 | + String attributeName = attr.getAttributeName(); | ||
947 | + String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC | ||
948 | + + SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS | ||
949 | + + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION | ||
950 | + + RETURN + SPACE + attributeName + PERIOD + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS | ||
951 | + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET | ||
952 | + + NEW_LINE; | ||
953 | + methods.add(bitsToStringMethod); | ||
954 | + } else { | ||
902 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, | 955 | methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, |
903 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), | 956 | ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getTypeTempFiles(), |
904 | path) + getToStringMethodClose()); | 957 | path) + getToStringMethodClose()); |
958 | + } | ||
905 | 959 | ||
906 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; | 960 | JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode; |
907 | /** | 961 | /** | ... | ... |
... | @@ -59,6 +59,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; | ... | @@ -59,6 +59,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING; |
59 | import static org.onosproject.yangutils.utils.UtilConstants.AND; | 59 | import static org.onosproject.yangutils.utils.UtilConstants.AND; |
60 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; | 60 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION; |
61 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED; | 61 | import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED; |
62 | +import static org.onosproject.yangutils.utils.UtilConstants.BASE64; | ||
62 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL; | 63 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL; |
63 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; | 64 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; |
64 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; | 65 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
... | @@ -74,10 +75,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.CLASS; | ... | @@ -74,10 +75,11 @@ import static org.onosproject.yangutils.utils.UtilConstants.CLASS; |
74 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING; | 75 | import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING; |
75 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; | 76 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET; |
76 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; | 77 | import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS; |
77 | -import static org.onosproject.yangutils.utils.UtilConstants.COLAN; | 78 | +import static org.onosproject.yangutils.utils.UtilConstants.COLON; |
78 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; | 79 | import static org.onosproject.yangutils.utils.UtilConstants.COMMA; |
79 | import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE; | 80 | import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE; |
80 | import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION; | 81 | import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION; |
82 | +import static org.onosproject.yangutils.utils.UtilConstants.DECODE; | ||
81 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; | 83 | import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT; |
82 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; | 84 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET; |
83 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; | 85 | import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET; |
... | @@ -89,11 +91,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING; | ... | @@ -89,11 +91,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING; |
89 | import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION; | 91 | import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION; |
90 | import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR; | 92 | import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR; |
91 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; | 93 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; |
94 | +import static org.onosproject.yangutils.utils.UtilConstants.FOR; | ||
92 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; | 95 | import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION; |
93 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; | 96 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME; |
94 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME; | 97 | import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME; |
95 | import static org.onosproject.yangutils.utils.UtilConstants.GET; | 98 | import static org.onosproject.yangutils.utils.UtilConstants.GET; |
96 | -import static org.onosproject.yangutils.utils.UtilConstants.GET_BYTES; | 99 | +import static org.onosproject.yangutils.utils.UtilConstants.GET_DECODER; |
97 | import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX; | 100 | import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX; |
98 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING; | 101 | import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING; |
99 | import static org.onosproject.yangutils.utils.UtilConstants.HASH; | 102 | import static org.onosproject.yangutils.utils.UtilConstants.HASH; |
... | @@ -170,6 +173,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.FILTER_CONTENT_MATCH | ... | @@ -170,6 +173,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.FILTER_CONTENT_MATCH |
170 | import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE; | 173 | import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE; |
171 | import static org.onosproject.yangutils.utils.UtilConstants.NOT; | 174 | import static org.onosproject.yangutils.utils.UtilConstants.NOT; |
172 | import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION; | 175 | import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION; |
176 | +import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING; | ||
177 | +import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE; | ||
178 | +import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING; | ||
179 | +import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS; | ||
180 | +import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING; | ||
181 | +import static org.onosproject.yangutils.utils.UtilConstants.ZERO; | ||
173 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; | 182 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD; |
174 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; | 183 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR; |
175 | import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR; | 184 | 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 | ... | @@ -188,11 +197,15 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase |
188 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; | 197 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase; |
189 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; | 198 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast; |
190 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY; | 199 | import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY; |
200 | +import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS; | ||
191 | 201 | ||
192 | /** | 202 | /** |
193 | * Represents generator for methods of generated files based on the file type. | 203 | * Represents generator for methods of generated files based on the file type. |
194 | */ | 204 | */ |
195 | public final class MethodsGenerator { | 205 | public final class MethodsGenerator { |
206 | + private static final String BITS_STRING_ARRAY_VAR = "bitsTemp"; | ||
207 | + private static final String BIT_TEMP_VAR = "bitTemp"; | ||
208 | + private static final String FOR_TYPE = " for type "; | ||
196 | 209 | ||
197 | /** | 210 | /** |
198 | * Creates an instance of method generator. | 211 | * Creates an instance of method generator. |
... | @@ -1085,14 +1098,39 @@ public final class MethodsGenerator { | ... | @@ -1085,14 +1098,39 @@ public final class MethodsGenerator { |
1085 | JavaAttributeInfo fromStringAttributeInfo) { | 1098 | JavaAttributeInfo fromStringAttributeInfo) { |
1086 | 1099 | ||
1087 | String targetDataType = getReturnType(attr); | 1100 | String targetDataType = getReturnType(attr); |
1088 | - if (fromStringAttributeInfo.getAttributeType().getDataType() == BINARY) { | 1101 | + if (fromStringAttributeInfo.getAttributeType().getDataType() == BITS) { |
1089 | - return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME | 1102 | + String lines = targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + NEW + SPACE + targetDataType |
1090 | - + PERIOD + GET_BYTES + OPEN_PARENTHESIS + CLOSE_PARENTHESIS; | 1103 | + + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; |
1104 | + lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME | ||
1105 | + + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + OPEN_CURLY_BRACKET + SINGLE_QUOTE | ||
1106 | + + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | ||
1107 | + lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME | ||
1108 | + + PERIOD + REPLACE_STRING + OPEN_PARENTHESIS + SINGLE_QUOTE + CLOSE_CURLY_BRACKET + SINGLE_QUOTE | ||
1109 | + + COMMA + SPACE + SINGLE_QUOTE + SPACE + SINGLE_QUOTE + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | ||
1110 | + lines += TWELVE_SPACE_INDENTATION + FROM_STRING_PARAM_NAME + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME | ||
1111 | + + PERIOD + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | ||
1112 | + lines += TWELVE_SPACE_INDENTATION + STRING_DATA_TYPE + SQUARE_BRACKETS + SPACE + BITS_STRING_ARRAY_VAR | ||
1113 | + + SPACE + EQUAL + SPACE + FROM_STRING_PARAM_NAME + PERIOD + SPLIT_STRING + OPEN_PARENTHESIS | ||
1114 | + + QUOTES + COMMA + QUOTES + COMMA + SPACE + ZERO + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | ||
1115 | + lines += TWELVE_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE | ||
1116 | + + BIT_TEMP_VAR + SPACE + COLON + SPACE + BITS_STRING_ARRAY_VAR + CLOSE_PARENTHESIS + SPACE | ||
1117 | + + OPEN_CURLY_BRACKET + NEW_LINE; | ||
1118 | + lines += SIXTEEN_SPACE_INDENTATION + BIT_TEMP_VAR + SPACE + EQUAL + SPACE + BIT_TEMP_VAR + PERIOD | ||
1119 | + + TRIM_STRING + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | ||
1120 | + lines += SIXTEEN_SPACE_INDENTATION + TMP_VAL + PERIOD + SET_METHOD_PREFIX + OPEN_PARENTHESIS | ||
1121 | + + INTEGER_WRAPPER + PERIOD + PARSE_INT + OPEN_PARENTHESIS + BIT_TEMP_VAR + CLOSE_PARENTHESIS | ||
1122 | + + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE; | ||
1123 | + lines += TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | ||
1124 | + return lines; | ||
1125 | + } else if (attr.getAttributeType().getDataType() == BINARY) { | ||
1126 | + return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + BASE64 + PERIOD | ||
1127 | + + GET_DECODER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + DECODE + OPEN_PARENTHESIS | ||
1128 | + + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN; | ||
1091 | } else { | 1129 | } else { |
1092 | String parseFromStringMethod = getParseFromStringMethod(targetDataType, | 1130 | String parseFromStringMethod = getParseFromStringMethod(targetDataType, |
1093 | fromStringAttributeInfo.getAttributeType()); | 1131 | fromStringAttributeInfo.getAttributeType()); |
1094 | return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod | 1132 | return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod |
1095 | - + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS; | 1133 | + + OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN; |
1096 | } | 1134 | } |
1097 | } | 1135 | } |
1098 | 1136 | ||
... | @@ -1350,15 +1388,15 @@ public final class MethodsGenerator { | ... | @@ -1350,15 +1388,15 @@ public final class MethodsGenerator { |
1350 | for (String str : enumList) { | 1388 | for (String str : enumList) { |
1351 | 1389 | ||
1352 | value = enumMap.get(str); | 1390 | value = enumMap.get(str); |
1353 | - method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLAN + NEW_LINE | 1391 | + method = method + TWELVE_SPACE_INDENTATION + CASE + SPACE + value + COLON + NEW_LINE |
1354 | + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD | 1392 | + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + getCapitalCase(className) + PERIOD |
1355 | + str + SEMI_COLAN + NEW_LINE; | 1393 | + str + SEMI_COLAN + NEW_LINE; |
1356 | } | 1394 | } |
1357 | - method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLAN + NEW_LINE + SIXTEEN_SPACE_INDENTATION | 1395 | + method = method + TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON + NEW_LINE + SIXTEEN_SPACE_INDENTATION |
1358 | + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET | 1396 | + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET |
1359 | + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; | 1397 | + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET; |
1360 | 1398 | ||
1361 | - return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type " + attrName, false, pluginConfig) | 1399 | + return getJavaDoc(OF_METHOD, getCapitalCase(className) + FOR_TYPE + attrName, false, pluginConfig) |
1362 | + method; | 1400 | + method; |
1363 | } | 1401 | } |
1364 | 1402 | ... | ... |
... | @@ -237,6 +237,31 @@ public final class UtilConstants { | ... | @@ -237,6 +237,31 @@ public final class UtilConstants { |
237 | public static final String PARSE_LONG = "parseLong"; | 237 | public static final String PARSE_LONG = "parseLong"; |
238 | 238 | ||
239 | /** | 239 | /** |
240 | + * Static attribute for base64. | ||
241 | + */ | ||
242 | + public static final String BASE64 = "Base64"; | ||
243 | + | ||
244 | + /** | ||
245 | + * Static attribute for getEncoder. | ||
246 | + */ | ||
247 | + public static final String GET_ENCODER = "getEncoder"; | ||
248 | + | ||
249 | + /** | ||
250 | + * Static attribute for encodeToString. | ||
251 | + */ | ||
252 | + public static final String ENCODE_TO_STRING = "encodeToString"; | ||
253 | + | ||
254 | + /** | ||
255 | + * Static attribute for getDecoder. | ||
256 | + */ | ||
257 | + public static final String GET_DECODER = "getDecoder"; | ||
258 | + | ||
259 | + /** | ||
260 | + * Static attribute for decode. | ||
261 | + */ | ||
262 | + public static final String DECODE = "decode"; | ||
263 | + | ||
264 | + /** | ||
240 | * Static attribute for omit null value. | 265 | * Static attribute for omit null value. |
241 | */ | 266 | */ |
242 | public static final String OMIT_NULL_VALUE_STRING = "omitNullValues()"; | 267 | public static final String OMIT_NULL_VALUE_STRING = "omitNullValues()"; |
... | @@ -322,6 +347,16 @@ public final class UtilConstants { | ... | @@ -322,6 +347,16 @@ public final class UtilConstants { |
322 | public static final String IDENTITYREF = "identityref"; | 347 | public static final String IDENTITYREF = "identityref"; |
323 | 348 | ||
324 | /** | 349 | /** |
350 | + * Static attribute for binary string. | ||
351 | + */ | ||
352 | + public static final String BINARY_STRING = "binary"; | ||
353 | + | ||
354 | + /** | ||
355 | + * Static attribute for bits string. | ||
356 | + */ | ||
357 | + public static final String BITS_STRING = "bits"; | ||
358 | + | ||
359 | + /** | ||
325 | * Static attribute for output variable of rpc. | 360 | * Static attribute for output variable of rpc. |
326 | */ | 361 | */ |
327 | public static final String RPC_INPUT_VAR_NAME = "inputVar"; | 362 | public static final String RPC_INPUT_VAR_NAME = "inputVar"; |
... | @@ -342,11 +377,21 @@ public final class UtilConstants { | ... | @@ -342,11 +377,21 @@ public final class UtilConstants { |
342 | public static final String ADD = "+"; | 377 | public static final String ADD = "+"; |
343 | 378 | ||
344 | /** | 379 | /** |
380 | + * Static attribute for single quote. | ||
381 | + */ | ||
382 | + public static final String SINGLE_QUOTE = "\'"; | ||
383 | + | ||
384 | + /** | ||
345 | * Static attribute for quotes. | 385 | * Static attribute for quotes. |
346 | */ | 386 | */ |
347 | public static final String QUOTES = "\""; | 387 | public static final String QUOTES = "\""; |
348 | 388 | ||
349 | /** | 389 | /** |
390 | + * Static attribute for zero. | ||
391 | + */ | ||
392 | + public static final String ZERO = "0"; | ||
393 | + | ||
394 | + /** | ||
350 | * Static attribute for ampersand. | 395 | * Static attribute for ampersand. |
351 | */ | 396 | */ |
352 | public static final String AND = "&"; | 397 | public static final String AND = "&"; |
... | @@ -412,6 +457,21 @@ public final class UtilConstants { | ... | @@ -412,6 +457,21 @@ public final class UtilConstants { |
412 | public static final String ADD_STRING = "add"; | 457 | public static final String ADD_STRING = "add"; |
413 | 458 | ||
414 | /** | 459 | /** |
460 | + * Static attribute for string replace syntax. | ||
461 | + */ | ||
462 | + public static final String REPLACE_STRING = "replace"; | ||
463 | + | ||
464 | + /** | ||
465 | + * Static attribute for string trim syntax. | ||
466 | + */ | ||
467 | + public static final String TRIM_STRING = "trim"; | ||
468 | + | ||
469 | + /** | ||
470 | + * Static attribute for string split syntax. | ||
471 | + */ | ||
472 | + public static final String SPLIT_STRING = "split"; | ||
473 | + | ||
474 | + /** | ||
415 | * Static attribute for from syntax. | 475 | * Static attribute for from syntax. |
416 | */ | 476 | */ |
417 | public static final String FROM_STRING_METHOD_NAME = "fromString"; | 477 | public static final String FROM_STRING_METHOD_NAME = "fromString"; |
... | @@ -457,6 +517,11 @@ public final class UtilConstants { | ... | @@ -457,6 +517,11 @@ public final class UtilConstants { |
457 | public static final String IF = "if"; | 517 | public static final String IF = "if"; |
458 | 518 | ||
459 | /** | 519 | /** |
520 | + * Static attribute for "for" syntax. | ||
521 | + */ | ||
522 | + public static final String FOR = "for"; | ||
523 | + | ||
524 | + /** | ||
460 | * Static attribute for of. | 525 | * Static attribute for of. |
461 | */ | 526 | */ |
462 | public static final String OF = "of"; | 527 | public static final String OF = "of"; |
... | @@ -1103,6 +1168,11 @@ public final class UtilConstants { | ... | @@ -1103,6 +1168,11 @@ public final class UtilConstants { |
1103 | public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n"; | 1168 | public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n"; |
1104 | 1169 | ||
1105 | /** | 1170 | /** |
1171 | + * Static attribute for java utilities import base64 class. | ||
1172 | + */ | ||
1173 | + public static final String JAVA_UTIL_IMPORT_BASE64_CLASS = "Base64;\n"; | ||
1174 | + | ||
1175 | + /** | ||
1106 | * Static attribute for AugmentedInfo class import package. | 1176 | * Static attribute for AugmentedInfo class import package. |
1107 | */ | 1177 | */ |
1108 | public static final String YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG = "org.onosproject.yangutils.datamodel"; | 1178 | 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; | ... | @@ -21,6 +21,7 @@ import static org.hamcrest.core.Is.is; |
21 | import org.junit.Test; | 21 | import org.junit.Test; |
22 | import org.onosproject.yangutils.datamodel.YangBit; | 22 | import org.onosproject.yangutils.datamodel.YangBit; |
23 | import org.onosproject.yangutils.datamodel.YangBits; | 23 | import org.onosproject.yangutils.datamodel.YangBits; |
24 | +import org.onosproject.yangutils.datamodel.YangDerivedInfo; | ||
24 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | 25 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
25 | import org.onosproject.yangutils.datamodel.YangLeaf; | 26 | import org.onosproject.yangutils.datamodel.YangLeaf; |
26 | import org.onosproject.yangutils.datamodel.YangModule; | 27 | import org.onosproject.yangutils.datamodel.YangModule; |
... | @@ -168,6 +169,117 @@ public class BitListenerTest { | ... | @@ -168,6 +169,117 @@ public class BitListenerTest { |
168 | } | 169 | } |
169 | 170 | ||
170 | /** | 171 | /** |
172 | + * Checks bit statement with typedef with referred leaf. | ||
173 | + */ | ||
174 | + @Test | ||
175 | + public void processBitTypedefReferredLeafStatement() throws IOException, ParserException { | ||
176 | + | ||
177 | + YangNode node = manager.getDataModel("src/test/resources/BitTypedefReferredLeafStatement.yang"); | ||
178 | + | ||
179 | + // Check whether the data model tree returned is of type module. | ||
180 | + assertThat((node instanceof YangModule), is(true)); | ||
181 | + | ||
182 | + // Check whether the node type is set properly to module. | ||
183 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
184 | + | ||
185 | + // Check whether the module name is set correctly. | ||
186 | + YangModule yangNode = (YangModule) node; | ||
187 | + assertThat(yangNode.getName(), is("Test")); | ||
188 | + | ||
189 | + YangTypeDef typedef = (YangTypeDef) yangNode.getChild(); | ||
190 | + assertThat(typedef.getName(), is("topBits")); | ||
191 | + | ||
192 | + YangType type = typedef.getTypeList().iterator().next(); | ||
193 | + assertThat(type.getDataType(), is(YangDataTypes.BITS)); | ||
194 | + assertThat(type.getDataTypeName(), is("bits")); | ||
195 | + | ||
196 | + // Check bit name map | ||
197 | + Map<String, YangBit> bitNameMap = ((YangBits) type.getDataTypeExtendedInfo()).getBitNameMap(); | ||
198 | + assertThat(bitNameMap.size(), is(3)); | ||
199 | + for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) { | ||
200 | + String bitName = element.getKey(); | ||
201 | + YangBit yangBit = element.getValue(); | ||
202 | + if (bitName.equals("disable-nagle")) { | ||
203 | + assertThat(yangBit.getPosition(), is(0)); | ||
204 | + } else if (bitName.equals("auto-sense-speed")) { | ||
205 | + assertThat(yangBit.getPosition(), is(1)); | ||
206 | + } else if (bitName.equals("Mb-only")) { | ||
207 | + assertThat(yangBit.getPosition(), is(2)); | ||
208 | + } else { | ||
209 | + throw new IOException("Invalid bit name: " + bitName); | ||
210 | + } | ||
211 | + } | ||
212 | + | ||
213 | + // Check bit position map | ||
214 | + Map<Integer, YangBit> bitPositionMap = ((YangBits) type.getDataTypeExtendedInfo()).getBitPositionMap(); | ||
215 | + assertThat(bitPositionMap.size(), is(3)); | ||
216 | + for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) { | ||
217 | + int position = element.getKey(); | ||
218 | + YangBit yangBit = element.getValue(); | ||
219 | + if (position == 0) { | ||
220 | + assertThat(yangBit.getBitName(), is("disable-nagle")); | ||
221 | + } else if (position == 1) { | ||
222 | + assertThat(yangBit.getBitName(), is("auto-sense-speed")); | ||
223 | + } else if (position == 2) { | ||
224 | + assertThat(yangBit.getBitName(), is("Mb-only")); | ||
225 | + } else { | ||
226 | + throw new IOException("Invalid bit position: " + position); | ||
227 | + } | ||
228 | + } | ||
229 | + | ||
230 | + // Check leaf reffered typedef | ||
231 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
232 | + YangLeaf leafInfo = leafIterator.next(); | ||
233 | + | ||
234 | + assertThat(leafInfo.getName(), is("myBits")); | ||
235 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("topBits")); | ||
236 | + assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.DERIVED)); | ||
237 | + YangType<YangDerivedInfo> typeDerived = (YangType<YangDerivedInfo>) leafInfo.getDataType(); | ||
238 | + YangDerivedInfo derivedInfo = (YangDerivedInfo) typeDerived.getDataTypeExtendedInfo(); | ||
239 | + YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | ||
240 | + assertThat(prevTypedef.getName(), is("topBits")); | ||
241 | + YangType topType = prevTypedef.getTypeList().iterator().next(); | ||
242 | + assertThat(topType.getDataType(), is(YangDataTypes.BITS)); | ||
243 | + assertThat(topType.getDataTypeName(), is("bits")); | ||
244 | + YangType<YangBits> typeBits = (YangType<YangBits>) topType; | ||
245 | + YangBits bits = typeBits.getDataTypeExtendedInfo(); | ||
246 | + | ||
247 | + // Check bit name map | ||
248 | + bitNameMap = bits.getBitNameMap(); | ||
249 | + assertThat(bitNameMap.size(), is(3)); | ||
250 | + for (Map.Entry<String, YangBit> element : bitNameMap.entrySet()) { | ||
251 | + String bitName = element.getKey(); | ||
252 | + YangBit yangBit = element.getValue(); | ||
253 | + if (bitName.equals("disable-nagle")) { | ||
254 | + assertThat(yangBit.getPosition(), is(0)); | ||
255 | + } else if (bitName.equals("auto-sense-speed")) { | ||
256 | + assertThat(yangBit.getPosition(), is(1)); | ||
257 | + } else if (bitName.equals("Mb-only")) { | ||
258 | + assertThat(yangBit.getPosition(), is(2)); | ||
259 | + } else { | ||
260 | + throw new IOException("Invalid bit name: " + bitName); | ||
261 | + } | ||
262 | + } | ||
263 | + | ||
264 | + // Check bit position map | ||
265 | + bitPositionMap = bits.getBitPositionMap(); | ||
266 | + assertThat(bitPositionMap.size(), is(3)); | ||
267 | + for (Map.Entry<Integer, YangBit> element : bitPositionMap.entrySet()) { | ||
268 | + int position = element.getKey(); | ||
269 | + YangBit yangBit = element.getValue(); | ||
270 | + if (position == 0) { | ||
271 | + assertThat(yangBit.getBitName(), is("disable-nagle")); | ||
272 | + } else if (position == 1) { | ||
273 | + assertThat(yangBit.getBitName(), is("auto-sense-speed")); | ||
274 | + } else if (position == 2) { | ||
275 | + assertThat(yangBit.getBitName(), is("Mb-only")); | ||
276 | + } else { | ||
277 | + throw new IOException("Invalid bit position: " + position); | ||
278 | + } | ||
279 | + } | ||
280 | + } | ||
281 | + | ||
282 | + /** | ||
171 | * Checks bit statement with union. | 283 | * Checks bit statement with union. |
172 | */ | 284 | */ |
173 | @Test | 285 | @Test | ... | ... |
... | @@ -33,6 +33,7 @@ import org.onosproject.yangutils.datamodel.YangRangeInterval; | ... | @@ -33,6 +33,7 @@ import org.onosproject.yangutils.datamodel.YangRangeInterval; |
33 | import org.onosproject.yangutils.datamodel.YangType; | 33 | import org.onosproject.yangutils.datamodel.YangType; |
34 | import org.onosproject.yangutils.datamodel.YangTypeDef; | 34 | import org.onosproject.yangutils.datamodel.YangTypeDef; |
35 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; | 35 | import org.onosproject.yangutils.datamodel.exceptions.DataModelException; |
36 | +import org.onosproject.yangutils.linker.exceptions.LinkerException; | ||
36 | import org.onosproject.yangutils.parser.exceptions.ParserException; | 37 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
37 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; | 38 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
38 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; | 39 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
... | @@ -56,7 +57,7 @@ public class Decimal64ListenerTest { | ... | @@ -56,7 +57,7 @@ public class Decimal64ListenerTest { |
56 | @Test | 57 | @Test |
57 | public void processDecimal64TypeStatement() throws IOException, ParserException { | 58 | public void processDecimal64TypeStatement() throws IOException, ParserException { |
58 | 59 | ||
59 | - YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeStatement.yang"); | 60 | + YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeStatement.yang"); |
60 | 61 | ||
61 | // Check whether the data model tree returned is of type module. | 62 | // Check whether the data model tree returned is of type module. |
62 | assertThat((node instanceof YangModule), is(true)); | 63 | assertThat((node instanceof YangModule), is(true)); |
... | @@ -84,7 +85,7 @@ public class Decimal64ListenerTest { | ... | @@ -84,7 +85,7 @@ public class Decimal64ListenerTest { |
84 | @Test | 85 | @Test |
85 | public void processDecimal64TypeWithRangeStatement() throws IOException, ParserException { | 86 | public void processDecimal64TypeWithRangeStatement() throws IOException, ParserException { |
86 | 87 | ||
87 | - YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeWithRangeStatement.yang"); | 88 | + YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeWithRangeStatement.yang"); |
88 | 89 | ||
89 | // Check whether the data model tree returned is of type module. | 90 | // Check whether the data model tree returned is of type module. |
90 | assertThat((node instanceof YangModule), is(true)); | 91 | assertThat((node instanceof YangModule), is(true)); |
... | @@ -122,7 +123,7 @@ public class Decimal64ListenerTest { | ... | @@ -122,7 +123,7 @@ public class Decimal64ListenerTest { |
122 | @Test | 123 | @Test |
123 | public void processDecimal64ValueSuccessfulValidation() throws IOException, ParserException, DataModelException { | 124 | public void processDecimal64ValueSuccessfulValidation() throws IOException, ParserException, DataModelException { |
124 | 125 | ||
125 | - YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeValidation.yang"); | 126 | + YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeValidation.yang"); |
126 | 127 | ||
127 | // Check whether the data model tree returned is of type module. | 128 | // Check whether the data model tree returned is of type module. |
128 | assertThat((node instanceof YangModule), is(true)); | 129 | assertThat((node instanceof YangModule), is(true)); |
... | @@ -157,7 +158,7 @@ public class Decimal64ListenerTest { | ... | @@ -157,7 +158,7 @@ public class Decimal64ListenerTest { |
157 | thrown.expect(DataModelException.class); | 158 | thrown.expect(DataModelException.class); |
158 | thrown.expectMessage("YANG file error : decimal64 validation failed."); | 159 | thrown.expectMessage("YANG file error : decimal64 validation failed."); |
159 | 160 | ||
160 | - YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeValidation.yang"); | 161 | + YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeValidation.yang"); |
161 | 162 | ||
162 | // Check whether the data model tree returned is of type module. | 163 | // Check whether the data model tree returned is of type module. |
163 | assertThat((node instanceof YangModule), is(true)); | 164 | assertThat((node instanceof YangModule), is(true)); |
... | @@ -191,7 +192,7 @@ public class Decimal64ListenerTest { | ... | @@ -191,7 +192,7 @@ public class Decimal64ListenerTest { |
191 | thrown.expect(ParserException.class); | 192 | thrown.expect(ParserException.class); |
192 | thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18."); | 193 | thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18."); |
193 | 194 | ||
194 | - manager.getDataModel("src/test/resources/Decimal64TypeInvalidMaxValueFraction.yang"); | 195 | + manager.getDataModel("src/test/resources/decimal64/Decimal64TypeInvalidMaxValueFraction.yang"); |
195 | } | 196 | } |
196 | 197 | ||
197 | /** | 198 | /** |
... | @@ -202,7 +203,7 @@ public class Decimal64ListenerTest { | ... | @@ -202,7 +203,7 @@ public class Decimal64ListenerTest { |
202 | thrown.expect(ParserException.class); | 203 | thrown.expect(ParserException.class); |
203 | thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18."); | 204 | thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18."); |
204 | 205 | ||
205 | - manager.getDataModel("src/test/resources/Decimal64TypeInvalidMinValueFraction1.yang"); | 206 | + manager.getDataModel("src/test/resources/decimal64/Decimal64TypeInvalidMinValueFraction1.yang"); |
206 | } | 207 | } |
207 | 208 | ||
208 | /** | 209 | /** |
... | @@ -213,7 +214,7 @@ public class Decimal64ListenerTest { | ... | @@ -213,7 +214,7 @@ public class Decimal64ListenerTest { |
213 | thrown.expect(ParserException.class); | 214 | thrown.expect(ParserException.class); |
214 | thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18."); | 215 | thrown.expectMessage("YANG file error : fraction-digits value should be between 1 and 18."); |
215 | 216 | ||
216 | - manager.getDataModel("src/test/resources/Decimal64TypeInvalidMinValueFraction2.yang"); | 217 | + manager.getDataModel("src/test/resources/decimal64/Decimal64TypeInvalidMinValueFraction2.yang"); |
217 | } | 218 | } |
218 | 219 | ||
219 | /** | 220 | /** |
... | @@ -222,7 +223,7 @@ public class Decimal64ListenerTest { | ... | @@ -222,7 +223,7 @@ public class Decimal64ListenerTest { |
222 | @Test | 223 | @Test |
223 | public void processDecimal64TypeWithMultiValueRangeStatement() throws IOException, ParserException { | 224 | public void processDecimal64TypeWithMultiValueRangeStatement() throws IOException, ParserException { |
224 | 225 | ||
225 | - YangNode node = manager.getDataModel("src/test/resources/Decimal64TypeWithMultiValueRangeStmnt.yang"); | 226 | + YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypeWithMultiValueRangeStmnt.yang"); |
226 | 227 | ||
227 | // Check whether the data model tree returned is of type module. | 228 | // Check whether the data model tree returned is of type module. |
228 | assertThat((node instanceof YangModule), is(true)); | 229 | assertThat((node instanceof YangModule), is(true)); |
... | @@ -272,7 +273,7 @@ public class Decimal64ListenerTest { | ... | @@ -272,7 +273,7 @@ public class Decimal64ListenerTest { |
272 | thrown.expect(ParserException.class); | 273 | thrown.expect(ParserException.class); |
273 | thrown.expectMessage("YANG file error : decimal64 validation failed."); | 274 | thrown.expectMessage("YANG file error : decimal64 validation failed."); |
274 | 275 | ||
275 | - manager.getDataModel("src/test/resources/Decimal64TypeInvalidRangeStmnt.yang"); | 276 | + manager.getDataModel("src/test/resources/decimal64/Decimal64TypeInvalidRangeStmnt.yang"); |
276 | } | 277 | } |
277 | 278 | ||
278 | /** | 279 | /** |
... | @@ -283,7 +284,7 @@ public class Decimal64ListenerTest { | ... | @@ -283,7 +284,7 @@ public class Decimal64ListenerTest { |
283 | thrown.expect(ParserException.class); | 284 | thrown.expect(ParserException.class); |
284 | thrown.expectMessage("YANG file error : a type decimal64 must have fraction-digits statement."); | 285 | thrown.expectMessage("YANG file error : a type decimal64 must have fraction-digits statement."); |
285 | 286 | ||
286 | - manager.getDataModel("src/test/resources/Decimal64TypeWithoutFraction.yang"); | 287 | + manager.getDataModel("src/test/resources/decimal64/Decimal64TypeWithoutFraction.yang"); |
287 | } | 288 | } |
288 | 289 | ||
289 | /** | 290 | /** |
... | @@ -292,7 +293,7 @@ public class Decimal64ListenerTest { | ... | @@ -292,7 +293,7 @@ public class Decimal64ListenerTest { |
292 | @Test | 293 | @Test |
293 | public void processDecimal64TypedefStatement() throws IOException, ParserException { | 294 | public void processDecimal64TypedefStatement() throws IOException, ParserException { |
294 | 295 | ||
295 | - YangNode node = manager.getDataModel("src/test/resources/Decimal64TypedefStatement.yang"); | 296 | + YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64TypedefStatement.yang"); |
296 | 297 | ||
297 | // Check whether the data model tree returned is of type module. | 298 | // Check whether the data model tree returned is of type module. |
298 | assertThat((node instanceof YangModule), is(true)); | 299 | assertThat((node instanceof YangModule), is(true)); |
... | @@ -329,7 +330,7 @@ public class Decimal64ListenerTest { | ... | @@ -329,7 +330,7 @@ public class Decimal64ListenerTest { |
329 | @Test | 330 | @Test |
330 | public void processDecimal64MultiTypedefStatement() throws IOException, ParserException { | 331 | public void processDecimal64MultiTypedefStatement() throws IOException, ParserException { |
331 | 332 | ||
332 | - YangNode node = manager.getDataModel("src/test/resources/Decimal64MultiTypedefStatement.yang"); | 333 | + YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefStatement.yang"); |
333 | 334 | ||
334 | // Check whether the data model tree returned is of type module. | 335 | // Check whether the data model tree returned is of type module. |
335 | assertThat((node instanceof YangModule), is(true)); | 336 | assertThat((node instanceof YangModule), is(true)); |
... | @@ -345,15 +346,264 @@ public class Decimal64ListenerTest { | ... | @@ -345,15 +346,264 @@ public class Decimal64ListenerTest { |
345 | YangLeaf leafInfo = leafIterator.next(); | 346 | YangLeaf leafInfo = leafIterator.next(); |
346 | 347 | ||
347 | // check leaf type | 348 | // check leaf type |
348 | - assertThat(leafInfo.getName(), is("setFourDecimal")); | 349 | + assertThat(leafInfo.getName(), is("lowerDecimal")); |
349 | - assertThat(leafInfo.getDataType().getDataTypeName(), is("validDecimal")); | 350 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal")); |
351 | + YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType(); | ||
352 | + assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED)); | ||
353 | + YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo(); | ||
354 | + | ||
355 | + // check previous typedef | ||
356 | + YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | ||
357 | + assertThat(prevTypedef.getName(), is("midDecimal")); | ||
358 | + YangType type = prevTypedef.getTypeList().iterator().next(); | ||
359 | + assertThat(type.getDataType(), is(YangDataTypes.DERIVED)); | ||
360 | + derivedInfo = (YangDerivedInfo) type.getDataTypeExtendedInfo(); | ||
361 | + | ||
362 | + // check top typedef | ||
363 | + YangTypeDef topTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | ||
364 | + assertThat(topTypedef.getName(), is("topDecimal")); | ||
365 | + type = topTypedef.getTypeList().iterator().next(); | ||
366 | + assertThat(type.getDataType(), is(YangDataTypes.DECIMAL64)); | ||
367 | + assertThat(type.getDataTypeName(), is("decimal64")); | ||
368 | + YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) type; | ||
369 | + YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo(); | ||
370 | + assertThat(decimal64.getFractionDigit(), is(4)); | ||
371 | + } | ||
372 | + | ||
373 | + /** | ||
374 | + * Checks decimal64 with multiple typedef with single range statement. | ||
375 | + * Range value in typedef statement. | ||
376 | + */ | ||
377 | + @Test | ||
378 | + public void processDecimal64MultiTypedefRangeStatement() throws IOException, ParserException { | ||
379 | + | ||
380 | + YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefRangeStatement.yang"); | ||
381 | + | ||
382 | + // Check whether the data model tree returned is of type module. | ||
383 | + assertThat((node instanceof YangModule), is(true)); | ||
384 | + | ||
385 | + // Check whether the node type is set properly to module. | ||
386 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
387 | + | ||
388 | + // Check whether the module name is set correctly. | ||
389 | + YangModule yangNode = (YangModule) node; | ||
390 | + assertThat(yangNode.getName(), is("Test")); | ||
391 | + | ||
392 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
393 | + YangLeaf leafInfo = leafIterator.next(); | ||
394 | + | ||
395 | + // check leaf type | ||
396 | + assertThat(leafInfo.getName(), is("lowerDecimal")); | ||
397 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal")); | ||
398 | + YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType(); | ||
399 | + assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED)); | ||
400 | + YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo(); | ||
401 | + | ||
402 | + // Check range restriction | ||
403 | + YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
404 | + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals() | ||
405 | + .listIterator(); | ||
406 | + YangRangeInterval rangeInterval = rangeListIterator.next(); | ||
407 | + assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0)); | ||
408 | + assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0)); | ||
409 | + | ||
410 | + // check previous typedef | ||
411 | + YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | ||
412 | + assertThat(prevTypedef.getName(), is("midDecimal")); | ||
413 | + YangType type = prevTypedef.getTypeList().iterator().next(); | ||
414 | + assertThat(type.getDataType(), is(YangDataTypes.DERIVED)); | ||
415 | + derivedInfo = (YangDerivedInfo) type.getDataTypeExtendedInfo(); | ||
416 | + | ||
417 | + // check top typedef | ||
418 | + YangTypeDef topTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | ||
419 | + assertThat(topTypedef.getName(), is("topDecimal")); | ||
420 | + type = topTypedef.getTypeList().iterator().next(); | ||
421 | + assertThat(type.getDataType(), is(YangDataTypes.DECIMAL64)); | ||
422 | + assertThat(type.getDataTypeName(), is("decimal64")); | ||
423 | + YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) type; | ||
424 | + YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo(); | ||
425 | + assertThat(decimal64.getFractionDigit(), is(4)); | ||
426 | + | ||
427 | + // Check range restriction | ||
428 | + rangeRestriction = (YangRangeRestriction) decimal64.getRangeRestrictedExtendedInfo(); | ||
429 | + rangeListIterator = rangeRestriction.getAscendingRangeIntervals().listIterator(); | ||
430 | + rangeInterval = rangeListIterator.next(); | ||
431 | + assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0)); | ||
432 | + assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0)); | ||
433 | + } | ||
434 | + | ||
435 | + /** | ||
436 | + * Checks decimal64 with multiple typedef with single range statement. | ||
437 | + * Range value in leaf statement. | ||
438 | + */ | ||
439 | + @Test | ||
440 | + public void processDecimal64MultiTypedefRangeInLeafStatement() throws IOException, ParserException { | ||
441 | + | ||
442 | + YangNode node = manager | ||
443 | + .getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefRangeInLeafStatement.yang"); | ||
444 | + | ||
445 | + // Check whether the data model tree returned is of type module. | ||
446 | + assertThat((node instanceof YangModule), is(true)); | ||
447 | + | ||
448 | + // Check whether the node type is set properly to module. | ||
449 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
450 | + | ||
451 | + // Check whether the module name is set correctly. | ||
452 | + YangModule yangNode = (YangModule) node; | ||
453 | + assertThat(yangNode.getName(), is("Test")); | ||
454 | + | ||
455 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
456 | + YangLeaf leafInfo = leafIterator.next(); | ||
457 | + | ||
458 | + // check leaf type | ||
459 | + assertThat(leafInfo.getName(), is("lowerDecimal")); | ||
460 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal")); | ||
461 | + YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType(); | ||
462 | + assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED)); | ||
463 | + YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo(); | ||
464 | + | ||
465 | + // Check range restriction | ||
466 | + YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
467 | + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals() | ||
468 | + .listIterator(); | ||
469 | + YangRangeInterval rangeInterval = rangeListIterator.next(); | ||
470 | + assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0)); | ||
471 | + assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0)); | ||
472 | + | ||
473 | + // check previous typedef | ||
474 | + YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | ||
475 | + assertThat(prevTypedef.getName(), is("midDecimal")); | ||
476 | + YangType type = prevTypedef.getTypeList().iterator().next(); | ||
477 | + assertThat(type.getDataType(), is(YangDataTypes.DERIVED)); | ||
478 | + derivedInfo = (YangDerivedInfo) type.getDataTypeExtendedInfo(); | ||
479 | + | ||
480 | + // check top typedef | ||
481 | + YangTypeDef topTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | ||
482 | + assertThat(topTypedef.getName(), is("topDecimal")); | ||
483 | + type = topTypedef.getTypeList().iterator().next(); | ||
484 | + assertThat(type.getDataType(), is(YangDataTypes.DECIMAL64)); | ||
485 | + assertThat(type.getDataTypeName(), is("decimal64")); | ||
486 | + YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) type; | ||
487 | + YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo(); | ||
488 | + assertThat(decimal64.getFractionDigit(), is(4)); | ||
489 | + } | ||
490 | + | ||
491 | + /** | ||
492 | + * Checks decimal64 with multiple typedef with multiple range statement. | ||
493 | + * Having more restricted range at leaf. | ||
494 | + */ | ||
495 | + @Test | ||
496 | + public void processDecimal64MultiTypedefMultipleRangeStatement() throws IOException, ParserException { | ||
497 | + | ||
498 | + YangNode node = manager | ||
499 | + .getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefMultiRangeStatement.yang"); | ||
500 | + | ||
501 | + // Check whether the data model tree returned is of type module. | ||
502 | + assertThat((node instanceof YangModule), is(true)); | ||
503 | + | ||
504 | + // Check whether the node type is set properly to module. | ||
505 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
506 | + | ||
507 | + // Check whether the module name is set correctly. | ||
508 | + YangModule yangNode = (YangModule) node; | ||
509 | + assertThat(yangNode.getName(), is("Test")); | ||
510 | + | ||
511 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
512 | + YangLeaf leafInfo = leafIterator.next(); | ||
513 | + | ||
514 | + // check leaf type | ||
515 | + assertThat(leafInfo.getName(), is("lowerDecimal")); | ||
516 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal")); | ||
517 | + YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType(); | ||
518 | + assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED)); | ||
519 | + YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo(); | ||
520 | + | ||
521 | + // Check range restriction | ||
522 | + YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
523 | + | ||
524 | + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals() | ||
525 | + .listIterator(); | ||
526 | + YangRangeInterval rangeInterval = rangeListIterator.next(); | ||
527 | + assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(4.0)); | ||
528 | + assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(11.0)); | ||
529 | + | ||
530 | + // check previous typedef | ||
531 | + YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | ||
532 | + assertThat(prevTypedef.getName(), is("midDecimal")); | ||
533 | + YangType type = prevTypedef.getTypeList().iterator().next(); | ||
534 | + assertThat(type.getDataType(), is(YangDataTypes.DERIVED)); | ||
535 | + derivedInfo = (YangDerivedInfo) type.getDataTypeExtendedInfo(); | ||
536 | + | ||
537 | + // check top typedef | ||
538 | + YangTypeDef topTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | ||
539 | + assertThat(topTypedef.getName(), is("topDecimal")); | ||
540 | + type = topTypedef.getTypeList().iterator().next(); | ||
541 | + assertThat(type.getDataType(), is(YangDataTypes.DECIMAL64)); | ||
542 | + assertThat(type.getDataTypeName(), is("decimal64")); | ||
543 | + YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) type; | ||
544 | + YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo(); | ||
545 | + assertThat(decimal64.getFractionDigit(), is(4)); | ||
546 | + | ||
547 | + // Check range restriction | ||
548 | + rangeRestriction = (YangRangeRestriction) decimal64.getRangeRestrictedExtendedInfo(); | ||
549 | + rangeListIterator = rangeRestriction.getAscendingRangeIntervals().listIterator(); | ||
550 | + rangeInterval = rangeListIterator.next(); | ||
551 | + assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0)); | ||
552 | + assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0)); | ||
553 | + } | ||
554 | + | ||
555 | + /** | ||
556 | + * Checks decimal64 with multiple typedef with multiple range statement. | ||
557 | + * But having more restricted range at top of typedef. | ||
558 | + */ | ||
559 | + @Test | ||
560 | + public void processDecimal64MultiTypedefMultiInvalidRangeStatement() throws IOException, LinkerException { | ||
561 | + thrown.expect(LinkerException.class); | ||
562 | + thrown.expectMessage(" Range interval doesn't fall within the referred restriction ranges"); | ||
563 | + | ||
564 | + manager.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefMultiInvalidRangeStatement.yang"); | ||
565 | + } | ||
566 | + | ||
567 | + /** | ||
568 | + * Checks decimal64 with multiple typedef with max range statement. | ||
569 | + */ | ||
570 | + @Test | ||
571 | + public void processDecimal64MultiTypedefWithMaxRange() throws IOException, ParserException { | ||
572 | + | ||
573 | + YangNode node = manager.getDataModel("src/test/resources/decimal64/Decimal64MultiTypedefWithMaxRange.yang"); | ||
574 | + | ||
575 | + // Check whether the data model tree returned is of type module. | ||
576 | + assertThat((node instanceof YangModule), is(true)); | ||
577 | + | ||
578 | + // Check whether the node type is set properly to module. | ||
579 | + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); | ||
580 | + | ||
581 | + // Check whether the module name is set correctly. | ||
582 | + YangModule yangNode = (YangModule) node; | ||
583 | + assertThat(yangNode.getName(), is("Test")); | ||
584 | + | ||
585 | + ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); | ||
586 | + YangLeaf leafInfo = leafIterator.next(); | ||
587 | + | ||
588 | + // check leaf type | ||
589 | + assertThat(leafInfo.getName(), is("lowerDecimal")); | ||
590 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("midDecimal")); | ||
350 | YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType(); | 591 | YangType<YangDerivedInfo> derivedInfoType = (YangType<YangDerivedInfo>) leafInfo.getDataType(); |
351 | assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED)); | 592 | assertThat(derivedInfoType.getDataType(), is(YangDataTypes.DERIVED)); |
352 | YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo(); | 593 | YangDerivedInfo derivedInfo = (YangDerivedInfo) derivedInfoType.getDataTypeExtendedInfo(); |
353 | 594 | ||
595 | + // Check range restriction | ||
596 | + YangRangeRestriction rangeRestriction = (YangRangeRestriction) derivedInfo.getResolvedExtendedInfo(); | ||
597 | + | ||
598 | + ListIterator<YangRangeInterval> rangeListIterator = rangeRestriction.getAscendingRangeIntervals() | ||
599 | + .listIterator(); | ||
600 | + YangRangeInterval rangeInterval = rangeListIterator.next(); | ||
601 | + assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(4.0)); | ||
602 | + assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0)); | ||
603 | + | ||
354 | // check previous typedef | 604 | // check previous typedef |
355 | YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); | 605 | YangTypeDef prevTypedef = (YangTypeDef) derivedInfo.getReferredTypeDef(); |
356 | - assertThat(prevTypedef.getName(), is("validDecimal")); | 606 | + assertThat(prevTypedef.getName(), is("midDecimal")); |
357 | YangType type = prevTypedef.getTypeList().iterator().next(); | 607 | YangType type = prevTypedef.getTypeList().iterator().next(); |
358 | assertThat(type.getDataType(), is(YangDataTypes.DERIVED)); | 608 | assertThat(type.getDataType(), is(YangDataTypes.DERIVED)); |
359 | derivedInfo = (YangDerivedInfo) type.getDataTypeExtendedInfo(); | 609 | derivedInfo = (YangDerivedInfo) type.getDataTypeExtendedInfo(); |
... | @@ -367,5 +617,12 @@ public class Decimal64ListenerTest { | ... | @@ -367,5 +617,12 @@ public class Decimal64ListenerTest { |
367 | YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) type; | 617 | YangType<YangDecimal64> decimal64Type = (YangType<YangDecimal64>) type; |
368 | YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo(); | 618 | YangDecimal64 decimal64 = decimal64Type.getDataTypeExtendedInfo(); |
369 | assertThat(decimal64.getFractionDigit(), is(4)); | 619 | assertThat(decimal64.getFractionDigit(), is(4)); |
620 | + | ||
621 | + // Check range restriction | ||
622 | + rangeRestriction = (YangRangeRestriction) decimal64.getRangeRestrictedExtendedInfo(); | ||
623 | + rangeListIterator = rangeRestriction.getAscendingRangeIntervals().listIterator(); | ||
624 | + rangeInterval = rangeListIterator.next(); | ||
625 | + assertThat(((YangDecimal64) rangeInterval.getStartValue()).getValue().doubleValue(), is(1.0)); | ||
626 | + assertThat(((YangDecimal64) rangeInterval.getEndValue()).getValue().doubleValue(), is(12.0)); | ||
370 | } | 627 | } |
371 | } | 628 | } | ... | ... |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + typedef topBits { | ||
6 | + type bits { | ||
7 | + bit disable-nagle { | ||
8 | + position 0; | ||
9 | + } | ||
10 | + bit auto-sense-speed { | ||
11 | + position 1; | ||
12 | + } | ||
13 | + bit Mb-only { | ||
14 | + position 2; | ||
15 | + } | ||
16 | + } | ||
17 | + } | ||
18 | + | ||
19 | + leaf myBits { | ||
20 | + type topBits; | ||
21 | + } | ||
22 | +} |
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + | ||
6 | + typedef topDecimal { | ||
7 | + type decimal64 { | ||
8 | + fraction-digits 4; | ||
9 | + range 4..11; | ||
10 | + } | ||
11 | + } | ||
12 | + | ||
13 | + typedef midDecimal { | ||
14 | + type topDecimal; | ||
15 | + } | ||
16 | + | ||
17 | + leaf lowerDecimal { | ||
18 | + type midDecimal { | ||
19 | + range 1..12; | ||
20 | + } | ||
21 | + } | ||
22 | +} |
utils/yangutils/plugin/src/test/resources/decimal64/Decimal64MultiTypedefMultiRangeStatement.yang
0 → 100644
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + | ||
6 | + typedef topDecimal { | ||
7 | + type decimal64 { | ||
8 | + fraction-digits 4; | ||
9 | + range 1..12; | ||
10 | + } | ||
11 | + } | ||
12 | + | ||
13 | + typedef midDecimal { | ||
14 | + type topDecimal; | ||
15 | + } | ||
16 | + | ||
17 | + leaf lowerDecimal { | ||
18 | + type midDecimal { | ||
19 | + range 4..11; | ||
20 | + } | ||
21 | + } | ||
22 | +} |
utils/yangutils/plugin/src/test/resources/decimal64/Decimal64MultiTypedefRangeInLeafStatement.yang
0 → 100644
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + | ||
6 | + typedef topDecimal { | ||
7 | + type decimal64 { | ||
8 | + fraction-digits 4; | ||
9 | + } | ||
10 | + } | ||
11 | + | ||
12 | + typedef midDecimal { | ||
13 | + type topDecimal; | ||
14 | + } | ||
15 | + | ||
16 | + leaf lowerDecimal { | ||
17 | + type midDecimal { | ||
18 | + range 1..12; | ||
19 | + } | ||
20 | + } | ||
21 | +} |
utils/yangutils/plugin/src/test/resources/decimal64/Decimal64MultiTypedefRangeStatement.yang
0 → 100644
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + | ||
6 | + typedef topDecimal { | ||
7 | + type decimal64 { | ||
8 | + fraction-digits 4; | ||
9 | + range 1..12; | ||
10 | + } | ||
11 | + } | ||
12 | + | ||
13 | + typedef midDecimal { | ||
14 | + type topDecimal; | ||
15 | + } | ||
16 | + | ||
17 | + leaf lowerDecimal { | ||
18 | + type midDecimal; | ||
19 | + } | ||
20 | +} |
... | @@ -9,11 +9,11 @@ module Test { | ... | @@ -9,11 +9,11 @@ module Test { |
9 | } | 9 | } |
10 | } | 10 | } |
11 | 11 | ||
12 | - typedef validDecimal { | 12 | + typedef midDecimal { |
13 | type topDecimal; | 13 | type topDecimal; |
14 | } | 14 | } |
15 | 15 | ||
16 | - leaf setFourDecimal { | 16 | + leaf lowerDecimal { |
17 | - type validDecimal; | 17 | + type midDecimal; |
18 | } | 18 | } |
19 | } | 19 | } | ... | ... |
utils/yangutils/plugin/src/test/resources/decimal64/Decimal64MultiTypedefWithMaxRange.yang
0 → 100644
1 | +module Test { | ||
2 | + yang-version 1; | ||
3 | + namespace http://huawei.com; | ||
4 | + prefix Ant; | ||
5 | + | ||
6 | + typedef topDecimal { | ||
7 | + type decimal64 { | ||
8 | + fraction-digits 4; | ||
9 | + range 1..12; | ||
10 | + } | ||
11 | + } | ||
12 | + | ||
13 | + typedef midDecimal { | ||
14 | + type topDecimal; | ||
15 | + } | ||
16 | + | ||
17 | + leaf lowerDecimal { | ||
18 | + type midDecimal { | ||
19 | + range 4..max; | ||
20 | + } | ||
21 | + } | ||
22 | +} |
... | @@ -1723,7 +1723,6 @@ | ... | @@ -1723,7 +1723,6 @@ |
1723 | uses tet:te-link-state-derived; | 1723 | uses tet:te-link-state-derived; |
1724 | } | 1724 | } |
1725 | 1725 | ||
1726 | - | ||
1727 | augment "/te-link-event/te-link-attributes/underlay" { | 1726 | augment "/te-link-event/te-link-attributes/underlay" { |
1728 | description "Add state attributes to te-link underlay."; | 1727 | description "Add state attributes to te-link underlay."; |
1729 | uses te-link-state-underlay-attributes; | 1728 | uses te-link-state-underlay-attributes; | ... | ... |
-
Please register or login to post a comment