Committed by
Gerrit Code Review
[ONOS-4352]Defect fix for unsupported types.
Change-Id: I5c1425518422492de8e108c54ea82f0c85812157
Showing
9 changed files
with
143 additions
and
2 deletions
... | @@ -34,12 +34,16 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE; | ... | @@ -34,12 +34,16 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE; |
34 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; | 34 | import static org.onosproject.yangutils.utils.UtilConstants.SLASH; |
35 | import static org.onosproject.yangutils.utils.UtilConstants.COLON; | 35 | import static org.onosproject.yangutils.utils.UtilConstants.COLON; |
36 | import static org.onosproject.yangutils.utils.UtilConstants.CARET; | 36 | import static org.onosproject.yangutils.utils.UtilConstants.CARET; |
37 | +import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED; | ||
37 | import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; | 38 | import static org.onosproject.yangutils.utils.UtilConstants.QUOTES; |
38 | import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN; | 39 | import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN; |
39 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; | 40 | import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING; |
40 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; | 41 | import static org.onosproject.yangutils.utils.UtilConstants.TRUE; |
41 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; | 42 | import static org.onosproject.yangutils.utils.UtilConstants.FALSE; |
42 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR; | 43 | import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR; |
44 | +import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF; | ||
45 | +import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF; | ||
46 | +import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_IDENTIFIER; | ||
43 | 47 | ||
44 | /** | 48 | /** |
45 | * Represents an utility for listener. | 49 | * Represents an utility for listener. |
... | @@ -263,6 +267,7 @@ public final class ListenerUtil { | ... | @@ -263,6 +267,7 @@ public final class ListenerUtil { |
263 | String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); | 267 | String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON)); |
264 | if (tmpData.length == 1) { | 268 | if (tmpData.length == 1) { |
265 | YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier(); | 269 | YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier(); |
270 | + checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx); | ||
266 | nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx)); | 271 | nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx)); |
267 | return nodeIdentifier; | 272 | return nodeIdentifier; |
268 | } else if (tmpData.length == 2) { | 273 | } else if (tmpData.length == 2) { |
... | @@ -281,6 +286,30 @@ public final class ListenerUtil { | ... | @@ -281,6 +286,30 @@ public final class ListenerUtil { |
281 | } | 286 | } |
282 | 287 | ||
283 | /** | 288 | /** |
289 | + * Checks whether the type is an unsupported type. | ||
290 | + * | ||
291 | + * @param typeName name of the type | ||
292 | + * @param yangConstruct yang construct to check if it is type | ||
293 | + * @param ctx yang construct's context to get the line number and character position | ||
294 | + */ | ||
295 | + private static void checkForUnsupportedTypes(String typeName, | ||
296 | + YangConstructType yangConstruct, ParserRuleContext ctx) { | ||
297 | + | ||
298 | + if (yangConstruct == YangConstructType.TYPE_DATA) { | ||
299 | + if (typeName.equalsIgnoreCase(LEAFREF)) { | ||
300 | + handleUnsupportedYangConstruct(YangConstructType.LEAFREF_DATA, | ||
301 | + ctx, CURRENTLY_UNSUPPORTED); | ||
302 | + } else if (typeName.equalsIgnoreCase(IDENTITYREF)) { | ||
303 | + handleUnsupportedYangConstruct(YangConstructType.IDENTITYREF_DATA, | ||
304 | + ctx, CURRENTLY_UNSUPPORTED); | ||
305 | + } else if (typeName.equalsIgnoreCase(INSTANCE_IDENTIFIER)) { | ||
306 | + handleUnsupportedYangConstruct(YangConstructType.INSTANCE_IDENTIFIER_DATA, | ||
307 | + ctx, CURRENTLY_UNSUPPORTED); | ||
308 | + } | ||
309 | + } | ||
310 | + } | ||
311 | + | ||
312 | + /** | ||
284 | * Checks and return valid absolute schema node id. | 313 | * Checks and return valid absolute schema node id. |
285 | * | 314 | * |
286 | * @param argumentString string from yang file | 315 | * @param argumentString string from yang file | ... | ... |
... | @@ -272,6 +272,21 @@ public final class UtilConstants { | ... | @@ -272,6 +272,21 @@ public final class UtilConstants { |
272 | public static final String INPUT = "input"; | 272 | public static final String INPUT = "input"; |
273 | 273 | ||
274 | /** | 274 | /** |
275 | + * Static attribute for leafref string. | ||
276 | + */ | ||
277 | + public static final String LEAFREF = "leafref"; | ||
278 | + | ||
279 | + /** | ||
280 | + * Static attribute for identityref string. | ||
281 | + */ | ||
282 | + public static final String IDENTITYREF = "identityref"; | ||
283 | + | ||
284 | + /** | ||
285 | + * Static attribute for instance identifier string. | ||
286 | + */ | ||
287 | + public static final String INSTANCE_IDENTIFIER = "instance-identifier"; | ||
288 | + | ||
289 | + /** | ||
275 | * Static attribute for output variable of rpc. | 290 | * Static attribute for output variable of rpc. |
276 | */ | 291 | */ |
277 | public static final String RPC_INPUT_VAR_NAME = "inputVar"; | 292 | public static final String RPC_INPUT_VAR_NAME = "inputVar"; | ... | ... |
... | @@ -350,6 +350,21 @@ public enum YangConstructType { | ... | @@ -350,6 +350,21 @@ public enum YangConstructType { |
350 | REFINE_DATA, | 350 | REFINE_DATA, |
351 | 351 | ||
352 | /** | 352 | /** |
353 | + * Identifies the YANG leafref element parsed data. | ||
354 | + */ | ||
355 | + LEAFREF_DATA, | ||
356 | + | ||
357 | + /** | ||
358 | + * Identifies the YANG identityref element parsed data. | ||
359 | + */ | ||
360 | + IDENTITYREF_DATA, | ||
361 | + | ||
362 | + /** | ||
363 | + * Identifies the YANG instance identifier element parsed data. | ||
364 | + */ | ||
365 | + INSTANCE_IDENTIFIER_DATA, | ||
366 | + | ||
367 | + /** | ||
353 | * Identifies the YANG deviation element parsed data. | 368 | * Identifies the YANG deviation element parsed data. |
354 | */ | 369 | */ |
355 | DEVIATION_DATA, | 370 | DEVIATION_DATA, |
... | @@ -500,6 +515,12 @@ public enum YangConstructType { | ... | @@ -500,6 +515,12 @@ public enum YangConstructType { |
500 | return "unique"; | 515 | return "unique"; |
501 | case REFINE_DATA: | 516 | case REFINE_DATA: |
502 | return "refine"; | 517 | return "refine"; |
518 | + case LEAFREF_DATA: | ||
519 | + return "leafref"; | ||
520 | + case IDENTITYREF_DATA: | ||
521 | + return "identityref"; | ||
522 | + case INSTANCE_IDENTIFIER_DATA: | ||
523 | + return "instance-identifier"; | ||
503 | case DEVIATION_DATA: | 524 | case DEVIATION_DATA: |
504 | return "deviation"; | 525 | return "deviation"; |
505 | case ANYXML_DATA: | 526 | case ANYXML_DATA: | ... | ... |
... | @@ -66,6 +66,6 @@ public class NotificationListenerTest { | ... | @@ -66,6 +66,6 @@ public class NotificationListenerTest { |
66 | YangLeaf leafInfo = leafIterator.next(); | 66 | YangLeaf leafInfo = leafIterator.next(); |
67 | 67 | ||
68 | assertThat(leafInfo.getName(), is("if-name")); | 68 | assertThat(leafInfo.getName(), is("if-name")); |
69 | - assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref")); | 69 | + assertThat(leafInfo.getDataType().getDataTypeName(), is("string")); |
70 | } | 70 | } |
71 | } | 71 | } | ... | ... |
... | @@ -17,7 +17,9 @@ package org.onosproject.yangutils.parser.impl.listeners; | ... | @@ -17,7 +17,9 @@ package org.onosproject.yangutils.parser.impl.listeners; |
17 | 17 | ||
18 | import java.io.IOException; | 18 | import java.io.IOException; |
19 | import java.util.ListIterator; | 19 | import java.util.ListIterator; |
20 | +import org.junit.Rule; | ||
20 | import org.junit.Test; | 21 | import org.junit.Test; |
22 | +import org.junit.rules.ExpectedException; | ||
21 | import org.onosproject.yangutils.datamodel.YangDataTypes; | 23 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
22 | import org.onosproject.yangutils.datamodel.YangLeaf; | 24 | import org.onosproject.yangutils.datamodel.YangLeaf; |
23 | import org.onosproject.yangutils.datamodel.YangLeafList; | 25 | import org.onosproject.yangutils.datamodel.YangLeafList; |
... | @@ -35,6 +37,9 @@ import static org.hamcrest.core.Is.is; | ... | @@ -35,6 +37,9 @@ import static org.hamcrest.core.Is.is; |
35 | */ | 37 | */ |
36 | public class TypeListenerTest { | 38 | public class TypeListenerTest { |
37 | 39 | ||
40 | + @Rule | ||
41 | + public ExpectedException thrown = ExpectedException.none(); | ||
42 | + | ||
38 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); | 43 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
39 | 44 | ||
40 | /** | 45 | /** |
... | @@ -114,4 +119,46 @@ public class TypeListenerTest { | ... | @@ -114,4 +119,46 @@ public class TypeListenerTest { |
114 | assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16")); | 119 | assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16")); |
115 | assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); | 120 | assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); |
116 | } | 121 | } |
122 | + | ||
123 | + /** | ||
124 | + * Checks for unsupported type leafref. | ||
125 | + */ | ||
126 | + @Test | ||
127 | + public void processLeafrefType() throws IOException, ParserException { | ||
128 | + | ||
129 | + thrown.expect(ParserException.class); | ||
130 | + thrown.expectMessage("YANG file error : \"leafref\" is not supported in current version," | ||
131 | + + " please check wiki for YANG utils road map."); | ||
132 | + | ||
133 | + YangNode node = manager | ||
134 | + .getDataModel("src/test/resources/LeafrefInvalidIdentifier.yang"); | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * Checks for unsupported type identityref. | ||
139 | + */ | ||
140 | + @Test | ||
141 | + public void processIdentityrefType() throws IOException, ParserException { | ||
142 | + | ||
143 | + thrown.expect(ParserException.class); | ||
144 | + thrown.expectMessage("YANG file error : \"identityref\" is not supported in current version," | ||
145 | + + " please check wiki for YANG utils road map."); | ||
146 | + | ||
147 | + YangNode node = manager | ||
148 | + .getDataModel("src/test/resources/IdentityrefInvalidIdentifier.yang"); | ||
149 | + } | ||
150 | + | ||
151 | + /** | ||
152 | + * Checks for unsupported type instance identifier. | ||
153 | + */ | ||
154 | + @Test | ||
155 | + public void processInstanceIdentifierType() throws IOException, ParserException { | ||
156 | + | ||
157 | + thrown.expect(ParserException.class); | ||
158 | + thrown.expectMessage("YANG file error : \"instance-identifier\" is not supported in current version," | ||
159 | + + " please check wiki for YANG utils road map."); | ||
160 | + | ||
161 | + YangNode node = manager | ||
162 | + .getDataModel("src/test/resources/InstanceIdentifierInvalidIdentifier.yang"); | ||
163 | + } | ||
117 | } | 164 | } | ... | ... |
-
Please register or login to post a comment