[ONOS-4352]Defect fix for unsupported types.
Change-Id: I5c1425518422492de8e108c54ea82f0c85812157
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
index de11f05..7f4e86b 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
@@ -34,12 +34,16 @@
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.CARET;
+import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR;
+import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
+import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
+import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_IDENTIFIER;
/**
* Represents an utility for listener.
@@ -263,6 +267,7 @@
String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
if (tmpData.length == 1) {
YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
+ checkForUnsupportedTypes(tmpData[0], yangConstruct, ctx);
nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx));
return nodeIdentifier;
} else if (tmpData.length == 2) {
@@ -281,6 +286,30 @@
}
/**
+ * Checks whether the type is an unsupported type.
+ *
+ * @param typeName name of the type
+ * @param yangConstruct yang construct to check if it is type
+ * @param ctx yang construct's context to get the line number and character position
+ */
+ private static void checkForUnsupportedTypes(String typeName,
+ YangConstructType yangConstruct, ParserRuleContext ctx) {
+
+ if (yangConstruct == YangConstructType.TYPE_DATA) {
+ if (typeName.equalsIgnoreCase(LEAFREF)) {
+ handleUnsupportedYangConstruct(YangConstructType.LEAFREF_DATA,
+ ctx, CURRENTLY_UNSUPPORTED);
+ } else if (typeName.equalsIgnoreCase(IDENTITYREF)) {
+ handleUnsupportedYangConstruct(YangConstructType.IDENTITYREF_DATA,
+ ctx, CURRENTLY_UNSUPPORTED);
+ } else if (typeName.equalsIgnoreCase(INSTANCE_IDENTIFIER)) {
+ handleUnsupportedYangConstruct(YangConstructType.INSTANCE_IDENTIFIER_DATA,
+ ctx, CURRENTLY_UNSUPPORTED);
+ }
+ }
+ }
+
+ /**
* Checks and return valid absolute schema node id.
*
* @param argumentString string from yang file
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 24744fa..39e5148 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -272,6 +272,21 @@
public static final String INPUT = "input";
/**
+ * Static attribute for leafref string.
+ */
+ public static final String LEAFREF = "leafref";
+
+ /**
+ * Static attribute for identityref string.
+ */
+ public static final String IDENTITYREF = "identityref";
+
+ /**
+ * Static attribute for instance identifier string.
+ */
+ public static final String INSTANCE_IDENTIFIER = "instance-identifier";
+
+ /**
* Static attribute for output variable of rpc.
*/
public static final String RPC_INPUT_VAR_NAME = "inputVar";
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/YangConstructType.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/YangConstructType.java
index 91bc61a..03c4983 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/YangConstructType.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/YangConstructType.java
@@ -350,6 +350,21 @@
REFINE_DATA,
/**
+ * Identifies the YANG leafref element parsed data.
+ */
+ LEAFREF_DATA,
+
+ /**
+ * Identifies the YANG identityref element parsed data.
+ */
+ IDENTITYREF_DATA,
+
+ /**
+ * Identifies the YANG instance identifier element parsed data.
+ */
+ INSTANCE_IDENTIFIER_DATA,
+
+ /**
* Identifies the YANG deviation element parsed data.
*/
DEVIATION_DATA,
@@ -500,6 +515,12 @@
return "unique";
case REFINE_DATA:
return "refine";
+ case LEAFREF_DATA:
+ return "leafref";
+ case IDENTITYREF_DATA:
+ return "identityref";
+ case INSTANCE_IDENTIFIER_DATA:
+ return "instance-identifier";
case DEVIATION_DATA:
return "deviation";
case ANYXML_DATA:
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java
index 3b9907e..7da2468 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListenerTest.java
@@ -66,6 +66,6 @@
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("if-name"));
- assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
}
}
diff --git a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
index 1737ea6..1b6a7c6 100644
--- a/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
+++ b/utils/yangutils/src/test/java/org/onosproject/yangutils/parser/impl/listeners/TypeListenerTest.java
@@ -17,7 +17,9 @@
import java.io.IOException;
import java.util.ListIterator;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
@@ -35,6 +37,9 @@
*/
public class TypeListenerTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
@@ -114,4 +119,46 @@
assertThat(leafListInfo.getDataType().getDataTypeName(), is("uint16"));
assertThat(leafListInfo.getDataType().getDataType(), is(YangDataTypes.UINT16));
}
+
+ /**
+ * Checks for unsupported type leafref.
+ */
+ @Test
+ public void processLeafrefType() throws IOException, ParserException {
+
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : \"leafref\" is not supported in current version,"
+ + " please check wiki for YANG utils road map.");
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/LeafrefInvalidIdentifier.yang");
+ }
+
+ /**
+ * Checks for unsupported type identityref.
+ */
+ @Test
+ public void processIdentityrefType() throws IOException, ParserException {
+
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : \"identityref\" is not supported in current version,"
+ + " please check wiki for YANG utils road map.");
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/IdentityrefInvalidIdentifier.yang");
+ }
+
+ /**
+ * Checks for unsupported type instance identifier.
+ */
+ @Test
+ public void processInstanceIdentifierType() throws IOException, ParserException {
+
+ thrown.expect(ParserException.class);
+ thrown.expectMessage("YANG file error : \"instance-identifier\" is not supported in current version,"
+ + " please check wiki for YANG utils road map.");
+
+ YangNode node = manager
+ .getDataModel("src/test/resources/InstanceIdentifierInvalidIdentifier.yang");
+ }
}
diff --git a/utils/yangutils/src/test/resources/IdentityrefInvalidIdentifier.yang b/utils/yangutils/src/test/resources/IdentityrefInvalidIdentifier.yang
new file mode 100644
index 0000000..99a8129
--- /dev/null
+++ b/utils/yangutils/src/test/resources/IdentityrefInvalidIdentifier.yang
@@ -0,0 +1,11 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ grouping currentcheck {
+ leaf invalid-interval {
+ type identityref {
+ }
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/InstanceIdentifierInvalidIdentifier.yang b/utils/yangutils/src/test/resources/InstanceIdentifierInvalidIdentifier.yang
new file mode 100644
index 0000000..0bbe2f1
--- /dev/null
+++ b/utils/yangutils/src/test/resources/InstanceIdentifierInvalidIdentifier.yang
@@ -0,0 +1,10 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ container currentcheck {
+ leaf invalid-interval {
+ type instance-identifier;
+ }
+ }
+}
diff --git a/utils/yangutils/src/test/resources/LeafrefInvalidIdentifier.yang b/utils/yangutils/src/test/resources/LeafrefInvalidIdentifier.yang
new file mode 100644
index 0000000..4737b6c
--- /dev/null
+++ b/utils/yangutils/src/test/resources/LeafrefInvalidIdentifier.yang
@@ -0,0 +1,8 @@
+module Test {
+ yang-version 1;
+ namespace http://huawei.com;
+ prefix Ant;
+ leaf-list invalid-interval {
+ type leafref;
+ }
+}
diff --git a/utils/yangutils/src/test/resources/ValidNotificationStatement.yang b/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
index 7e6bc17..1e0f144 100644
--- a/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
+++ b/utils/yangutils/src/test/resources/ValidNotificationStatement.yang
@@ -14,7 +14,7 @@
type int32;
}
leaf if-name {
- type leafref;
+ type string;
}
leaf if-admin-status {
type P:admin-status;