janani b
Committed by Gerrit Code Review

[ONOS-4352]Defect fix for unsupported types.

Change-Id: I5c1425518422492de8e108c54ea82f0c85812157
......@@ -34,12 +34,16 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
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 @@ public final class ListenerUtil {
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 @@ public final class ListenerUtil {
}
/**
* 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
......
......@@ -272,6 +272,21 @@ public final class UtilConstants {
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";
......
......@@ -350,6 +350,21 @@ public enum YangConstructType {
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 @@ public enum YangConstructType {
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:
......
......@@ -66,6 +66,6 @@ public class NotificationListenerTest {
YangLeaf leafInfo = leafIterator.next();
assertThat(leafInfo.getName(), is("if-name"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("leafref"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
}
}
......
......@@ -17,7 +17,9 @@ package org.onosproject.yangutils.parser.impl.listeners;
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 @@ import static org.hamcrest.core.Is.is;
*/
public class TypeListenerTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
......@@ -114,4 +119,46 @@ public class TypeListenerTest {
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");
}
}
......
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
grouping currentcheck {
leaf invalid-interval {
type identityref {
}
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
container currentcheck {
leaf invalid-interval {
type instance-identifier;
}
}
}
module Test {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
leaf-list invalid-interval {
type leafref;
}
}
......@@ -14,7 +14,7 @@ module rock {
type int32;
}
leaf if-name {
type leafref;
type string;
}
leaf if-admin-status {
type P:admin-status;
......