YAB and YOB defect fix
Change-Id: Ifed54236cfa83b4754383467818581bec59191d9
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yab/YangApplicationBroker.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yab/YangApplicationBroker.java
index cb6f7d7..aa76750 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/yab/YangApplicationBroker.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yab/YangApplicationBroker.java
@@ -44,6 +44,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.yms.app.utils.TraversalType.CHILD;
@@ -67,6 +68,7 @@
private static final String AUGMENTED = "Augmented";
private static final String VOID = "void";
private final YangSchemaRegistry schemaRegistry;
+ private Set<String> augGenMethodSet;
/**
* Creates a new YANG application broker.
@@ -88,11 +90,14 @@
throws YabException {
List<Object> responseObjects = new LinkedList<>();
YangRequestWorkBench workBench = (YangRequestWorkBench) ydtWorkBench;
+ augGenMethodSet = ((YangRequestWorkBench) ydtWorkBench).getAugGenMethodSet();
for (YdtAppContext appContext = workBench.getAppRootNode().getFirstChild();
appContext != null; appContext = appContext.getNextSibling()) {
Object responseObject = processQueryOfApplication(appContext);
- responseObjects.add(responseObject);
+ if (responseObject != null) {
+ responseObjects.add(responseObject);
+ }
}
YdtContext rootYdtContext = workBench.getRootNode();
@@ -116,7 +121,7 @@
public YdtResponse processEdit(YdtBuilder ydtWorkBench)
throws CloneNotSupportedException, YabException {
YangRequestWorkBench workBench = (YangRequestWorkBench) ydtWorkBench;
-
+ augGenMethodSet = ((YangRequestWorkBench) ydtWorkBench).getAugGenMethodSet();
for (YdtAppContext appContext = workBench.getAppRootNode().getFirstChild();
appContext != null; appContext = appContext.getNextSibling()) {
processEditOfApplication(appContext);
@@ -229,10 +234,13 @@
String methodName = getApplicationMethodName(appContext,
appName, GET);
+ String moduleName = appContext.getAppData()
+ .getRootSchemaNode().getName();
+
// invoke application's getter method
outputObject = invokeApplicationsMethod(appManagerObject,
outputObject,
- methodName);
+ methodName, moduleName);
}
/*
@@ -293,9 +301,12 @@
String methodName = getApplicationMethodName(appContext,
appName, SET);
+ String moduleName = appContext.getAppData()
+ .getRootSchemaNode().getName();
+
// invoke application's setter method
invokeApplicationsMethod(appManagerObject, outputObject,
- methodName);
+ methodName, moduleName);
}
/*
@@ -366,8 +377,12 @@
String methodName = getApplicationMethodName(appContext,
appName, SET);
+ String moduleName = appContext.getAppData().getRootSchemaNode()
+ .getName();
+
// invoke application's setter method
- invokeApplicationsMethod(appManagerObject, inputObject, methodName);
+ invokeApplicationsMethod(appManagerObject, inputObject,
+ methodName, moduleName);
if (appContext.getPreviousSibling() != null) {
curTraversal = SIBLING;
@@ -614,7 +629,8 @@
.getAugmentedInfoList()) {
Object appManagerObject = schemaRegistry
.getRegisteredApplication(yangAugment.getParent());
- if (appManagerObject != null) {
+ if (appManagerObject != null
+ && augGenMethodSet.add(yangAugment.getSetterMethodName())) {
childAppContext = addChildToYdtAppTree(curAppContext,
yangAugment);
processAugmentForChildNode(childAppContext, yangAugment);
@@ -788,7 +804,8 @@
*/
private Object invokeApplicationsMethod(Object appManagerObject,
Object inputObject,
- String methodName) throws YabException {
+ String methodName, String appName)
+ throws YabException {
checkNotNull(appManagerObject);
Class<?> appClass = appManagerObject.getClass();
try {
@@ -798,9 +815,11 @@
return methodObject.invoke(appManagerObject, inputObject);
}
throw new YabException("No such method in application");
- } catch (IllegalAccessException | NoSuchMethodException |
- InvocationTargetException e) {
+ } catch (IllegalAccessException | NoSuchMethodException e) {
throw new YabException(e);
+ } catch (InvocationTargetException e) {
+ throw new YabException("Invocation exception in service " + appName,
+ e.getCause());
}
}
@@ -869,4 +888,13 @@
throw new YabException(e);
}
}
+
+ /**
+ * Sets the augment setter method name.
+ *
+ * @param augGenMethodSet augment setter method name
+ */
+ public void setAugGenMethodSet(Set<String> augGenMethodSet) {
+ this.augGenMethodSet = augGenMethodSet;
+ }
}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobBuilderOrBuiltObject.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobBuilderOrBuiltObject.java
index 6df0724..03af131 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobBuilderOrBuiltObject.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobBuilderOrBuiltObject.java
@@ -20,6 +20,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.onosproject.yms.app.yob.YobConstants.E_BUILDER_IS_NOT_ALREADY_SET;
import static org.onosproject.yms.app.yob.YobConstants.E_BUILDER_IS_NOT_SET;
import static org.onosproject.yms.app.yob.YobConstants.E_BUILT_OBJ_IS_NOT_SET;
import static org.onosproject.yms.app.yob.YobConstants.E_FAIL_TO_CREATE_OBJ;
@@ -27,6 +28,7 @@
import static org.onosproject.yms.app.yob.YobConstants.E_OBJ_BUILDING_WITHOUT_BUILDER;
import static org.onosproject.yms.app.yob.YobConstants.E_OBJ_IS_ALREADY_BUILT_NOT_BUILD;
import static org.onosproject.yms.app.yob.YobConstants.E_OBJ_IS_ALREADY_BUILT_NOT_FETCH;
+import static org.onosproject.yms.app.yob.YobConstants.E_OBJ_IS_ALREADY_BUILT_NOT_SET;
import static org.onosproject.yms.app.yob.YobConstants.E_OBJ_IS_NOT_SET_NOT_FETCH;
import static org.onosproject.yms.app.yob.YobConstants.E_REFLECTION_FAIL_TO_CREATE_OBJ;
import static org.onosproject.yms.app.yob.YobConstants.L_FAIL_TO_CREATE_OBJ;
@@ -73,7 +75,7 @@
yangDefaultClass =
registeredAppClassLoader.loadClass(qualifiedClassName);
yangBuilderClass = yangDefaultClass.getDeclaredClasses()[0];
- builderOrBuiltObject = yangBuilderClass.newInstance();
+ setBuilderObject(yangBuilderClass.newInstance());
} catch (ClassNotFoundException e) {
log.error(L_FAIL_TO_LOAD_CLASS, qualifiedClassName);
throw new YobException(E_FAIL_TO_LOAD_CLASS + qualifiedClassName);
@@ -91,8 +93,7 @@
* Returns the builder object if it is set.
*
* @return builder object
- * @throws YobException if builder object is not available or if it is
- * already built
+ * @throws YobException if builder is not available
*/
Object getBuilderObject() {
if (isBuilt) {
@@ -107,6 +108,25 @@
}
/**
+ * Check if the builder object is being initialized for the first time and
+ * set it.
+ *
+ * @param builderObject new builder object
+ * @throws YobException if built object is not available
+ */
+ private void setBuilderObject(Object builderObject) {
+ if (isBuilt) {
+ throw new YobException(E_OBJ_IS_ALREADY_BUILT_NOT_SET);
+ }
+
+ if (builderOrBuiltObject != null) {
+ throw new YobException(E_BUILDER_IS_NOT_ALREADY_SET);
+ }
+
+ builderOrBuiltObject = builderObject;
+ }
+
+ /**
* Returns the built object.
*
* @return built object
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobConstants.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobConstants.java
index 6ed14267..cf2638e 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobConstants.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobConstants.java
@@ -30,12 +30,16 @@
static final String DEFAULT = "Default";
static final String ADD_TO = "addTo";
static final String VALUE_OF = "valueOf";
- static final String OPERATION_TYPE = "onosYangNodeOperationType";
- static final String OP_TYPE = "OnosYangNodeOperationType";
+ static final String OP_TYPE = "OpType";
+ static final String ONOS_YANG_OP_TYPE = "OnosYangOpType";
static final String OF = "of";
static final String PERIOD = ".";
static final String SPACE = " ";
static final String ADD_AUGMENT_METHOD = "addYangAugmentedInfo";
+ static final String YANG = "yang";
+ static final String JAVA_LANG = "java.lang";
+ static final String LEAF_IDENTIFIER = "LeafIdentifier";
+ static final String SELECT_LEAF = "selectLeaf";
//Error strings
static final String E_NO_HANDLE_FOR_YDT = "No handler for YDT node";
@@ -78,6 +82,10 @@
"Builder is not yet set, cannot fetch it";
static final String E_BUILT_OBJ_IS_NOT_SET =
"Built object is not set";
+ static final String E_OBJ_IS_ALREADY_BUILT_NOT_SET =
+ "Object is already built, cannot set builder";
+ static final String E_BUILDER_IS_NOT_ALREADY_SET =
+ "Builder is not already set";
static final String E_OBJ_IS_NOT_SET_NOT_FETCH =
"Builder is not yet set, cannot fetch it";
static final String E_OBJ_IS_ALREADY_BUILT_NOT_BUILD =
@@ -88,4 +96,6 @@
"YANG data tree is missing the data required for YOB";
static final String E_INVALID_DATA_TREE =
"YANG tree does not have a application root";
+ static final String E_INVALID_EMPTY_DATA =
+ "Value for empty data type is invalid";
}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobHandler.java
index abb6248..28527ea 100755
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobHandler.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobHandler.java
@@ -47,6 +47,9 @@
YangSchemaRegistry registry) {
String setterName = null;
YangSchemaNode node = curNode.getYangSchemaNode();
+ while (node.getReferredSchema() != null) {
+ node = node.getReferredSchema();
+ }
String qualName = getQualifiedDefaultClass(node);
ClassLoader classLoader = YobUtils.getClassLoader(registry, qualName,
@@ -56,7 +59,7 @@
setterName = node.getJavaAttributeName();
}
- Object workBench = new YobWorkBench(node, classLoader, qualName,
+ Object workBench = new YobWorkBench(curNode.getYangSchemaNode(), classLoader, qualName,
setterName);
curNode.addAppInfo(YOB, workBench);
@@ -71,8 +74,9 @@
*/
public void setInParent(YdtExtendedContext ydtNode,
YangSchemaRegistry schemaRegistry) {
- YobWorkBench yobWorkBench = (YobWorkBench) ydtNode.getAppInfo(YOB);
- yobWorkBench.setObjectInParent(ydtNode);
+ YdtExtendedContext parentNode = (YdtExtendedContext) ydtNode.getParent();
+ YobWorkBench parentWorkbench = (YobWorkBench) parentNode.getAppInfo(YOB);
+ parentWorkbench.setObject(ydtNode, schemaRegistry);
}
/**
@@ -88,6 +92,6 @@
YdtExtendedContext ydtRootNode,
YangSchemaRegistry schemaRegistry) {
YobWorkBench yobWorkBench = (YobWorkBench) ydtNode.getAppInfo(YOB);
- yobWorkBench.buildObject(ydtNode);
+ yobWorkBench.buildObject(ydtNode.getYdtContextOperationType(), schemaRegistry);
}
}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobMultiInstanceLeafHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobMultiInstanceLeafHandler.java
index c59725a..6d97841 100755
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobMultiInstanceLeafHandler.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobMultiInstanceLeafHandler.java
@@ -33,6 +33,7 @@
import java.lang.reflect.ParameterizedType;
import java.util.Set;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yms.app.ydt.AppType.YOB;
import static org.onosproject.yms.app.yob.YobConstants.ADD_TO;
@@ -74,6 +75,10 @@
YangSchemaRegistry schemaRegistry) {
Class<?> parentBuilderClass = null;
YangSchemaNode yangSchemaNode = leafListNode.getYangSchemaNode();
+ while (yangSchemaNode.getReferredSchema() != null) {
+ yangSchemaNode = yangSchemaNode.getReferredSchema();
+ }
+
YdtExtendedContext parentYdtNode =
(YdtExtendedContext) leafListNode.getParent();
YobWorkBench parentYobWorkBench =
@@ -90,17 +95,25 @@
.getDeclaredField(setterInParent);
ParameterizedType genericListType =
(ParameterizedType) leafName.getGenericType();
- Class<?> genericListClass =
- (Class<?>) genericListType.getActualTypeArguments()[0];
- Method setterMethod =
- parentBuilderClass.getDeclaredMethod(
- ADD_TO + getCapitalCase(setterInParent),
- genericListClass);
+ Class<?> genericListClass;
+ if (((YangLeafList) leafListNode.getYangSchemaNode())
+ .getDataType().getDataType() == IDENTITYREF) {
+ ParameterizedType type = (ParameterizedType)
+ genericListType.getActualTypeArguments()[0];
+ genericListClass = type.getClass().getClass();
+ } else {
+ genericListClass = (Class<?>) genericListType.getActualTypeArguments()[0];
+ }
+
+ Method setterMethod = parentBuilderClass.getDeclaredMethod(
+ ADD_TO + getCapitalCase(setterInParent), genericListClass);
+
JavaQualifiedTypeInfoContainer javaQualifiedType =
(JavaQualifiedTypeInfoContainer) yangSchemaNode;
YangType<?> yangType =
((YangLeafList) javaQualifiedType).getDataType();
- YobUtils.setDataFromStringValue(yangType, value, setterMethod,
+ YobUtils.setDataFromStringValue(yangType.getDataType(), value,
+ setterMethod,
builderObject, leafListNode);
} catch (NoSuchMethodException | InvocationTargetException
| IllegalAccessException | NoSuchFieldException e) {
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobSingleInstanceLeafHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobSingleInstanceLeafHandler.java
index 6840684..4d8736b 100755
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobSingleInstanceLeafHandler.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobSingleInstanceLeafHandler.java
@@ -19,6 +19,7 @@
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangSchemaNode;
import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yms.app.ydt.YdtExtendedContext;
import org.onosproject.yms.app.yob.exception.YobException;
import org.onosproject.yms.app.ysr.YangSchemaRegistry;
@@ -69,6 +70,10 @@
try {
YangSchemaNode schemaNode = leafNode.getYangSchemaNode();
+ while (schemaNode.getReferredSchema() != null) {
+ schemaNode = schemaNode.getReferredSchema();
+ }
+
String setterInParent = schemaNode.getJavaAttributeName();
YdtExtendedContext parentNode =
(YdtExtendedContext) leafNode.getParent();
@@ -76,13 +81,20 @@
Object builderObject = workBench
.getParentBuilder(leafNode, schemaRegistry);
builderClass = builderObject.getClass();
- Field leafName = builderClass.getDeclaredField(setterInParent);
- Method setterMethod = builderClass
- .getDeclaredMethod(setterInParent, leafName.getType());
- YangType<?> yangType = ((YangLeaf) schemaNode).getDataType();
- YobUtils.setDataFromStringValue(yangType, leafNode.getValue(),
- setterMethod, builderObject,
- leafNode);
+ if (leafNode.getValue() != null || ((YangLeaf) schemaNode)
+ .getDataType().getDataType() == YangDataTypes.EMPTY) {
+ Field leafName = builderClass.getDeclaredField(setterInParent);
+ Method setterMethod = builderClass
+ .getDeclaredMethod(setterInParent, leafName.getType());
+ YangType<?> yangType = ((YangLeaf) schemaNode).getDataType();
+ YobUtils.setDataFromStringValue(yangType.getDataType(), leafNode
+ .getValue(),
+ setterMethod, builderObject,
+ leafNode);
+ } else {
+ YobUtils.setSelectLeaf(builderClass, leafNode,
+ schemaRegistry, builderObject);
+ }
} catch (NoSuchMethodException | InvocationTargetException |
IllegalAccessException | NoSuchFieldException e) {
log.error(L_FAIL_TO_INVOKE_METHOD, builderClass.getName());
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobUtils.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobUtils.java
index c8256c9..c4cbfc5 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobUtils.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobUtils.java
@@ -17,14 +17,17 @@
package org.onosproject.yms.app.yob;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangBit;
-import org.onosproject.yangutils.datamodel.YangBits;
+import org.onosproject.yangutils.datamodel.YangDerivedInfo;
+import org.onosproject.yangutils.datamodel.YangIdentity;
+import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSchemaNode;
import org.onosproject.yangutils.datamodel.YangSchemaNodeContextInfo;
import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yms.app.ydt.YdtExtendedContext;
import org.onosproject.yms.app.yob.exception.YobException;
import org.onosproject.yms.app.ysr.YangSchemaRegistry;
@@ -37,22 +40,23 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Base64;
-import java.util.BitSet;
-import java.util.Map;
import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_AUGMENT_NODE;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yms.app.ydt.AppType.YOB;
import static org.onosproject.yms.app.yob.YobConstants.DEFAULT;
import static org.onosproject.yms.app.yob.YobConstants.E_DATA_TYPE_NOT_SUPPORT;
+import static org.onosproject.yms.app.yob.YobConstants.E_FAIL_TO_LOAD_CLASS;
import static org.onosproject.yms.app.yob.YobConstants.E_FAIL_TO_LOAD_CONSTRUCTOR;
import static org.onosproject.yms.app.yob.YobConstants.E_INVALID_DATA_TREE;
+import static org.onosproject.yms.app.yob.YobConstants.E_INVALID_EMPTY_DATA;
import static org.onosproject.yms.app.yob.YobConstants.FROM_STRING;
+import static org.onosproject.yms.app.yob.YobConstants.LEAF_IDENTIFIER;
import static org.onosproject.yms.app.yob.YobConstants.L_FAIL_TO_LOAD_CLASS;
import static org.onosproject.yms.app.yob.YobConstants.OF;
import static org.onosproject.yms.app.yob.YobConstants.OP_PARAM;
import static org.onosproject.yms.app.yob.YobConstants.PERIOD;
-import static org.onosproject.yms.app.yob.YobConstants.SPACE;
+import static org.onosproject.yms.app.yob.YobConstants.SELECT_LEAF;
+import static org.onosproject.yms.app.yob.YobConstants.VALUE_OF;
/**
* Utils to support object creation.
@@ -82,13 +86,13 @@
* @throws IllegalAccessException if member cannot be accessed
* @throws NoSuchMethodException if method is not found
*/
- static void setDataFromStringValue(YangType<?> type, String leafValue,
+ static void setDataFromStringValue(YangDataTypes type, String leafValue,
Method parentSetterMethod,
Object parentBuilderObject,
YdtExtendedContext ydtExtendedContext)
throws InvocationTargetException, IllegalAccessException,
NoSuchMethodException {
- switch (type.getDataType()) {
+ switch (type) {
case INT8:
parentSetterMethod.invoke(parentBuilderObject,
Byte.parseByte(leafValue));
@@ -118,6 +122,13 @@
break;
case EMPTY:
+ if (leafValue == null || leafValue.equals("")) {
+ parentSetterMethod.invoke(parentBuilderObject, true);
+ } else {
+ log.info(E_INVALID_EMPTY_DATA);
+ }
+ break;
+
case BOOLEAN:
parentSetterMethod.invoke(parentBuilderObject,
Boolean.parseBoolean(leafValue));
@@ -133,10 +144,8 @@
break;
case BITS:
- YangBits yangBits = (YangBits) type.getDataTypeExtendedInfo();
- parentSetterMethod.invoke(parentBuilderObject,
- getBitSetValueFromString(yangBits,
- leafValue));
+ parseBitSetTypeInfo(ydtExtendedContext, parentSetterMethod,
+ parentBuilderObject, leafValue);
break;
case DECIMAL64:
@@ -149,6 +158,11 @@
parentBuilderObject, leafValue, false);
break;
+ case IDENTITYREF:
+ parseIdentityRefInfo(ydtExtendedContext, parentSetterMethod,
+ parentBuilderObject, leafValue);
+ break;
+
case UNION:
parseDerivedTypeInfo(ydtExtendedContext, parentSetterMethod,
parentBuilderObject, leafValue, false);
@@ -170,20 +184,72 @@
}
/**
+ * Sets the select leaf flag for leaf.
+ *
+ * @param builderClass builder in which the select leaf flag needs to be
+ * set
+ * @param leafNode YANG data tree leaf node
+ * @param schemaRegistry YANG schema registry
+ * @param builderObject the parent build object on which to invoke
+ * the method
+ * @throws InvocationTargetException if method could not be invoked
+ * @throws IllegalAccessException if method could not be accessed
+ * @throws NoSuchMethodException if method does not exist
+ */
+ static void setSelectLeaf(Class builderClass,
+ YdtExtendedContext leafNode,
+ YangSchemaRegistry schemaRegistry,
+ Object builderObject) throws NoSuchMethodException,
+ InvocationTargetException, IllegalAccessException {
+
+ YangSchemaNode parentSchema = ((YdtExtendedContext) leafNode
+ .getParent()).getYangSchemaNode();
+ while (parentSchema.getReferredSchema() != null) {
+ parentSchema = parentSchema.getReferredSchema();
+ }
+
+ while (((YangNode) parentSchema).getParent() != null) {
+ parentSchema = ((YangNode) parentSchema).getParent();
+ }
+
+ String qualName = getQualifiedinterface(parentSchema);
+ Class<?> regClass = schemaRegistry.getRegisteredClass(parentSchema);
+ if (regClass == null) {
+ throw new YobException(E_FAIL_TO_LOAD_CLASS + qualName);
+ }
+
+ Class<?> interfaceClass = null;
+ try {
+ interfaceClass = regClass.getClassLoader().loadClass(qualName);
+ } catch (ClassNotFoundException e) {
+ log.info(E_FAIL_TO_LOAD_CLASS, qualName);
+ }
+
+ Class<?>[] innerClasses = interfaceClass.getClasses();
+ for (Class<?> innerEnumClass : innerClasses) {
+ if (innerEnumClass.getSimpleName().equals(LEAF_IDENTIFIER)) {
+ Method valueOfMethod = innerEnumClass
+ .getDeclaredMethod(VALUE_OF, String.class);
+ String leafName = leafNode.getYangSchemaNode()
+ .getJavaAttributeName().toUpperCase();
+ Object obj = valueOfMethod.invoke(null, leafName);
+ Method selectLeafMethod = builderClass
+ .getDeclaredMethod(SELECT_LEAF, innerEnumClass);
+ selectLeafMethod.invoke(builderObject, obj);
+ break;
+ }
+ }
+ }
+
+ /**
* To set data into parent setter method from string value for derived type.
*
- * @param leafValue leafValue argument is used to set the value
- * in method
- * @param parentSetterMethod Invokes the underlying method represented
- * by this parentSetterMethod
- * @param parentBuilderObject the parentBuilderObject is to invoke the
- * underlying method
- * @param ydtExtendedContext ydtExtendedContext is used to get
- * application related
- * information maintained in YDT
- * @param isEnum isEnum parameter is used to check whether
- * type is enum or derived
- * information maintained in YDT
+ * @param leafValue value to be set in method
+ * @param parentSetterMethod the parent setter method to be invoked
+ * @param parentBuilderObject the parent build object on which to invoke the
+ * method
+ * @param ydtExtendedContext application context
+ * @param isEnum flag to check whether type is enum or derived
* @throws InvocationTargetException if failed to invoke method
* @throws IllegalAccessException if member cannot be accessed
* @throws NoSuchMethodException if the required method is not found
@@ -201,6 +267,10 @@
Method childMethod = null;
YangSchemaNode yangJavaModule = ydtExtendedContext.getYangSchemaNode();
+ while (yangJavaModule.getReferredSchema() != null) {
+ yangJavaModule = yangJavaModule.getReferredSchema();
+ }
+
String qualifiedClassName = yangJavaModule.getJavaPackage() + PERIOD +
getCapitalCase(yangJavaModule.getJavaClassNameOrBuiltInType());
ClassLoader classLoader = getClassLoader(null, qualifiedClassName,
@@ -210,8 +280,8 @@
} catch (ClassNotFoundException e) {
log.error(L_FAIL_TO_LOAD_CLASS, qualifiedClassName);
}
- if (!isEnum) {
+ if (!isEnum) {
if (childSetClass != null) {
childConstructor = childSetClass.getDeclaredConstructor();
}
@@ -219,6 +289,7 @@
if (childConstructor != null) {
childConstructor.setAccessible(true);
}
+
try {
if (childConstructor != null) {
childObject = childConstructor.newInstance();
@@ -234,8 +305,59 @@
if (childSetClass != null) {
childMethod = childSetClass.getDeclaredMethod(OF, String.class);
}
- //leafValue = JavaIdentifierSyntax.getEnumJavaAttribute(leafValue);
- //leafValue = leafValue.toUpperCase();
+ }
+ if (childMethod != null) {
+ childValue = childMethod.invoke(childObject, leafValue);
+ }
+
+ parentSetterMethod.invoke(parentBuilderObject, childValue);
+ }
+
+ /**
+ * To set data into parent setter method from string value for bits type.
+ *
+ * @param leafValue value to be set in method
+ * @param parentSetterMethod the parent setter method to be invoked
+ * @param parentBuilderObject the parent build object on which to invoke the
+ * method
+ * @param ydtExtendedContext application context
+ * @throws InvocationTargetException if failed to invoke method
+ * @throws IllegalAccessException if member cannot be accessed
+ * @throws NoSuchMethodException if the required method is not found
+ */
+ private static void parseBitSetTypeInfo(YdtExtendedContext ydtExtendedContext,
+ Method parentSetterMethod,
+ Object parentBuilderObject,
+ String leafValue)
+ throws InvocationTargetException, IllegalAccessException,
+ NoSuchMethodException {
+ Class<?> childSetClass = null;
+ Object childValue = null;
+ Object childObject = null;
+ Method childMethod = null;
+
+ YangSchemaNode schemaNode = ydtExtendedContext.getYangSchemaNode();
+ while (schemaNode.getReferredSchema() != null) {
+ schemaNode = schemaNode.getReferredSchema();
+ }
+
+ YangSchemaNode parentSchema = ((YdtExtendedContext) ydtExtendedContext
+ .getParent()).getYangSchemaNode();
+ String qualifiedClassName = parentSchema.getJavaPackage() + PERIOD +
+ parentSchema.getJavaAttributeName().toLowerCase() +
+ PERIOD + getCapitalCase(schemaNode.getJavaAttributeName());
+
+ ClassLoader classLoader = getClassLoader(null, qualifiedClassName,
+ ydtExtendedContext, null);
+
+ try {
+ childSetClass = classLoader.loadClass(qualifiedClassName);
+ } catch (ClassNotFoundException e) {
+ log.error(L_FAIL_TO_LOAD_CLASS, qualifiedClassName);
+ }
+
+ if (childSetClass != null) {
+ childMethod = childSetClass.getDeclaredMethod(FROM_STRING, String.class);
}
if (childMethod != null) {
childValue = childMethod.invoke(childObject, leafValue);
@@ -262,12 +384,42 @@
String leafValue)
throws InvocationTargetException, IllegalAccessException,
NoSuchMethodException {
+
YangSchemaNode schemaNode = ydtExtendedContext.getYangSchemaNode();
- YangLeafRef leafRef = (YangLeafRef) ((YangLeaf) schemaNode)
- .getDataType().getDataTypeExtendedInfo();
- YobUtils.setDataFromStringValue(leafRef.getEffectiveDataType(),
- leafValue, parentSetterMethod,
- parentBuilderObject, ydtExtendedContext);
+ while (schemaNode.getReferredSchema() != null) {
+ schemaNode = schemaNode.getReferredSchema();
+ }
+
+ YangLeafRef leafRef;
+ if (schemaNode instanceof YangLeaf) {
+ leafRef = (YangLeafRef) ((YangLeaf) schemaNode)
+ .getDataType().getDataTypeExtendedInfo();
+ } else {
+ leafRef = (YangLeafRef) ((YangLeafList) schemaNode)
+ .getDataType().getDataTypeExtendedInfo();
+ }
+
+ YangType type = leafRef.getEffectiveDataType();
+ if (type.getDataType() == YangDataTypes.DERIVED &&
+ schemaNode.getJavaPackage().equals(YobConstants.JAVA_LANG)) {
+ /*
+ * If leaf is inside grouping, then its return type will be of type
+ * Object and if its actual type is derived type then get the
+ * effective built-in type and set the value.
+ */
+ YangDerivedInfo derivedInfo = (YangDerivedInfo) leafRef
+ .getEffectiveDataType()
+ .getDataTypeExtendedInfo();
+ YobUtils.setDataFromStringValue(derivedInfo.getEffectiveBuiltInType(),
+ leafValue, parentSetterMethod,
+ parentBuilderObject,
+ ydtExtendedContext);
+ } else {
+ YobUtils.setDataFromStringValue(type.getDataType(),
+ leafValue, parentSetterMethod,
+ parentBuilderObject,
+ ydtExtendedContext);
+ }
}
/**
@@ -278,12 +430,12 @@
* @param curNode YDT context
* @param rootNode application root node
* @return current class loader
- * @throws YobException if the YDT is an invalid tree
*/
static ClassLoader getClassLoader(YangSchemaRegistry registry,
String qualifiedClassName,
YdtExtendedContext curNode,
YdtExtendedContext rootNode) {
+
if (rootNode != null && curNode == rootNode) {
YangSchemaNode curSchemaNode = curNode.getYangSchemaNode();
while (!(curSchemaNode instanceof RpcNotificationContainer)) {
@@ -292,21 +444,16 @@
throw new YobException(E_INVALID_DATA_TREE);
}
curSchemaNode = curNode.getYangSchemaNode();
-
}
- Class<?> regClass = registry.getRegisteredClass(curSchemaNode
- );
+ Class<?> regClass = registry.getRegisteredClass(curSchemaNode);
return regClass.getClassLoader();
-
}
- YdtExtendedContext parent =
- (YdtExtendedContext) curNode.getParent();
- YobWorkBench parentBuilderContainer =
- (YobWorkBench) parent.getAppInfo(YOB);
- Object parentObj =
- parentBuilderContainer.getParentBuilder(curNode, registry);
+ YdtExtendedContext parent = (YdtExtendedContext) curNode.getParent();
+ YobWorkBench parentBuilderContainer = (YobWorkBench) parent.getAppInfo(YOB);
+ Object parentObj = parentBuilderContainer.getParentBuilder(curNode,
+ registry);
return parentObj.getClass().getClassLoader();
}
@@ -318,24 +465,58 @@
* @param registry schema registry
* @return class loader to be used for the switched context schema node
*/
- static ClassLoader getTargetClassLoader(
- ClassLoader curLoader,
- YangSchemaNodeContextInfo context,
- YangSchemaRegistry registry) {
+ static ClassLoader getTargetClassLoader(ClassLoader curLoader,
+ YangSchemaNodeContextInfo context,
+ YangSchemaRegistry registry) {
YangSchemaNode augmentSchemaNode = context.getContextSwitchedNode();
if (augmentSchemaNode.getYangSchemaNodeType() == YANG_AUGMENT_NODE) {
- YangSchemaNode moduleNode =
- ((YangNode) augmentSchemaNode).getParent();
+ YangSchemaNode moduleNode = ((YangNode) augmentSchemaNode).getParent();
- Class<?> moduleClass = registry.getRegisteredClass(
- moduleNode);
+ Class<?> moduleClass = registry.getRegisteredClass(moduleNode);
+ if (moduleClass == null) {
+ throw new YobException(E_FAIL_TO_LOAD_CLASS + moduleNode
+ .getJavaClassNameOrBuiltInType());
+ }
return moduleClass.getClassLoader();
}
-
return curLoader;
}
/**
+ * Returns the schema node's module interface.
+ *
+ * @param schemaNode YANG schema node
+ * @param schemaRegistry YANG schema registry
+ * @return schema node's module interface
+ */
+ public static Class<?> getModuleInterface(YangSchemaNode schemaNode,
+ YangSchemaRegistry schemaRegistry) {
+
+ YangNode yangNode = (YangNode) schemaNode;
+ while (yangNode.getReferredSchema() != null) {
+ yangNode = (YangNode) yangNode.getReferredSchema();
+ }
+
+ while (yangNode.getParent() != null) {
+ yangNode = yangNode.getParent();
+ }
+
+ String qualName = getQualifiedinterface(yangNode);
+ Class<?> regClass = schemaRegistry.getRegisteredClass(yangNode);
+ if (regClass == null) {
+ throw new YobException(E_FAIL_TO_LOAD_CLASS + qualName);
+ }
+
+ try {
+ return regClass.getClassLoader().loadClass(qualName);
+ } catch (ClassNotFoundException e) {
+ log.error(L_FAIL_TO_LOAD_CLASS, qualName);
+ }
+
+ return null;
+ }
+
+ /**
* Returns the qualified default / op param class.
*
* @param schemaNode schema node of the required class
@@ -368,26 +549,86 @@
}
/**
- * Returns BitSet value from string.
+ * Returns the capital cased first letter of the given string.
*
- * @param yangBits schema node of the YANG bits
- * @param leafValue leaf value from RESTCONF
- * @return BitSet value
+ * @param name string to be capital cased
+ * @return capital cased string
*/
- private static BitSet getBitSetValueFromString(YangBits yangBits,
- String leafValue) {
- String[] bitNames = leafValue.trim().split(SPACE);
- Map<String, YangBit> bitNameMap = yangBits.getBitNameMap();
- BitSet bitDataSet = new BitSet();
- YangBit bit;
- for (String bitName : bitNames) {
- bit = bitNameMap.get(bitName);
- if (bit == null) {
- throw new YobException("Unable to find corresponding bit" +
- " position for bit : " + bitName);
- }
- bitDataSet.set(bit.getPosition());
+ public static String getCapitalCase(String name) {
+ // TODO: It will be removed if common util is committed.
+ return name.substring(0, 1).toUpperCase() +
+ name.substring(1);
+ }
+
+ /**
+ * To set data into parent setter method from string value for identity ref.
+ *
+ * @param leafValue leaf value to be set
+ * @param parentSetterMethod the parent setter method to be invoked
+ * @param parentBuilderObject the parent build object on which to invoke
+ * the method
+ * @param ydtExtendedContext application context
+ * @throws InvocationTargetException if method could not be invoked
+ * @throws IllegalAccessException if method could not be accessed
+ * @throws NoSuchMethodException if method does not exist
+ */
+ private static void parseIdentityRefInfo(YdtExtendedContext
+ ydtExtendedContext,
+ Method parentSetterMethod,
+ Object parentBuilderObject,
+ String leafValue)
+ throws InvocationTargetException, IllegalAccessException,
+ NoSuchMethodException {
+ Class<?> childSetClass = null;
+ Object childValue = null;
+ Method childMethod = null;
+
+ YangSchemaNode yangJavaModule = ydtExtendedContext.getYangSchemaNode();
+ while (yangJavaModule.getReferredSchema() != null) {
+ yangJavaModule = yangJavaModule.getReferredSchema();
}
- return bitDataSet;
+
+ String qualifiedClassName = null;
+ YangType type;
+ if (yangJavaModule instanceof YangLeaf) {
+ type = ((YangLeaf) yangJavaModule).getDataType();
+ } else {
+ type = ((YangLeafList) yangJavaModule).getDataType();
+ }
+
+ if (type.getDataType() == YangDataTypes.LEAFREF && yangJavaModule
+ .getJavaPackage().equals(YobConstants.JAVA_LANG)) {
+ YangLeafRef leafref = ((YangLeafRef) type.getDataTypeExtendedInfo());
+ YangType effectiveType = leafref.getEffectiveDataType();
+ if (effectiveType.getDataType() == YangDataTypes.IDENTITYREF) {
+ YangIdentityRef identityref = ((YangIdentityRef) effectiveType
+ .getDataTypeExtendedInfo());
+ YangIdentity identity = identityref.getReferredIdentity();
+ qualifiedClassName = identity.getJavaPackage() + PERIOD +
+ getCapitalCase(identity.getJavaClassNameOrBuiltInType());
+ }
+ } else {
+ qualifiedClassName = yangJavaModule.getJavaPackage() + PERIOD +
+ getCapitalCase(yangJavaModule.getJavaClassNameOrBuiltInType());
+ }
+
+ ClassLoader classLoader = getClassLoader(null, qualifiedClassName,
+ ydtExtendedContext, null);
+ try {
+ childSetClass = classLoader.loadClass(qualifiedClassName);
+ } catch (ClassNotFoundException e) {
+ log.error(L_FAIL_TO_LOAD_CLASS, qualifiedClassName);
+ }
+
+ if (childSetClass != null) {
+ childMethod = childSetClass
+ .getDeclaredMethod(FROM_STRING, String.class);
+ }
+
+ if (childMethod != null) {
+ childValue = childMethod.invoke(null, leafValue);
+ }
+
+ parentSetterMethod.invoke(parentBuilderObject, childValue);
}
}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobWorkBench.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobWorkBench.java
index 29031ff..37d22ad 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobWorkBench.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobWorkBench.java
@@ -23,6 +23,7 @@
import org.onosproject.yms.app.ydt.YdtExtendedContext;
import org.onosproject.yms.app.yob.exception.YobException;
import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.onosproject.yms.ydt.YdtContextOperationType;
import org.onosproject.yms.ydt.YdtType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,7 +37,6 @@
import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_AUGMENT_NODE;
import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_CHOICE_NODE;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yms.app.ydt.AppType.YOB;
import static org.onosproject.yms.app.yob.YobConstants.ADD_AUGMENT_METHOD;
import static org.onosproject.yms.app.yob.YobConstants.ADD_TO;
@@ -47,15 +47,18 @@
import static org.onosproject.yms.app.yob.YobConstants.E_FAIL_TO_INVOKE_METHOD;
import static org.onosproject.yms.app.yob.YobConstants.E_FAIL_TO_LOAD_CLASS;
import static org.onosproject.yms.app.yob.YobConstants.E_HAS_NO_CHILD;
-import static org.onosproject.yms.app.yob.YobConstants.E_NO_HANDLE_FOR_YDT;
import static org.onosproject.yms.app.yob.YobConstants.E_SET_OP_TYPE_FAIL;
import static org.onosproject.yms.app.yob.YobConstants.L_FAIL_TO_BUILD;
import static org.onosproject.yms.app.yob.YobConstants.L_FAIL_TO_GET_FIELD;
import static org.onosproject.yms.app.yob.YobConstants.L_FAIL_TO_GET_METHOD;
import static org.onosproject.yms.app.yob.YobConstants.L_FAIL_TO_INVOKE_METHOD;
-import static org.onosproject.yms.app.yob.YobConstants.OPERATION_TYPE;
+import static org.onosproject.yms.app.yob.YobConstants.ONOS_YANG_OP_TYPE;
import static org.onosproject.yms.app.yob.YobConstants.OP_TYPE;
import static org.onosproject.yms.app.yob.YobConstants.VALUE_OF;
+import static org.onosproject.yms.app.yob.YobConstants.YANG;
+import static org.onosproject.yms.app.yob.YobUtils.getCapitalCase;
+import static org.onosproject.yms.app.yob.YobUtils.getModuleInterface;
+import static org.onosproject.yms.app.yob.YobUtils.getQualifiedDefaultClass;
import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_NODE;
import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_NODE;
@@ -113,228 +116,12 @@
}
/**
- * Returns the builder object or the built object corresponding to the
- * current schema node.
- *
- * @return builder or built object
- */
- YobBuilderOrBuiltObject getBuilderOrBuiltObject() {
- return builderOrBuiltObject;
- }
-
- /**
- * Returns the parent builder object in which the child object can be set.
- *
- * @param node child YDT node
- * @param registry schema registry
- * @return parent builder object
- * @throws YobException if schema node does not have child
- */
- Object getParentBuilder(YdtExtendedContext node,
- YangSchemaRegistry registry) {
-
- // Descendant schema node for whom the builder is required.
- YangSchemaNodeIdentifier targetNode =
- node.getYangSchemaNode().getYangSchemaNodeIdentifier();
-
- //Current builder container
- YobWorkBench curWorkBench = this;
-
- YangSchemaNode nonSchemaHolder;
- do {
-
- //Current Schema node context
- YangSchemaNodeContextInfo schemaContext;
- try {
- //Find the new schema context node.
- schemaContext = curWorkBench.yangSchemaNode.getChildSchema(
- targetNode);
-
- } catch (DataModelException e) {
- throw new YobException(yangSchemaNode.getName() +
- E_HAS_NO_CHILD +
- targetNode.getName());
- }
-
- nonSchemaHolder = schemaContext.getContextSwitchedNode();
-
- //If the descendant schema node is in switched context
- if (nonSchemaHolder != null) {
-
- YangSchemaNodeIdentifier nonSchemaIdentifier =
- nonSchemaHolder.getYangSchemaNodeIdentifier();
-
- //check if the descendant builder container is already available
- YobWorkBench childWorkBench =
- curWorkBench.attributeMap.get(nonSchemaIdentifier);
-
- if (childWorkBench == null) {
- YobWorkBench newWorkBench = getNewChildWorkBench(
- schemaContext, targetNode, curWorkBench, registry);
-
- curWorkBench.attributeMap.put(nonSchemaIdentifier,
- newWorkBench);
- curWorkBench = newWorkBench;
- } else {
- curWorkBench = childWorkBench;
- }
- }
-
- } while (nonSchemaHolder != null);
-
- return curWorkBench.builderOrBuiltObject.getBuilderObject();
- }
-
- /**
- * Set the operation type attribute and build the object from the builder
- * object, by invoking the build method.
- *
- * @param ydtNode data tree node
- * @throws YobException if member method is not found or failed to build
- */
- void buildObject(YdtExtendedContext ydtNode) {
-
- buildNonSchemaAttributes(ydtNode);
-
- Object builderObject = builderOrBuiltObject.getBuilderObject();
- Class<?> defaultBuilderClass = builderOrBuiltObject.yangBuilderClass;
-
- //set the operation type
- setOperationType(ydtNode);
-
- // Invoking the build method to get built object from build method.
- try {
- Method method = defaultBuilderClass.getDeclaredMethod(BUILD);
- if (method == null) {
- log.error(L_FAIL_TO_GET_METHOD, defaultBuilderClass.getName());
- throw new YobException(E_FAIL_TO_GET_METHOD +
- defaultBuilderClass.getName());
- }
- Object builtObject = method.invoke(builderObject);
- // The built object will be maintained in ydt context and same will
- // be used while setting into parent method.
- builderOrBuiltObject.setBuiltObject(builtObject);
-
- } catch (NoSuchMethodException | InvocationTargetException |
- IllegalAccessException e) {
- log.error(L_FAIL_TO_BUILD, defaultBuilderClass.getName());
- throw new YobException(E_FAIL_TO_BUILD +
- defaultBuilderClass.getName());
- }
- }
-
- /**
- * Set the operation type in the built object from the YDT node.
- * <p>
- * It needs to be invoked only for the workbench corresponding to the
- * schema YDT nodes, non schema node without the YDT node should not
- * invoke this, as it is not applicable to it.
- *
- * @param ydtNode schema data tree node
- * @throws YobException if fail to set the operation type
- */
- private void setOperationType(YdtExtendedContext ydtNode) {
-
- Object builderObject = builderOrBuiltObject.getBuilderObject();
- Class<?> defaultBuilderClass = builderOrBuiltObject.yangBuilderClass;
-
- // Setting the value into YANG node operation type from ydtContext
- // operation type.
- try {
- Class<?> interfaceClass = builderOrBuiltObject.yangDefaultClass;
- Object operationType;
- Class<?>[] innerClasses = interfaceClass.getClasses();
- for (Class<?> innerEnumClass : innerClasses) {
- if (innerEnumClass.getSimpleName().equals(OP_TYPE)) {
- Method valueOfMethod = innerEnumClass
- .getDeclaredMethod(VALUE_OF, String.class);
- if (ydtNode.getYdtContextOperationType() != null) {
- operationType = valueOfMethod.invoke(null, ydtNode
- .getYdtContextOperationType().toString());
- Field operationTypeField = defaultBuilderClass
- .getDeclaredField(OPERATION_TYPE);
- operationTypeField.setAccessible(true);
- operationTypeField.set(builderObject, operationType);
- break;
- }
- }
- }
- } catch (NoSuchFieldException | NoSuchMethodException |
- InvocationTargetException | IllegalAccessException e) {
- log.error(E_SET_OP_TYPE_FAIL);
- throw new YobException(E_SET_OP_TYPE_FAIL);
- }
- }
-
- /**
- * build the non schema objects and maintain it in the contained schema
- * node.
- *
- * @param ydtNode contained schema node
- */
- private void buildNonSchemaAttributes(YdtExtendedContext ydtNode) {
- for (Map.Entry<YangSchemaNodeIdentifier, YobWorkBench> entry :
- attributeMap.entrySet()) {
- YobWorkBench childWorkBench = entry.getValue();
- childWorkBench.buildObject(ydtNode);
-
- if (childWorkBench.yangSchemaNode.getYangSchemaNodeType() ==
- YANG_AUGMENT_NODE) {
- addInAugmentation(builderOrBuiltObject.getBuilderObject(),
- childWorkBench.setterInParent,
- childWorkBench.getBuilderOrBuiltObject()
- .getBuiltObject());
- return;
- }
-
- setObjectInBuilder(
- builderOrBuiltObject.getBuilderObject(),
- childWorkBench.setterInParent,
- SINGLE_INSTANCE_NODE,
- childWorkBench.getBuilderOrBuiltObject().getBuiltObject());
- }
- }
-
-
- //TODO add objectIn Augmentation
-
- /**
- * Sets the YANG built object in corresponding parent class method.
- *
- * @param ydtNode ydtExtendedContext is used to get application
- * related information maintained in YDT
- * @throws YobException if there is no parent's YOB handler
- */
- void setObjectInParent(YdtExtendedContext ydtNode) {
- YdtExtendedContext parentNode =
- (YdtExtendedContext) ydtNode.getParent();
- if (parentNode == null || parentNode.getAppInfo(YOB) == null) {
- throw new YobException(E_NO_HANDLE_FOR_YDT);
- }
- YobWorkBench parentWorkBench =
- (YobWorkBench) parentNode.getAppInfo(YOB);
- Object parentBuilderObject =
- parentWorkBench.builderOrBuiltObject.getBuilderObject();
- YdtType nodeType = ydtNode.getYdtType();
- Object objectToSetInParent = builderOrBuiltObject.getBuiltObject();
-
- // set the object in the parent builder
- setObjectInBuilder(parentBuilderObject, setterInParent, nodeType,
- objectToSetInParent);
-
- ydtNode.addAppInfo(YOB, this);
- }
-
- /**
* Set the attribute in a builder object.
*
- * @param builder builder object in which the attribute needs to be
- * set
+ * @param builder builder object in which the attribute needs to be set
* @param setter setter method in parent
* @param nodeType type of node to set
* @param attribute attribute to set in the builder
- * @throws YobException if member is not found or failed to invoke the
- * method
*/
private static void setObjectInBuilder(Object builder, String setter,
YdtType nodeType, Object attribute) {
@@ -408,7 +195,6 @@
}
-
/**
* Creates a new builder container object corresponding to a context
* switch schema node.
@@ -420,7 +206,6 @@
* @param registry schema registry
* @return new builder container object corresponding to a context
* switch schema node
- * @throws YobException if expected child is not found in schema
*/
private static YobWorkBench getNewChildWorkBench(
YangSchemaNodeContextInfo childContext,
@@ -430,7 +215,7 @@
YangSchemaNode ctxSwitchedNode = childContext.getContextSwitchedNode();
String name;
- /*This is the first child trying to set its object in the
+ /* This is the first child trying to set its object in the
current context. */
String setterInParent = ctxSwitchedNode.getJavaAttributeName();
@@ -440,7 +225,7 @@
try {
childContext = ctxSwitchedNode.getChildSchema(targetNode);
ctxSwitchedNode = childContext.getContextSwitchedNode();
- name = YobUtils.getQualifiedDefaultClass(
+ name = getQualifiedDefaultClass(
childContext.getContextSwitchedNode());
} catch (DataModelException e) {
@@ -450,10 +235,10 @@
}
} else if (ctxSwitchedNode.getYangSchemaNodeType() ==
YANG_AUGMENT_NODE) {
- name = YobUtils.getQualifiedDefaultClass(ctxSwitchedNode);
+ name = getQualifiedDefaultClass(ctxSwitchedNode);
setterInParent = YobUtils.getQualifiedinterface(ctxSwitchedNode);
} else {
- name = YobUtils.getQualifiedDefaultClass(childContext.getSchemaNode());
+ name = getQualifiedDefaultClass(childContext.getSchemaNode());
}
ClassLoader newClassesLoader = YobUtils.getTargetClassLoader(
@@ -463,4 +248,216 @@
setterInParent);
}
+ /**
+ * Returns the builder object or the built object corresponding to the
+ * current schema node.
+ *
+ * @return builder or built object
+ */
+ YobBuilderOrBuiltObject getBuilderOrBuiltObject() {
+ return builderOrBuiltObject;
+ }
+
+ /**
+ * Returns the parent builder object in which the child object can be set.
+ *
+ * @param node child YDT node
+ * @param registry schema registry
+ * @return parent builder object
+ */
+ Object getParentBuilder(YdtExtendedContext node,
+ YangSchemaRegistry registry) {
+
+ // Descendant schema node for whom the builder is required.
+ YangSchemaNodeIdentifier targetNode =
+ node.getYangSchemaNode().getYangSchemaNodeIdentifier();
+
+ //Current builder container
+ YobWorkBench curWorkBench = this;
+
+ YangSchemaNode nonSchemaHolder;
+ do {
+
+ //Current Schema node context
+ YangSchemaNodeContextInfo schemaContext;
+ try {
+ //Find the new schema context node.
+ schemaContext = curWorkBench.yangSchemaNode
+ .getChildSchema(targetNode);
+
+ } catch (DataModelException e) {
+ throw new YobException(yangSchemaNode.getName() +
+ E_HAS_NO_CHILD +
+ targetNode.getName());
+ }
+
+ nonSchemaHolder = schemaContext.getContextSwitchedNode();
+
+ //If the descendant schema node is in switched context
+ if (nonSchemaHolder != null) {
+
+ YangSchemaNodeIdentifier nonSchemaIdentifier =
+ nonSchemaHolder.getYangSchemaNodeIdentifier();
+
+ //check if the descendant builder container is already available
+ YobWorkBench childWorkBench =
+ curWorkBench.attributeMap.get(nonSchemaIdentifier);
+
+ if (childWorkBench == null) {
+ YobWorkBench newWorkBench = getNewChildWorkBench(
+ schemaContext, targetNode, curWorkBench, registry);
+
+ curWorkBench.attributeMap.put(nonSchemaIdentifier,
+ newWorkBench);
+ curWorkBench = newWorkBench;
+ } else {
+ curWorkBench = childWorkBench;
+ }
+ }
+
+ } while (nonSchemaHolder != null);
+
+ return curWorkBench.builderOrBuiltObject.getBuilderObject();
+ }
+
+ /**
+ * Set the operation type attribute and build the object from the builder
+ * object, by invoking the build method.
+ *
+ * @param operationType data tree node
+ * @param schemaRegistry YANG schema registry
+ */
+ void buildObject(YdtContextOperationType operationType,
+ YangSchemaRegistry schemaRegistry) {
+
+ buildNonSchemaAttributes(operationType, schemaRegistry);
+
+ Object builderObject = builderOrBuiltObject.getBuilderObject();
+ Class<?> defaultBuilderClass = builderOrBuiltObject.yangBuilderClass;
+
+ //set the operation type
+ setOperationType(operationType, schemaRegistry);
+
+ // Invoking the build method to get built object from build method.
+ try {
+ Method method = defaultBuilderClass.getDeclaredMethod(BUILD);
+ if (method == null) {
+ log.error(L_FAIL_TO_GET_METHOD, defaultBuilderClass.getName());
+ throw new YobException(E_FAIL_TO_GET_METHOD +
+ defaultBuilderClass.getName());
+ }
+ Object builtObject = method.invoke(builderObject);
+ // The built object will be maintained in ydt context and same will
+ // be used while setting into parent method.
+ builderOrBuiltObject.setBuiltObject(builtObject);
+
+ } catch (NoSuchMethodException | InvocationTargetException |
+ IllegalAccessException e) {
+ log.error(L_FAIL_TO_BUILD, defaultBuilderClass.getName());
+ throw new YobException(E_FAIL_TO_BUILD +
+ defaultBuilderClass.getName());
+ }
+ }
+
+ /**
+ * Set the operation type in the built object from the YDT node.
+ * <p>
+ * It needs to be invoked only for the workbench corresponding to the
+ * schema YDT nodes, non schema node without the YDT node should not
+ * invoke this, as it is not applicable to it.
+ *
+ * @param ydtoperation schema data tree node
+ * @param schemaRegistry YANG schema registry
+ */
+ private void setOperationType(YdtContextOperationType ydtoperation,
+ YangSchemaRegistry schemaRegistry) {
+
+ if (ydtoperation == null) {
+ return;
+ }
+
+ Object builderObject = builderOrBuiltObject.getBuilderObject();
+ Class<?> defaultBuilderClass = builderOrBuiltObject.yangBuilderClass;
+ Class<?>[] intfClass = builderOrBuiltObject.yangDefaultClass
+ .getInterfaces();
+ String setterName = YANG + intfClass[0].getSimpleName() + OP_TYPE;
+
+ // Setting the value into YANG node operation type from ydtContext
+ // operation type.
+ try {
+ Class<?> interfaceClass;
+ interfaceClass = getModuleInterface(yangSchemaNode,
+ schemaRegistry);
+ Object operationType;
+ Class<?>[] innerClasses = interfaceClass.getClasses();
+ for (Class<?> innerEnumClass : innerClasses) {
+ if (innerEnumClass.getSimpleName().equals(ONOS_YANG_OP_TYPE)) {
+ Method valueOfMethod = innerEnumClass
+ .getDeclaredMethod(VALUE_OF, String.class);
+ operationType = valueOfMethod.invoke(null, ydtoperation.
+ toString());
+ Field operationTypeField = defaultBuilderClass
+ .getDeclaredField(setterName);
+ operationTypeField.setAccessible(true);
+ operationTypeField.set(builderObject, operationType);
+ break;
+ }
+ }
+ } catch (NoSuchMethodException |
+ InvocationTargetException | IllegalAccessException |
+ IllegalArgumentException e) {
+ log.error(E_SET_OP_TYPE_FAIL);
+ throw new YobException(E_SET_OP_TYPE_FAIL);
+ } catch (NoSuchFieldException e) {
+ log.error(E_SET_OP_TYPE_FAIL);
+ }
+ }
+
+ /**
+ * build the non schema objects and maintain it in the contained schema
+ * node.
+ *
+ * @param operationType contained schema node
+ * @param schemaRegistry YANG schema registry
+ */
+ private void buildNonSchemaAttributes(YdtContextOperationType operationType,
+ YangSchemaRegistry schemaRegistry) {
+ for (Map.Entry<YangSchemaNodeIdentifier, YobWorkBench> entry :
+ attributeMap.entrySet()) {
+ YobWorkBench childWorkBench = entry.getValue();
+ childWorkBench.buildObject(operationType, schemaRegistry);
+
+ if (childWorkBench.yangSchemaNode.getYangSchemaNodeType() ==
+ YANG_AUGMENT_NODE) {
+ addInAugmentation(builderOrBuiltObject.getBuilderObject(),
+ childWorkBench.setterInParent,
+ childWorkBench.getBuilderOrBuiltObject()
+ .getBuiltObject());
+ continue;
+ }
+
+ setObjectInBuilder(
+ builderOrBuiltObject.getBuilderObject(),
+ childWorkBench.setterInParent,
+ SINGLE_INSTANCE_NODE,
+ childWorkBench.getBuilderOrBuiltObject().getBuiltObject());
+ }
+ }
+
+ /**
+ * Sets the YANG built object in corresponding parent class method.
+ *
+ * @param childnode ydtExtendedContext is used to get application
+ * related information maintained in YDT
+ * @param schemaRegistry YANG schema registry
+ */
+ public void setObject(YdtExtendedContext childnode,
+ YangSchemaRegistry schemaRegistry) {
+ Object builder = getParentBuilder(childnode, schemaRegistry);
+ YobWorkBench childWorkBench = (YobWorkBench) childnode.getAppInfo(YOB);
+
+ setObjectInBuilder(builder, childWorkBench.setterInParent,
+ childnode.getYdtType(), childWorkBench
+ .builderOrBuiltObject.getBuiltObject());
+ }
}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/MockYmsManager.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/MockYmsManager.java
new file mode 100644
index 0000000..22f4fd9
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/MockYmsManager.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yab;
+
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ysr.TestYangSchemaNodeProvider;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.onosproject.yms.ych.YangCodecHandler;
+import org.onosproject.yms.ych.YangDataTreeCodec;
+import org.onosproject.yms.ych.YangProtocolEncodingFormat;
+import org.onosproject.yms.ydt.YdtBuilder;
+import org.onosproject.yms.ydt.YdtResponse;
+import org.onosproject.yms.ydt.YdtWalker;
+import org.onosproject.yms.ydt.YmsOperationType;
+import org.onosproject.yms.ymsm.YmsService;
+import org.onosproject.yms.ynh.YangNotificationService;
+import org.onosproject.yms.ysr.YangModuleIdentifier;
+import org.onosproject.yms.ysr.YangModuleLibrary;
+
+import java.util.List;
+
+/**
+ * Represents implementation of YANG application management system manager.
+ */
+public class MockYmsManager
+ implements YmsService {
+
+ YangSchemaRegistry schemaRegistry;
+ TestYangSchemaNodeProvider testYangSchemaNodeProvider =
+ new TestYangSchemaNodeProvider();
+
+ @Override
+ public YdtBuilder getYdtBuilder(String logicalRootName,
+ String rootNamespace,
+ YmsOperationType operationType) {
+ testYangSchemaNodeProvider.processSchemaRegistry(new TestManager());
+ schemaRegistry = testYangSchemaNodeProvider.getDefaultYangSchemaRegistry();
+ return new YangRequestWorkBench(logicalRootName, rootNamespace,
+ operationType, schemaRegistry, false);
+ }
+
+ @Override
+ public YdtBuilder getYdtBuilder(String logicalRootName,
+ String rootNamespace,
+ YmsOperationType operationType,
+ Object schemaRegistryForYdt) {
+ return null;
+ }
+
+ @Override
+ public YdtWalker getYdtWalker() {
+ return null;
+ }
+
+ @Override
+ public YdtResponse executeOperation(YdtBuilder operationRequest) {
+ YangApplicationBroker requestBroker =
+ new YangApplicationBroker(schemaRegistry);
+ switch (operationRequest.getYmsOperationType()) {
+ case EDIT_CONFIG_REQUEST:
+ try {
+ return requestBroker.processEdit(operationRequest);
+ } catch (CloneNotSupportedException e) {
+ }
+ break;
+ case QUERY_CONFIG_REQUEST:
+ case QUERY_REQUEST:
+ return requestBroker.processQuery(operationRequest);
+ case RPC_REQUEST:
+ return requestBroker.processOperation(operationRequest);
+ default:
+ }
+ return null;
+ }
+
+ @Override
+ public YangNotificationService getYangNotificationService() {
+ return null;
+ }
+
+ @Override
+ public void registerService(Object appManager, Class<?> yangService,
+ List<String> supportedFeatureList) {
+ }
+
+ @Override
+ public void unRegisterService(Object appManager, Class<?> yangService) {
+
+ }
+
+ @Override
+ public YangModuleLibrary getYangModuleLibrary() {
+ return null;
+ }
+
+ @Override
+ public String getYangFile(YangModuleIdentifier moduleIdentifier) {
+ return null;
+ }
+
+ @Override
+ public void registerDefaultCodec(YangDataTreeCodec defaultCodec,
+ YangProtocolEncodingFormat dataFormat) {
+ }
+
+ @Override
+ public YangCodecHandler getYangCodecHandler() {
+ return null;
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/TestManager.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/TestManager.java
new file mode 100644
index 0000000..c07a18f
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/TestManager.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yab;
+
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.Test;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.TestOpParam;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.TestService;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.Cont1;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.DefaultCont1;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse.DefaultRockTheHouseOutput;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse.RockTheHouseInput;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse.RockTheHouseOutput;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse1.RockTheHouse1Input;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse2.DefaultRockTheHouse2Output;
+import org.onosproject.yang.gen.v1.ydt.test.rev20160524.test.rockthehouse2.RockTheHouse2Output;
+
+/**
+ * Implementation of the application management service.
+ */
+public class TestManager implements TestService {
+
+ Test response;
+
+ @Override
+ public Test getTest(TestOpParam test) {
+ Cont1 cont = new DefaultCont1.Cont1Builder().leaf4("4").build();
+ Test response = new TestOpParam.TestBuilder().cont1(cont).build();
+ return response;
+ }
+
+ @Override
+ public void setTest(TestOpParam test) {
+ response = test;
+ }
+
+ @Override
+ public Test getAugmentedTestCont4(TestOpParam test) {
+ Cont1 cont = new DefaultCont1.Cont1Builder().leaf4("4").build();
+ Test response = new TestOpParam.TestBuilder().cont1(cont).build();
+ return response;
+ }
+
+ @Override
+ public void setAugmentedTestCont4(TestOpParam augmentedTestCont4) {
+ response = augmentedTestCont4;
+ }
+
+ @Override
+ public RockTheHouseOutput rockTheHouse(RockTheHouseInput inputVar) {
+ return DefaultRockTheHouseOutput.builder().hello("hello").build();
+ }
+
+
+ @Override
+ public void rockTheHouse1(RockTheHouse1Input inputVar) {
+ // TODO : to be implemented
+ }
+
+ @Override
+ public RockTheHouse2Output rockTheHouse2() {
+ return DefaultRockTheHouse2Output
+ .builder().leaf14("14").build();
+ }
+
+ @Override
+ public void rockTheHouse3() {
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/YangApplicationBrokerTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/YangApplicationBrokerTest.java
new file mode 100644
index 0000000..33a9a56
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yab/YangApplicationBrokerTest.java
@@ -0,0 +1,1080 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yab;
+
+import org.junit.Test;
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtAppContext;
+import org.onosproject.yms.app.ydt.YdtAppNodeOperationType;
+import org.onosproject.yms.app.ydt.YdtNode;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.onosproject.yms.ydt.YdtContextOperationType.DELETE;
+import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
+import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REQUEST;
+import static org.onosproject.yms.ydt.YmsOperationType.QUERY_CONFIG_REQUEST;
+import static org.onosproject.yms.ydt.YmsOperationType.RPC_REQUEST;
+
+/**
+ * Unit test case for YANG application broker.
+ */
+public class YangApplicationBrokerTest {
+
+ MockYmsManager ymsManager = new MockYmsManager();
+
+ /**
+ * Returns YANG data tree to check edit operation of container.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForEditOperationWithoutDelete() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.addChild("cont2", null, MERGE);
+ defaultYdtBuilder.addChild("cont3", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf1", null, "1");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf4", null, "4");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, MERGE);
+ defaultYdtBuilder.addChild("cont5", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf9", null, "9");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ private YangRequestWorkBench buildYdtForKeyLeavesInDeleteTree() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("list2", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "6");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf7", null, "7");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont7", null, DELETE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation of container.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForEditOperationWithDelete() {
+ String rootName = "rootNode";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.addChild("cont2", null, DELETE);
+ defaultYdtBuilder.addChild("cont3", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf1", null, "1");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf4", null, "4");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ defaultYdtBuilder.addChild("cont5", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf9", null, "9");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check edit operation of list.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForListEditOperationWithoutDelete() {
+ String rootName = "listWithoutDelete";
+ Set<String> valueSet = new LinkedHashSet<>();
+ valueSet.add("10");
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.addChild("list1", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf2", null, "2");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf3", null, "3");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf4", null, "4");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "6");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf7", null, "7");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaflist8", null, valueSet);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation of list.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForListEditOperationWithDelete() {
+ String rootName = "listWithDelete";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.addChild("list1", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf2", null, "2");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf3", null, "3");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf4", null, "4");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "6");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check query operation of container.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForQueryOperation() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ QUERY_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("cont1", null);
+ defaultYdtBuilder.addChild("cont2", null);
+ defaultYdtBuilder.addChild("cont3", null);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null);
+ defaultYdtBuilder.addChild("cont5", null);
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check query operation of list.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForListQueryOperation() {
+ String rootName = "listQuery";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ QUERY_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("cont1", null);
+ defaultYdtBuilder.addChild("list1", null);
+ defaultYdtBuilder.addLeaf("leaf2", null, "2");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null);
+ defaultYdtBuilder.addLeaf("leaf5", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "6");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation of a node.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtWithOneDeleteNode() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf10", null, "10");
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation of last node.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtWithDeleteNodeAsLastChild() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", MERGE);
+ defaultYdtBuilder.addChild("cont1", null, MERGE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null, MERGE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "10");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "10");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to with delete operation of all the nodes.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtWithAllDeleteNode() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test", DELETE);
+ defaultYdtBuilder.addChild("cont1", null, DELETE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("list2", null, DELETE);
+ defaultYdtBuilder.addLeaf("leaf5", null, "10");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addLeaf("leaf6", null, "10");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check rpc operation with only input.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForRpcWithOnlyInput() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ RPC_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("rock-the-house1", null);
+ defaultYdtBuilder.addChild("input", null);
+ defaultYdtBuilder.addLeaf("leaf13", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check rpc operation with only output.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForRpcWithOnlyOutput() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ RPC_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("rock-the-house2", null);
+ defaultYdtBuilder.addChild("output", null);
+ defaultYdtBuilder.addLeaf("leaf14", null, "14");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check rpc operation with both input and output.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForRpcWithBothInputOutput() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ RPC_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("rock-the-house", null);
+ defaultYdtBuilder.addChild("input", null);
+ defaultYdtBuilder.addLeaf("zip-code", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.addChild("output", null);
+ defaultYdtBuilder.addLeaf("hello", null, "5");
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check rpc operation.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForRpc() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ RPC_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("rock-the-house3", null);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check query operation with multiple level of
+ * augment.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForQueryWithMultipleAugment() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ QUERY_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Returns YANG data tree to check delete operation with multiple level of
+ * augment.
+ *
+ * @return YANG data tree
+ */
+ private YangRequestWorkBench buildYdtForDeleteWithMultipleAugment() {
+ String rootName = "root";
+ YangRequestWorkBench defaultYdtBuilder =
+ (YangRequestWorkBench) ymsManager.getYdtBuilder(rootName, null,
+ EDIT_CONFIG_REQUEST);
+ defaultYdtBuilder.addChild("test", "ydt.test");
+ defaultYdtBuilder.addChild("cont4", null, DELETE);
+ defaultYdtBuilder.traverseToParent();
+ defaultYdtBuilder.traverseToParent();
+ return defaultYdtBuilder;
+ }
+
+ /**
+ * Checks whether YANG data tree and delete tree is correct.
+ */
+ @Test
+ public void validateDeleteTreeOnlyOneNodeInDeleteList()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForEditOperationWithDelete();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ YdtContext cont1YdtContext;
+ YdtContext cont2YdtContext;
+ YdtContext cont3YdtContext;
+ YdtContext cont4YdtContext;
+ YdtContext deleteTree;
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ cont1YdtContext = ydtContext.getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ cont2YdtContext = cont1YdtContext.getFirstChild();
+ assertThat(cont2YdtContext.getName(), is("cont2"));
+
+ cont3YdtContext = cont2YdtContext.getFirstChild();
+ assertThat(cont3YdtContext.getName(), is("cont3"));
+
+ ydtContext = cont3YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf1"));
+ assertThat(ydtContext.getValue(), is("1"));
+
+ ydtContext = cont2YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf4"));
+ assertThat(ydtContext.getValue(), is("4"));
+
+ cont4YdtContext = cont1YdtContext.getNextSibling();
+ assertThat(cont4YdtContext.getName(), is("cont4"));
+
+ ydtContext = cont4YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont5"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf9"));
+ assertThat(ydtContext.getValue(), is("9"));
+
+ ydtContext = cont4YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ // verify whether delete ydt tree is correct
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ cont1YdtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ cont2YdtContext = cont1YdtContext.getFirstChild();
+ assertThat(cont2YdtContext.getName(), is("cont2"));
+
+ cont3YdtContext = cont2YdtContext.getFirstChild();
+ assertThat(cont3YdtContext.getName(), is("cont3"));
+
+ ydtContext = cont3YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf1"));
+ assertThat(ydtContext.getValue(), is("1"));
+
+ assertThat(cont2YdtContext.getNextSibling(), nullValue());
+
+ cont4YdtContext = cont1YdtContext.getNextSibling();
+ assertThat(cont4YdtContext.getName(), is("cont4"));
+
+ ydtContext = cont4YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont5"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf9"));
+ assertThat(ydtContext.getValue(), is("9"));
+
+ assertThat(cont4YdtContext.getNextSibling(), nullValue());
+
+ // ydtTree after removing delete nodes
+ ydtContext = appContext.getModuleContext();
+ assertThat(ydtContext.getName(), is("test"));
+
+ cont1YdtContext = ydtContext.getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ ydtContext = cont1YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf4"));
+ assertThat(ydtContext.getValue(), is("4"));
+
+ ydtContext = cont1YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+ }
+
+ /**
+ * Checks whether YANG data tree and delete tree is correct.
+ */
+ @Test
+ public void validateListDeleteTree()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForListEditOperationWithDelete();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ YdtContext cont1YdtContext;
+ YdtContext list1YdtContext;
+ YdtContext list2YdtContext;
+ YdtContext deleteTree;
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ cont1YdtContext = ydtContext.getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ list1YdtContext = cont1YdtContext.getFirstChild();
+ assertThat(list1YdtContext.getName(), is("list1"));
+
+ ydtContext = list1YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf2"));
+ assertThat(ydtContext.getValue(), is("2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf3"));
+ assertThat(ydtContext.getValue(), is("3"));
+
+ ydtContext = list1YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf4"));
+ assertThat(ydtContext.getValue(), is("4"));
+
+ list2YdtContext = cont1YdtContext.getNextSibling();
+ assertThat(list2YdtContext.getName(), is("list2"));
+
+ ydtContext = list2YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf5"));
+ assertThat(ydtContext.getValue(), is("5"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf6"));
+ assertThat(ydtContext.getValue(), is("6"));
+
+ ydtContext = list2YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ cont1YdtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ list1YdtContext = cont1YdtContext.getFirstChild();
+ assertThat(list1YdtContext.getName(), is("list1"));
+
+ ydtContext = list1YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf2"));
+ assertThat(ydtContext.getValue(), is("2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf3"));
+ assertThat(ydtContext.getValue(), is("3"));
+
+ assertThat(list1YdtContext.getNextSibling(), nullValue());
+
+ list2YdtContext = cont1YdtContext.getNextSibling();
+ assertThat(list2YdtContext.getName(), is("list2"));
+
+ ydtContext = list2YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf5"));
+ assertThat(ydtContext.getValue(), is("5"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf6"));
+ assertThat(ydtContext.getValue(), is("6"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ // verify whether ydt tree is correct
+ ydtContext = appContext.getModuleContext();
+ assertThat(ydtContext.getName(), is("test"));
+
+ cont1YdtContext = ydtContext.getFirstChild();
+ assertThat(cont1YdtContext.getName(), is("cont1"));
+
+ ydtContext = cont1YdtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf4"));
+ assertThat(ydtContext.getValue(), is("4"));
+
+ ydtContext = cont1YdtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid edit
+ * request.
+ */
+ @Test
+ public void testExecuteEditOperationWithoutDelete()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForEditOperationWithoutDelete();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid delete
+ * request.
+ */
+ @Test
+ public void testExecuteEditOperationWithDelete()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForEditOperationWithDelete();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid edit
+ * request for list.
+ */
+ @Test
+ public void testExecuteListEditOperationWithoutDelete()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForListEditOperationWithoutDelete();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid delete
+ * request for list.
+ */
+ @Test
+ public void testExecuteListEditOperationWithDelete()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForListEditOperationWithDelete();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid query
+ * request.
+ */
+ @Test
+ public void testExecuteQueryOperation()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtForQueryOperation();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid query
+ * request for list.
+ */
+ @Test
+ public void testExecuteListQueryOperation()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForListQueryOperation();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether delete tree is updated correctly.
+ */
+ @Test
+ public void testSiblingsInDeleteTree()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtWithOneDeleteNode();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ YdtContext deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ ydtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ assertThat(ydtContext.getPreviousSibling(), nullValue());
+
+ ydtContext = appContext.getModuleContext();
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf10"));
+ assertThat(ydtContext.getValue(), is("10"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ }
+
+ /**
+ * Checks last child is updated correctly after delete tree is built.
+ */
+ @Test
+ public void testLastChildInYdtTree()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtWithDeleteNodeAsLastChild();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+ assertThat(YdtAppNodeOperationType.BOTH,
+ is(appContext.getOperationType()));
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ YdtContext deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ ydtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ ydtContext = deleteTree.getFirstChild().getLastChild();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ assertThat(ydtContext.getPreviousSibling(), nullValue());
+
+ ydtContext = appContext.getModuleContext();
+
+ assertThat(ydtContext.getLastChild().getName(), is("list2"));
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ }
+
+ /**
+ * Checks YDT tree with all delete nodes.
+ */
+ @Test
+ public void testYdtTreeWithAllDeleteNodes()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtWithAllDeleteNode();
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ assertThat(YdtAppNodeOperationType.DELETE_ONLY,
+ is(appContext.getOperationType()));
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ YdtContext deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ ydtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(ydtContext.getName(), is("cont1"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont4"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ }
+
+ /**
+ * Checks whether key leaves are also available when there is delete
+ * request for list.
+ */
+ @Test
+ public void testKeyLeavesInDeleteTree() throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtForKeyLeavesInDeleteTree();
+
+ YdtAppContext appContext =
+ defaultYdtBuilder.getAppRootNode().getFirstChild();
+ YdtContext ydtContext = appContext.getModuleContext();
+ List<YdtContext> deleteNodes = appContext.getDeleteNodes();
+
+ assertThat(YdtAppNodeOperationType.BOTH, is(appContext.getOperationType()));
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf5"));
+ assertThat(ydtContext.getValue(), is("5"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf6"));
+ assertThat(ydtContext.getValue(), is("6"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf7"));
+ assertThat(ydtContext.getValue(), is("7"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont7"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ // build delete tree
+ YangApplicationBroker yab = new YangApplicationBroker(null);
+ YdtContext deleteTree = yab.buildDeleteTree(deleteNodes);
+
+ assertThat(deleteTree.getFirstChild().getName(), is("test"));
+
+ ydtContext = deleteTree.getFirstChild().getFirstChild();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext, notNullValue());
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext, notNullValue());
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("cont7"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+
+ ydtContext = appContext.getModuleContext();
+
+ // verify whether ydt tree is correct
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("list2"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("leaf5"));
+ assertThat(ydtContext.getValue(), is("5"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf6"));
+ assertThat(ydtContext.getValue(), is("6"));
+
+ ydtContext = ydtContext.getNextSibling();
+ assertThat(ydtContext.getName(), is("leaf7"));
+ assertThat(ydtContext.getValue(), is("7"));
+
+ assertThat(ydtContext.getNextSibling(), nullValue());
+ }
+
+ /**
+ * Checks YDT tree and application tree for query request with mutiple
+ * augments.
+ */
+ @Test
+ public void testApptreeForQueryWithMultipleAugment()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtForQueryWithMultipleAugment();
+ YdtAppContext appContext = defaultYdtBuilder.getAppRootNode()
+ .getFirstChild();
+ YdtContext ydtNode = appContext.getModuleContext();
+ YangNode yangNode = (YangNode) ((YdtNode) ydtNode).getYangSchemaNode();
+
+ YangApplicationBroker yab = new YangApplicationBroker(defaultYdtBuilder.
+ getYangSchemaRegistry());
+ yab.setAugGenMethodSet(defaultYdtBuilder.getAugGenMethodSet());
+ yab.processAugmentForChildNode(appContext, yangNode);
+
+ assertThat(appContext.getModuleContext().getName(), is("test"));
+
+ appContext = appContext.getFirstChild();
+
+ String augmentName = ((YangAugment) appContext
+ .getAugmentingSchemaNode()).getTargetNode().get(0)
+ .getResolvedNode().getJavaClassNameOrBuiltInType();
+ assertThat(augmentName, is("cont4"));
+
+ assertThat(appContext.getFirstChild(), nullValue());
+ assertThat(appContext.getLastChild(), nullValue());
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid query request
+ * for data resource with multiple augments.
+ */
+ @Test
+ public void testQueryWithMultipleAugment()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder = buildYdtForQueryWithMultipleAugment();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks whether YDT is updated correctly for delete with multiple augment.
+ */
+ @Test
+ public void testYdtForDeleteWithMultipleAugment()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForDeleteWithMultipleAugment();
+ YdtAppContext appContext = defaultYdtBuilder.getAppRootNode()
+ .getFirstChild();
+
+ YangApplicationBroker yab = new YangApplicationBroker(defaultYdtBuilder.
+ getYangSchemaRegistry());
+ yab.setAugGenMethodSet(defaultYdtBuilder.getAugGenMethodSet());
+ YdtContext deleteTree = yab.buildDeleteTree(appContext.getDeleteNodes());
+ yab.processAugmentedNodesForDelete(deleteTree.getFirstChild(),
+ appContext);
+
+ assertThat(appContext.getModuleContext().getName(), is("test"));
+
+ appContext = appContext.getFirstChild();
+ String augmentName = ((YangAugment) appContext
+ .getAugmentingSchemaNode()).getTargetNode().get(0)
+ .getResolvedNode().getJavaClassNameOrBuiltInType();
+ assertThat(augmentName, is("cont4"));
+
+ assertThat(appContext.getFirstChild(), nullValue());
+ assertThat(appContext.getLastChild(), nullValue());
+
+ YdtContext ydtContext = deleteTree.getFirstChild();
+ assertThat(ydtContext.getName(), is("test"));
+
+ ydtContext = ydtContext.getFirstChild();
+ assertThat(ydtContext.getName(), is("cont4"));
+ }
+
+ /**
+ * Checks whether there is no exception when there is valid delete request
+ * for data resource with multiple augments.
+ */
+ @Test
+ public void testDeleteWithMultipleAugment() {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForDeleteWithMultipleAugment();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks execute operation for rpc request with only output.
+ */
+ @Test
+ public void testRpcWithOutput()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForRpcWithOnlyOutput();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks execute operation for rpc request with only input.
+ */
+ @Test
+ public void testRpcWithInput()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForRpcWithOnlyInput();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks execute operation for rpc request with input and output.
+ */
+ @Test
+ public void testRpcWithInputOutput()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForRpcWithBothInputOutput();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+
+ /**
+ * Checks execute operation for rpc request without input and
+ * output.
+ */
+ @Test
+ public void testRpcWithoutInputOutput()
+ throws IOException, CloneNotSupportedException {
+ YangRequestWorkBench defaultYdtBuilder =
+ buildYdtForRpc();
+ ymsManager.executeOperation(defaultYdtBuilder);
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobAugmentTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobAugmentTest.java
new file mode 100644
index 0000000..da75702
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobAugmentTest.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.urn.ip.topo.rev20140101.ymsiptopology.node.AugmentedTopoNode;
+import org.onosproject.yang.gen.v1.urn.ip.topo.rev20140101.ymsiptopology.node.DefaultAugmentedTopoNode;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.YmsTopologyOpParam;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.DefaultNode;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.onosproject.yms.app.yob.YobTestUtils.NODE;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROUTER_ID;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROUTER_IP;
+import static org.onosproject.yms.app.yob.YobTestUtils.STR_LEAF_VALUE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TOPOLOGY;
+import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the non
+ * schema augmented nodes.
+ */
+public class YobAugmentTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void augmentedLeaf() throws IOException {
+
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(ROUTER_ID, "urn:ip:topo", STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull("Fail to create augmented YANG object", yangObject);
+
+ assertEquals("invalid augmented node created", YmsTopologyOpParam.class,
+ yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("failed to build augmented node", topology.node());
+ assertEquals("Single node entry is expected", 1, topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ DefaultNode node = (DefaultNode) topology.node().get(0);
+ assertNotNull("Augmented info is missing", node.yangAugmentedInfo(
+ AugmentedTopoNode.class));
+ assertEquals("Augmented class is incorrect",
+ DefaultAugmentedTopoNode.class,
+ node.yangAugmentedInfo(AugmentedTopoNode.class)
+ .getClass());
+
+ DefaultAugmentedTopoNode augmentedNode = (DefaultAugmentedTopoNode)
+ node.yangAugmentedInfo(AugmentedTopoNode.class);
+ assertThat("Augmented leaf value is incorrect",
+ augmentedNode.routerId(), is(STR_LEAF_VALUE));
+ }
+
+ @Test
+ public void augmentedLeaves() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(ROUTER_ID, "urn:ip:topo", STR_LEAF_VALUE);
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addLeaf(ROUTER_IP, "urn:ip:topo", STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull("Fail to create augmented YANG object", yangObject);
+
+ assertEquals("invalid augmented node created",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("failed to build augmented node", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ DefaultNode node = (DefaultNode) topology.node().get(0);
+ assertNotNull("Augmented info is missing", node.yangAugmentedInfo(
+ AugmentedTopoNode.class));
+ assertEquals("Augmented class is incorrect",
+ DefaultAugmentedTopoNode.class,
+ node.yangAugmentedInfo(AugmentedTopoNode.class)
+ .getClass());
+
+ DefaultAugmentedTopoNode augmentedNode = (DefaultAugmentedTopoNode)
+ node.yangAugmentedInfo(AugmentedTopoNode.class);
+ assertThat("Augmented router id is incorrect",
+ augmentedNode.routerId(), is(STR_LEAF_VALUE));
+ assertThat("Augmented router ip is incorrect",
+ augmentedNode.routerIp(), is(STR_LEAF_VALUE));
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBinaryTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBinaryTest.java
new file mode 100644
index 0000000..a749874
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBinaryTest.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.ydt.binarytest.rev20160524.BinarytestOpParam;
+import org.onosproject.yang.gen.v1.ydt.binarytest.rev20160524.binarytest.cont1.AugmentedCont1;
+import org.onosproject.yang.gen.v1.ydt.binarytest.rev20160524.binarytest.food.snack.Sportsarena;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the binary.
+ */
+public class YobBinaryTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testBinaryInLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addChild("binaryList", null);
+ ydtBuilder.addLeaf("binary", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ byte[] binaryValue = binarytestOpParam.binaryList().get(0).binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInTypedef() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addLeaf("name", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ byte[] binaryValue = binarytestOpParam.name().binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInGrouping() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addChild("cont1", "ydt.binarytest");
+ ydtBuilder.addLeaf("surname", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ byte[] binaryValue = binarytestOpParam.cont1().surname();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInAugment() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addChild("cont1", "ydt.binarytest");
+ ydtBuilder.addLeaf("lastname", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ AugmentedCont1 augmentedCont1 = (AugmentedCont1) binarytestOpParam.cont1()
+ .yangAugmentedInfo(AugmentedCont1.class);
+ byte[] binaryValue = augmentedCont1.lastname();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInCase() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addChild("food", "ydt.binarytest");
+ ydtBuilder.addLeaf("pretzel", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+ Sportsarena sportsArena = ((Sportsarena) binarytestOpParam.food()
+ .snack());
+ byte[] binaryValue = sportsArena.pretzel();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testBinaryInUnion() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("binarytest", "ydt.binarytest");
+ ydtBuilder.addLeaf("middlename", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BinarytestOpParam binarytestOpParam = ((BinarytestOpParam) yangObject);
+
+ byte[] binaryValue = binarytestOpParam.middlename().binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBitTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBitTest.java
new file mode 100644
index 0000000..41ca592
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBitTest.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.ydt.bit.rev20160524.BitOpParam;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YmsOperationType;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+
+/**
+ * Test the YANG object building for the YDT based on the bits.
+ */
+public class YobBitTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testBitsInLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("bit", "ydt.bit");
+ ydtBuilder.addChild("bitList", null);
+ ydtBuilder.addLeaf("bit", null, "disable-nagle");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addChild("bitList", null);
+ ydtBuilder.addLeaf("bit", null, "auto-sense-speed");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addChild("bitList", null);
+ ydtBuilder.addLeaf("bit", null, "ten-Mb-only");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BitOpParam bitOpParam = ((BitOpParam) yangObject);
+
+ assertThat(bitOpParam.bitList().get(0).bit().get(0), is(true));
+ assertThat(bitOpParam.bitList().get(0).bit().get(1), is(false));
+ assertThat(bitOpParam.bitList().get(1).bit().get(0), is(false));
+ assertThat(bitOpParam.bitList().get(1).bit().get(1), is(true));
+ assertThat(bitOpParam.bitList().get(2).bit().get(0), is(false));
+ assertThat(bitOpParam.bitList().get(2).bit().get(1), is(false));
+ assertThat(bitOpParam.bitList().get(2).bit().get(2), is(true));
+ assertThat(bitOpParam.bitList().get(2).bit().get(2), is(true));
+ }
+
+ @Test
+ public void testBitsInTypedef() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("bit", "ydt.bit");
+ ydtBuilder.addLeaf("name", null, "bit3");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BitOpParam bitOpParam = ((BitOpParam) yangObject);
+
+ assertThat(bitOpParam.name().bits().get(0), is(false));
+ assertThat(bitOpParam.name().bits().get(3), is(true));
+ }
+
+ @Test
+ public void testBitsQuery() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, YmsOperationType.QUERY_REQUEST,
+ utils.schemaRegistry(), true);
+ ydtBuilder.addChild("bit", "ydt.bit");
+ ydtBuilder.addChild("name", "ydt.bit");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ BitOpParam bitOpParam = ((BitOpParam) yangObject);
+ assertThat(bitOpParam.selectLeafFlags().get(1), is(true));
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBooleanTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBooleanTest.java
new file mode 100644
index 0000000..456a892
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobBooleanTest.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class YobBooleanTest {
+
+ private static final String BOOLEAN_LIST = "booleanList";
+ private static final String AUTO_PREFIX_BOOLEAN = "yangAutoPrefixBoolean";
+
+ /*
+ BOOLEAN
+ Positive scenario
+ input with in true and false
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.booleanYdt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+
+ Field field = yangObject.getClass().getDeclaredField(BOOLEAN_LIST);
+ field.setAccessible(true);
+ List booleanList = (List) field.get(yangObject);
+ Field invalidInterval = booleanList.get(0).getClass()
+ .getDeclaredField(AUTO_PREFIX_BOOLEAN);
+ invalidInterval.setAccessible(true);
+ assertTrue((boolean) invalidInterval.get(booleanList.get(0)));
+ assertFalse((boolean) invalidInterval.get(booleanList.get(1)));
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobChoiceTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobChoiceTest.java
new file mode 100644
index 0000000..03c2421
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobChoiceTest.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.YmsTopologyOpParam;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.DefaultNode;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.Node;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.Case1a;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.Case1b;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.DefaultCase1a;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.DefaultCase1b;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.case1b.choice1b.Case1Bi;
+import org.onosproject.yang.gen.v1.urn.topo.rev20140101.ymstopology.node.choice1.case1b.choice1b.DefaultCase1Bi;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.onosproject.yms.app.yob.YobTestUtils.LEAF_1A1;
+import static org.onosproject.yms.app.yob.YobTestUtils.LEAF_1A2;
+import static org.onosproject.yms.app.yob.YobTestUtils.LEAF_1BIA;
+import static org.onosproject.yms.app.yob.YobTestUtils.LEAF_1BIB;
+import static org.onosproject.yms.app.yob.YobTestUtils.NODE;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+import static org.onosproject.yms.app.yob.YobTestUtils.STR_LEAF_VALUE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TOPOLOGY;
+import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the non
+ * schema choice and case nodes.
+ */
+public class YobChoiceTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void caseInChoice() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(LEAF_1A1, null, STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull(yangObject);
+ assertEquals("YANG object created is not topology object",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("Failed to build the object", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ Node node = topology.node().get(0);
+ assertNotNull("choice1 is not set in node", node.choice1());
+ assertEquals("choice 1 type is not ", DefaultCase1a.class,
+ node.choice1().getClass());
+
+ Case1a case1a = (Case1a) node.choice1();
+ assertNotNull("leaf1a1 is not set in case", case1a.leaf1A1());
+ assertEquals("leaf1a1 type is not correct", String.class,
+ case1a.leaf1A1().getClass());
+ assertEquals("leaf1a1 value is not correct", STR_LEAF_VALUE,
+ case1a.leaf1A1());
+
+ }
+
+ @Test
+ public void caseWithMultiAttribute() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(LEAF_1A1, null, STR_LEAF_VALUE);
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addLeaf(LEAF_1A2, null, STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull(yangObject);
+ assertEquals("YANG object created is not topology object",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("Failed to build the object", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ Node node = topology.node().get(0);
+ assertNotNull("choice1 is not set in node", node.choice1());
+ assertEquals("choice 1 type is not ", DefaultCase1a.class,
+ node.choice1().getClass());
+
+ Case1a case1a = (Case1a) node.choice1();
+ assertNotNull("leaf1a1 is not set in case", case1a.leaf1A1());
+ assertEquals("leaf1a1 type is not correct", String.class,
+ case1a.leaf1A1().getClass());
+ assertEquals("leaf1a1 value is not correct", STR_LEAF_VALUE,
+ case1a.leaf1A1());
+
+ assertNotNull("leaf1a2 is not set in case", case1a.leaf1A2());
+ assertEquals("leaf1a2 type is not correct", String.class,
+ case1a.leaf1A2().getClass());
+ assertEquals("leaf1a1 value is not correct", STR_LEAF_VALUE,
+ case1a.leaf1A1());
+
+ }
+
+ @Test
+ public void recursiveChoice() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(LEAF_1BIA, null, STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull(yangObject);
+ assertEquals("YANG object created is not topology object",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("Failed to build the object", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ Node node = topology.node().get(0);
+ assertNotNull("Choice 1 is not set in Node", node.choice1());
+ assertEquals("Choice 1 is not of type DefaultCase1b",
+ DefaultCase1b.class, node.choice1().getClass());
+
+ Case1b case1b = (Case1b) node.choice1();
+ assertNotNull("Case1b does not have child choice1b ",
+ case1b.choice1b());
+ assertEquals("choice1b is not of type DefaultCase1Bi",
+ DefaultCase1Bi.class, case1b.choice1b().getClass());
+
+ Case1Bi case1Bi = (Case1Bi) case1b.choice1b();
+ assertNotNull("leaf1bia is not set", case1Bi.leaf1Bia());
+ assertEquals("leaf1bia type is not string", String.class,
+ case1Bi.leaf1Bia().getClass());
+ assertEquals("leaf1bia value is wrong", STR_LEAF_VALUE,
+ case1Bi.leaf1Bia());
+ }
+
+ @Test
+ public void recursiveChoiceWithMultipleAttribute() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+
+ ydtBuilder.addChild(TOPOLOGY, null, NONE);
+ ydtBuilder.addChild(NODE, null);
+ ydtBuilder.addLeaf(LEAF_1BIA, null, STR_LEAF_VALUE);
+ ydtBuilder.traverseToParent();
+ ydtBuilder.addLeaf(LEAF_1BIB, null, STR_LEAF_VALUE);
+
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertNotNull(yangObject);
+ assertEquals("YANG object created is not topology object",
+ YmsTopologyOpParam.class, yangObject.getClass());
+
+ YmsTopologyOpParam topology = (YmsTopologyOpParam) yangObject;
+ assertNotNull("Failed to build the object", topology.node());
+ assertEquals("Single node entry is expected", 1,
+ topology.node().size());
+ assertEquals("Node type is not DefaultNode", DefaultNode.class,
+ topology.node().get(0).getClass());
+
+ Node node = topology.node().get(0);
+ assertNotNull("Choice 1 is not set in Node", node.choice1());
+ assertEquals("Choice 1 is not of type DefaultCase1b",
+ DefaultCase1b.class,
+ node.choice1().getClass());
+
+ Case1b case1b = (Case1b) node.choice1();
+ assertNotNull("Case1b does not have child choice1b ",
+ case1b.choice1b());
+ assertEquals("choice1b is not of type DefaultCase1Bi",
+ DefaultCase1Bi.class,
+ case1b.choice1b().getClass());
+
+ Case1Bi case1Bi = (Case1Bi) case1b.choice1b();
+ assertNotNull("leaf1bia is not set", case1Bi.leaf1Bia());
+ assertEquals("leaf1bia type is not string", String.class,
+ case1Bi.leaf1Bia().getClass());
+ assertEquals("leaf1bia value is wrong", STR_LEAF_VALUE,
+ case1Bi.leaf1Bia());
+
+ assertNotNull("leaf1bib is not set", case1Bi.leaf1Bib());
+ assertEquals("leaf1bia type is not string", String.class,
+ case1Bi.leaf1Bib().getClass());
+ assertEquals("leaf1bia value is wrong", STR_LEAF_VALUE,
+ case1Bi.leaf1Bib());
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobDecimal64Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobDecimal64Test.java
new file mode 100644
index 0000000..dbc27f1
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobDecimal64Test.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobDecimal64Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for decimal64 with fraction 2
+ i. min value
+ ii. max value
+
+ input at boundary for decimal64 with minimum fraction
+ i. min value
+ ii. mid value
+ iii. max value
+
+ input at boundary for decimal64 with maximum fraction
+ i. min value
+ ii. mid value
+ iii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ input with multi interval range
+ if range is 10..40 | 50..100 for decimal64
+ i.1. input 11
+ i.2. input 10
+ i.3. input 40
+ i.4. input 50
+ i.5. input 55
+ i.6. input 100
+
+ if range is "min .. 3.14 | 10 | 20..max" for decimal64
+ i.1. input min
+ i.2. input 2.505
+ i.3. input 3.14
+ i.4. input 10
+ i.5. input 20
+ i.6. input 92233720368547757
+ i.7. input 92233720368547758.07
+
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.decimal64Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-92233720368547758.08", negInt
+ .get(yangObject).toString());
+ Field negIntWithMaxFraction = yangObject.getClass()
+ .getDeclaredField("negIntWithMaxFraction");
+ negIntWithMaxFraction.setAccessible(true);
+ assertEquals("-9.223372036854775808", negIntWithMaxFraction
+ .get(yangObject).toString());
+ Field negIntWithMinFraction = yangObject.getClass()
+ .getDeclaredField("negIntWithMinFraction");
+ negIntWithMinFraction.setAccessible(true);
+ assertEquals("-922337203685477580.8", negIntWithMinFraction
+ .get(yangObject).toString());
+ Field posInt = yangObject.getClass()
+ .getDeclaredField("posInt");
+ posInt.setAccessible(true);
+ assertEquals("92233720368547758.07", posInt
+ .get(yangObject).toString());
+ Field posIntWithMaxFraction = yangObject
+ .getClass().getDeclaredField("posIntWithMaxFraction");
+ posIntWithMaxFraction.setAccessible(true);
+ assertEquals("9.223372036854775807", posIntWithMaxFraction
+ .get(yangObject).toString());
+ Field posIntWithMinFraction = yangObject.getClass()
+ .getDeclaredField("posIntWithMinFraction");
+ posIntWithMinFraction.setAccessible(true);
+ assertEquals("922337203685477580.7", posIntWithMinFraction
+ .get(yangObject).toString());
+ Field minIntWithRange = yangObject.getClass()
+ .getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange
+ .get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange.get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEmptyTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEmptyTest.java
new file mode 100644
index 0000000..e919147
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEmptyTest.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the schema
+ * nodes with empty data type.
+ */
+public class YobEmptyTest {
+
+ /*
+ EMPTY
+ Positive scenario
+ input with in empty.
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.emptyTypeYdt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+
+ try {
+ Field field = yangObject.getClass().getDeclaredField("emptyList");
+ field.setAccessible(true);
+ List booleanList = (List) field.get(yangObject);
+ Field invalidInterval = booleanList.get(0)
+ .getClass().getDeclaredField("empty");
+ invalidInterval.setAccessible(true);
+ assertEquals(true, invalidInterval.get(booleanList.get(0)));
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEnumTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEnumTest.java
new file mode 100644
index 0000000..40ba5f1
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobEnumTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobEnumTest {
+
+/*
+ ENUM
+
+ Positive scenario
+
+ input with in enum
+ input with "ten"
+ input with "hundred"
+ input with "thousand"
+*/
+
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.enumYdt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field field = yangObject.getClass().getDeclaredField("enumList");
+ field.setAccessible(true);
+ List enumList = (List) field.get(yangObject);
+ assertEquals(false, enumList.isEmpty());
+ Field enumleaf = enumList.get(0)
+ .getClass().getDeclaredField("enumleaf");
+ enumleaf.setAccessible(true);
+ assertEquals("ten", enumleaf
+ .get(enumList.get(0)).toString().toLowerCase());
+ assertEquals("hundred", enumleaf
+ .get(enumList.get(1)).toString().toLowerCase());
+ assertEquals("thousand", enumleaf
+ .get(enumList.get(2)).toString().toLowerCase());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobGroupingUsesTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobGroupingUsesTest.java
new file mode 100644
index 0000000..547bac7
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobGroupingUsesTest.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.YmsIetfNetworkOpParam;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev20151208.ymsietfnetwork.networksstate.Network;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.YmsNetworkTopology;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ymsnetworktopology.networks.network.AugmentedNdNetwork;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ymsnetworktopology.networks.network.DefaultAugmentedNdNetwork;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev20151208.ymsnetworktopology.networks.network.augmentedndnetwork.Link;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.YmsIetfTeTopology;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.YmsIetfTeTopologyOpParam;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.TeAdminStatus;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.networks.network.link.AugmentedNtLink;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.networks.network.link.DefaultAugmentedNtLink;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.teadminstatus.TeAdminStatusEnum;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.telinkconfig.bundlestacklevel.DefaultBundle;
+import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.te.topology.rev20160317.ymsietftetopology.telinkconfig.bundlestacklevel.bundle.bundledlinks.BundledLink;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.onosproject.yms.app.yob.YobTestUtils.ADMIN_STATUS;
+import static org.onosproject.yms.app.yob.YobTestUtils.BUNDLED_LINK;
+import static org.onosproject.yms.app.yob.YobTestUtils.BUNDLED_LINKS;
+import static org.onosproject.yms.app.yob.YobTestUtils.CONFIG;
+import static org.onosproject.yms.app.yob.YobTestUtils.IETF_TE_TOPOLOGY;
+import static org.onosproject.yms.app.yob.YobTestUtils.LINK;
+import static org.onosproject.yms.app.yob.YobTestUtils.NETWORK;
+import static org.onosproject.yms.app.yob.YobTestUtils.NETWORKS;
+import static org.onosproject.yms.app.yob.YobTestUtils.NETWORKS_STATE;
+import static org.onosproject.yms.app.yob.YobTestUtils.NETWORK_REF;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+import static org.onosproject.yms.app.yob.YobTestUtils.SEQUENCE;
+import static org.onosproject.yms.app.yob.YobTestUtils.STR_LEAF_VALUE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TE_LINK_TEMPLATE;
+import static org.onosproject.yms.app.yob.YobTestUtils.TE_NODE_ATTRIBUTES;
+import static org.onosproject.yms.app.yob.YobTestUtils.TE_NODE_EVENT;
+import static org.onosproject.yms.app.yob.YobTestUtils.UP;
+import static org.onosproject.yms.app.yob.YobTestUtils.YMS_IETF_NETWORK;
+import static org.onosproject.yms.app.yob.YobTestUtils.YMS_NETWORK_TOPOLOGY;
+import static org.onosproject.yms.ydt.YdtContextOperationType.CREATE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the grouping
+ * and uses nodes.
+ */
+public class YobGroupingUsesTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testGroupingUsesLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild(YMS_IETF_NETWORK, null, CREATE);
+ ydtBuilder.addChild(NETWORKS_STATE, null);
+ ydtBuilder.addChild(NETWORK, null);
+ ydtBuilder.addLeaf(NETWORK_REF, null, STR_LEAF_VALUE);
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertThat(yangObject, is(notNullValue()));
+ YmsIetfNetworkOpParam ietfNetwork = (YmsIetfNetworkOpParam) yangObject;
+ Network network = ietfNetwork.networksState().network().iterator().next();
+ assertThat(network.networkRef(), is(STR_LEAF_VALUE));
+ }
+
+ @Test
+ public void testGroupingUsesContainer() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild(IETF_TE_TOPOLOGY, null, CREATE);
+ ydtBuilder.addChild(TE_NODE_EVENT, null);
+ ydtBuilder.addChild(TE_NODE_ATTRIBUTES, null);
+ ydtBuilder.addLeaf(ADMIN_STATUS, null, UP);
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertThat(yangObject, is(notNullValue()));
+ YmsIetfTeTopologyOpParam ietfTeTopology = (YmsIetfTeTopologyOpParam)
+ yangObject;
+ TeAdminStatus adminStatus = ietfTeTopology.teNodeEvent()
+ .teNodeAttributes()
+ .adminStatus();
+ assertThat(adminStatus.enumeration(), is(TeAdminStatusEnum.UP));
+ }
+
+ @Test
+ public void testGroupingUsesInterfile() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild(YMS_IETF_NETWORK, null, CREATE);
+ ydtBuilder.addChild(NETWORKS, null);
+ ydtBuilder.addChild(NETWORK, null);
+ ydtBuilder.addChild(LINK, YMS_NETWORK_TOPOLOGY);
+ ydtBuilder.addChild(TE, IETF_TE_TOPOLOGY);
+ ydtBuilder.addChild(CONFIG, IETF_TE_TOPOLOGY);
+ ydtBuilder.addChild(BUNDLED_LINKS, IETF_TE_TOPOLOGY);
+ ydtBuilder.addChild(BUNDLED_LINK, IETF_TE_TOPOLOGY);
+ ydtBuilder.addLeaf(SEQUENCE, null, "1");
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertThat(yangObject, is(notNullValue()));
+ YmsIetfNetworkOpParam ietfNetwork = (YmsIetfNetworkOpParam) yangObject;
+
+ org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang
+ .ietf.network.rev20151208.ymsietfnetwork
+ .networks.Network network = ietfNetwork.networks().network().get(0);
+
+ DefaultAugmentedNdNetwork augmentedNdNetworks = (DefaultAugmentedNdNetwork) network
+ .yangAugmentedInfo(AugmentedNdNetwork.class);
+ assertThat(augmentedNdNetworks.yangAugmentedNdNetworkOpType(),
+ is(YmsNetworkTopology.OnosYangOpType.CREATE));
+
+ Link link = augmentedNdNetworks.link().get(0);
+ DefaultAugmentedNtLink augmentedNtLink = (DefaultAugmentedNtLink) link
+ .yangAugmentedInfo(AugmentedNtLink.class);
+ assertThat(augmentedNtLink.yangAugmentedNtLinkOpType(),
+ is(YmsIetfTeTopology.OnosYangOpType.CREATE));
+
+ DefaultBundle bundleStackLevel = (DefaultBundle) augmentedNtLink.te()
+ .config().bundleStackLevel();
+ assertThat(bundleStackLevel.yangBundleOpType(),
+ is(YmsIetfTeTopology.OnosYangOpType.CREATE));
+
+ BundledLink bundledLink = bundleStackLevel.bundledLinks().bundledLink().get(0);
+ assertThat(bundledLink.yangBundledLinkOpType(),
+ is(YmsIetfTeTopology.OnosYangOpType.CREATE));
+ assertThat(bundledLink.sequence(), is(1L));
+ }
+
+ @Test
+ public void testGroupingUsesAugment() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild(YMS_IETF_NETWORK, null, CREATE);
+ ydtBuilder.addChild(NETWORKS, null);
+ ydtBuilder.addChild(NETWORK, null);
+ ydtBuilder.addChild(LINK, YMS_NETWORK_TOPOLOGY);
+ ydtBuilder.addChild(TE, IETF_TE_TOPOLOGY);
+ ydtBuilder.addChild(CONFIG, IETF_TE_TOPOLOGY);
+ ydtBuilder.addLeaf(TE_LINK_TEMPLATE, null, "1");
+ YdtContext logicalRoot = ydtBuilder.getRootNode();
+ YdtExtendedContext appRoot =
+ (YdtExtendedContext) logicalRoot.getFirstChild();
+
+ DefaultYobBuilder yobBuilder = new DefaultYobBuilder();
+ Object yangObject = yobBuilder.getYangObject(appRoot,
+ utils.schemaRegistry());
+ assertThat(yangObject, is(notNullValue()));
+ YmsIetfNetworkOpParam ietfNetwork = (YmsIetfNetworkOpParam) yangObject;
+
+ org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang
+ .ietf.network.rev20151208.ymsietfnetwork
+ .networks.Network network = ietfNetwork.networks().network().get(0);
+
+ DefaultAugmentedNdNetwork augmentedNdNetworks = (DefaultAugmentedNdNetwork) network
+ .yangAugmentedInfo(AugmentedNdNetwork.class);
+ assertThat(augmentedNdNetworks.yangAugmentedNdNetworkOpType(),
+ is(YmsNetworkTopology.OnosYangOpType.CREATE));
+
+ Link link = augmentedNdNetworks.link().get(0);
+ DefaultAugmentedNtLink augmentedNtLink = (DefaultAugmentedNtLink) link
+ .yangAugmentedInfo(AugmentedNtLink.class);
+ assertThat(augmentedNtLink.yangAugmentedNtLinkOpType(),
+ is(YmsIetfTeTopology.OnosYangOpType.CREATE));
+
+ assertThat(augmentedNtLink.te().config().teLinkTemplate().get(0),
+ is("1"));
+ }
+}
+
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobIetfNetworkTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobIetfNetworkTest.java
new file mode 100644
index 0000000..38aed89
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobIetfNetworkTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import static org.junit.Assert.assertNotNull;
+
+public class YobIetfNetworkTest {
+
+ @Test
+ public void ietfNetwork1Test() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.ietfNetwork1Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ //TODO yangObject need to verify
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger16Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger16Test.java
new file mode 100644
index 0000000..7d6dc1c
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger16Test.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobInteger16Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for integer
+ i. min value
+ ii. max value
+
+ input at boundary for unsigned integer
+ i. min value
+ ii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ if range is 10 to 100 for unsigned integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer16Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ public void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-32768", negInt.get(yangObject).toString());
+ Field posInt = yangObject.getClass().getDeclaredField("posInt");
+ posInt.setAccessible(true);
+ assertEquals("32767", posInt.get(yangObject).toString());
+ Field minIntWithRange = yangObject
+ .getClass().getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange.get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange.get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ Field minUint = yangObject.getClass().getDeclaredField("minUint");
+ minUint.setAccessible(true);
+ assertEquals("0", minUint.get(yangObject).toString());
+ Field maxUint = yangObject.getClass().getDeclaredField("maxUint");
+ maxUint.setAccessible(true);
+ assertEquals("65535", maxUint.get(yangObject).toString());
+ Field minUintWithRange = yangObject
+ .getClass().getDeclaredField("minUintWithRange");
+ minUintWithRange.setAccessible(true);
+ assertEquals("10", minUintWithRange.get(yangObject).toString());
+ Field midUintWithRange = yangObject
+ .getClass().getDeclaredField("midUintWithRange");
+ midUintWithRange.setAccessible(true);
+ assertEquals("11", midUintWithRange.get(yangObject).toString());
+ Field maxUintWithRange = yangObject
+ .getClass().getDeclaredField("maxUintWithRange");
+ maxUintWithRange.setAccessible(true);
+ assertEquals("100", maxUintWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger32Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger32Test.java
new file mode 100644
index 0000000..1e73dc7
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger32Test.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobInteger32Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for integer
+ i. min value
+ ii. max value
+
+ input at boundary for unsigned integer
+ i. min value
+ ii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ if range is 10 to 100 for unsigned integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer32Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ public void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-2147483648", negInt.get(yangObject).toString());
+ Field posInt = yangObject.getClass().getDeclaredField("posInt");
+ posInt.setAccessible(true);
+ assertEquals("2147483647", posInt.get(yangObject).toString());
+ Field minIntWithRange = yangObject
+ .getClass().getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange.get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange.get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ Field minUint = yangObject.getClass().getDeclaredField("minUint");
+ minUint.setAccessible(true);
+ assertEquals("0", minUint.get(yangObject).toString());
+ Field maxUint = yangObject.getClass().getDeclaredField("maxUint");
+ maxUint.setAccessible(true);
+ assertEquals("4294967295", maxUint.get(yangObject).toString());
+ Field minUintWithRange = yangObject
+ .getClass().getDeclaredField("minUintWithRange");
+ minUintWithRange.setAccessible(true);
+ assertEquals("10", minUintWithRange.get(yangObject).toString());
+ Field midUintWithRange = yangObject
+ .getClass().getDeclaredField("midUintWithRange");
+ midUintWithRange.setAccessible(true);
+ assertEquals("11", midUintWithRange.get(yangObject).toString());
+ Field maxUintWithRange = yangObject
+ .getClass().getDeclaredField("maxUintWithRange");
+ maxUintWithRange.setAccessible(true);
+ assertEquals("100", maxUintWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger64Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger64Test.java
new file mode 100644
index 0000000..eca6986
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger64Test.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+public class YobInteger64Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for integer
+ i. min value
+ ii. max value
+
+ input at boundary for unsigned integer
+ i. min value
+ ii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ if range is 10 to 100 for unsigned integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer64Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-9223372036854775808", negInt
+ .get(yangObject).toString());
+ Field posIntField = yangObject
+ .getClass().getDeclaredField("posInt");
+ posIntField.setAccessible(true);
+ assertEquals("9223372036854775807", posIntField
+ .get(yangObject).toString());
+ Field minIntWithRange = yangObject
+ .getClass().getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange.get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange.get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ Field minUint = yangObject.getClass().getDeclaredField("minUint");
+ minUint.setAccessible(true);
+ assertEquals("0", minUint.get(yangObject).toString());
+ Field maxUint = yangObject.getClass().getDeclaredField("maxUint");
+ maxUint.setAccessible(true);
+ assertEquals("18446744073709551615", maxUint
+ .get(yangObject).toString());
+ Field minUintWithRange = yangObject
+ .getClass().getDeclaredField("minUintWithRange");
+ minUintWithRange.setAccessible(true);
+ assertEquals("10", minUintWithRange.get(yangObject).toString());
+ Field midUintWithRange = yangObject
+ .getClass().getDeclaredField("midUintWithRange");
+ midUintWithRange.setAccessible(true);
+ assertEquals("11", midUintWithRange.get(yangObject).toString());
+ Field maxUintWithRange = yangObject
+ .getClass().getDeclaredField("maxUintWithRange");
+ maxUintWithRange.setAccessible(true);
+ assertEquals("100", maxUintWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger8Test.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger8Test.java
new file mode 100644
index 0000000..d6f75f9
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobInteger8Test.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.lang.reflect.Field;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class YobInteger8Test {
+
+ /*
+
+ Positive scenario
+
+ input at boundary for integer
+ i. min value
+ ii. max value
+
+ input at boundary for unsigned integer
+ i. min value
+ ii. max value
+
+ input with in range
+ if range is 10 to 100 for integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ if range is 10 to 100 for unsigned integer
+ i.1. input 11
+ i.2. min value 10
+ i.3. max value 100
+
+ input with multi interval range
+ if range is 10..40 | 50..100 for integer
+ i.1. input 11
+ i.2. input 10
+ i.3. input 40
+ i.4. input 50
+ i.5. input 55
+ i.6. input 100
+
+ if range is 10..40 | 50..100 for unsigned integer
+ i.1. input 11
+ i.2. input 10
+ i.3. input 40
+ i.4. input 50
+ i.5. input 55
+ i.6. input 100
+
+ if range is "min .. 2 | 10 | 20..max" for integer
+ i.1. input -128
+ i.2. input 1
+ i.3. input 2
+ i.4. input 10
+ i.5. input 20
+ i.6. input 100
+ i.7. input 127
+
+ if range is "min .. 2 | 10 | 20..max" for unsigned Integer
+ i.1. input 0
+ i.2. input 1
+ i.3. input 2
+ i.4. input 10
+ i.5. input 20
+ i.6. input 100
+ i.7. input 255
+ */
+ @Test
+ public void positiveTest() {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils.integer8Ydt();
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ private void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ try {
+ Field negInt = yangObject.getClass().getDeclaredField("negInt");
+ negInt.setAccessible(true);
+ assertEquals("-128", negInt.get(yangObject).toString());
+ Field posInt = yangObject.getClass().getDeclaredField("posInt");
+ posInt.setAccessible(true);
+ assertEquals("127", posInt.get(yangObject).toString());
+ Field minIntWithRange = yangObject
+ .getClass().getDeclaredField("minIntWithRange");
+ minIntWithRange.setAccessible(true);
+ assertEquals("10", minIntWithRange
+ .get(yangObject).toString());
+ Field midIntWithRange = yangObject
+ .getClass().getDeclaredField("midIntWithRange");
+ midIntWithRange.setAccessible(true);
+ assertEquals("11", midIntWithRange
+ .get(yangObject).toString());
+ Field maxIntWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ maxIntWithRange.setAccessible(true);
+ assertEquals("100", maxIntWithRange.get(yangObject).toString());
+ Field minUint = yangObject.getClass().getDeclaredField("minUint");
+ minUint.setAccessible(true);
+ assertEquals("0", minUint.get(yangObject).toString());
+ Field maxUint = yangObject.getClass().getDeclaredField("maxUint");
+ maxUint.setAccessible(true);
+ assertEquals("255", maxUint.get(yangObject).toString());
+ Field minUintWithRange = yangObject
+ .getClass().getDeclaredField("maxIntWithRange");
+ minUintWithRange.setAccessible(true);
+ assertEquals("100", minUintWithRange.get(yangObject).toString());
+ Field midUintWithRange = yangObject
+ .getClass().getDeclaredField("midUintWithRange");
+ midUintWithRange.setAccessible(true);
+ assertEquals("11", midUintWithRange.get(yangObject).toString());
+ Field maxUintWithRange = yangObject
+ .getClass().getDeclaredField("maxUintWithRange");
+ maxUintWithRange.setAccessible(true);
+ assertEquals("100", maxUintWithRange.get(yangObject).toString());
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLeafRefTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLeafRefTest.java
new file mode 100644
index 0000000..c7e5fe3
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLeafRefTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.ydt.leafreftest.rev20160524.LeafreftestOpParam;
+import org.onosproject.yang.gen.v1.ydt.leafreftest.rev20160524.leafreftest.cont1.AugmentedCont1;
+import org.onosproject.yang.gen.v1.ydt.leafreftest.rev20160524.leafreftest.food.snack.Sportsarena;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the leaf ref.
+ */
+public class YobLeafRefTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testLeafrefInLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addChild("leafrefList", null);
+ ydtBuilder.addLeaf("id", null, "leafref");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafrefTestOpParam = ((LeafreftestOpParam)
+ yangObject);
+ assertThat(leafrefTestOpParam.leafrefList().get(0).id().toString(),
+ is("leafref"));
+ }
+
+ @Test
+ public void testLeafrefInTypedef() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addLeaf("name", null, "leafref");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafrefTestOpParam = ((LeafreftestOpParam) yangObject);
+ assertThat(leafrefTestOpParam.name().toString(), is("leafref"));
+ }
+
+ @Test
+ public void testLeafrefInGrouping() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addChild("cont1", "ydt.leafreftest");
+ ydtBuilder.addLeaf("surname", null, "leafref");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafreftestOpParam = ((LeafreftestOpParam) yangObject);
+ assertThat(leafreftestOpParam.cont1().surname().toString(),
+ is("leafref"));
+ }
+
+ @Test
+ public void testLeafrefInAugment() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addChild("cont1", "ydt.leafreftest");
+ ydtBuilder.addLeaf("lastname", null, "yang");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafreftestOpParam = ((LeafreftestOpParam) yangObject);
+ AugmentedCont1 augmentedCont1 = (AugmentedCont1) leafreftestOpParam
+ .cont1().yangAugmentedInfo(AugmentedCont1.class);
+ assertThat(augmentedCont1.lastname().toString(), is("yang"));
+ }
+
+ @Test
+ public void testLeafrefInCase() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("leafreftest", "ydt.leafreftest");
+ ydtBuilder.addChild("food", "ydt.leafreftest");
+ ydtBuilder.addLeaf("pretzel", null, "yang");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ LeafreftestOpParam leafreftestOpParam = ((LeafreftestOpParam)
+ yangObject);
+ Sportsarena sportsArena = ((Sportsarena) leafreftestOpParam.food()
+ .snack());
+ assertThat(sportsArena.pretzel().toString(), is("yang"));
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobListTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobListTest.java
new file mode 100644
index 0000000..4f30ca2
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobListTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class YobListTest {
+
+ @Test
+ public void listwithoutcontainerTest() {
+ YangRequestWorkBench defaultYdtBuilder =
+ YdtTestUtils.listWithoutContainerYdt();
+ validateYangObjectList(defaultYdtBuilder);
+ }
+
+ private void validateYangObjectList(
+ YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils.
+ getSchemaRegistry());
+ assertNotNull(yangObject);
+ assertTrue(yangObject.getClass().getSimpleName()
+ .equals("RootlistOpParam"));
+ try {
+
+ Field field =
+ yangObject.getClass().getDeclaredField("listwithcontainer");
+ field.setAccessible(true);
+ List listwithcontainer = (List) field.get(yangObject);
+ assertNull(listwithcontainer);
+ Field field1 = yangObject.getClass()
+ .getDeclaredField("listwithoutcontainer");
+ field1.setAccessible(true);
+ List listwithoutcontainer = (List) field1.get(yangObject);
+ assertEquals(false, listwithoutcontainer.isEmpty());
+ Field invalidinterval = listwithoutcontainer.get(0).getClass()
+ .getDeclaredField("invalidinterval");
+ invalidinterval.setAccessible(true);
+ assertEquals("12", invalidinterval.get(listwithoutcontainer.get(0))
+ .toString());
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ Assert.fail();
+ }
+ }
+
+ @Test
+ public void listwithcontainerTest()
+ throws IOException {
+ YangRequestWorkBench defaultYdtBuilder =
+ YdtTestUtils.listWithContainerYdt();
+
+ validateYangObject(defaultYdtBuilder);
+ }
+
+ public void validateYangObject(YangRequestWorkBench defaultYdtBuilder) {
+
+ YdtContext ydtContext = defaultYdtBuilder.getRootNode();
+
+ YdtContext ydtContext1 = ydtContext.getFirstChild();
+
+ DefaultYobBuilder defaultYobBuilder = new DefaultYobBuilder();
+
+ Object yangObject = defaultYobBuilder.getYangObject(
+ (YdtExtendedContext) ydtContext1, YdtTestUtils
+ .getSchemaRegistry());
+ assertNotNull(yangObject);
+ assertTrue(yangObject.getClass().getSimpleName()
+ .equals("RootlistOpParam"));
+ try {
+
+ Field field = yangObject.getClass()
+ .getDeclaredField("listwithoutcontainer");
+ field.setAccessible(true);
+ List listwithoutcontainer = (List) field.get(yangObject);
+ assertNull(listwithoutcontainer);
+ Field listwithcontainerField =
+ yangObject.getClass().getDeclaredField("listwithcontainer");
+ listwithcontainerField.setAccessible(true);
+ List listwithcontainer =
+ (List) listwithcontainerField.get(yangObject);
+ Field invalid = listwithcontainer.get(0).getClass()
+ .getDeclaredField("invalid");
+ invalid.setAccessible(true);
+ assertEquals("12",
+ invalid.get(listwithcontainer.get(0)).toString());
+ Field invalidinterval = listwithcontainer.get(0).getClass()
+ .getDeclaredField("invalidinterval");
+ invalidinterval.setAccessible(true);
+ List invalidintervalList =
+ (List) invalidinterval.get(listwithcontainer.get(0));
+ assertEquals("1", invalidintervalList.get(0).toString());
+ assertEquals("2", invalidintervalList.get(1).toString());
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ Assert.fail();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLogisticsManagerTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLogisticsManagerTest.java
new file mode 100644
index 0000000..8d3b5e3
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobLogisticsManagerTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+
+import static org.junit.Assert.assertEquals;
+
+public class YobLogisticsManagerTest {
+
+ @Test
+ public void logisticsManagerTest() throws IOException {
+ YangRequestWorkBench defaultYdtBuilder = YdtTestUtils
+ .logisticsManagerYdt();
+
+ YdtContext rootCtx = defaultYdtBuilder.getRootNode();
+
+ YdtContext childCtx = rootCtx.getFirstChild();
+
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+
+ while (childCtx != null) {
+
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, YdtTestUtils
+ .getSchemaRegistry());
+ Class<?> aClass = yangObject.getClass();
+ if (aClass.getSimpleName().equals("CustomssupervisorOpParam")) {
+ try {
+ Field field = aClass.getDeclaredField("supervisor");
+ Field onosYangNodeOperationType = aClass
+ .getDeclaredField("yangCustomssupervisorOpType");
+ field.setAccessible(true);
+ onosYangNodeOperationType.setAccessible(true);
+ try {
+ assertEquals("abc", field.get(yangObject).toString());
+ assertEquals("MERGE", onosYangNodeOperationType
+ .get(yangObject).toString());
+ } catch (IllegalAccessException e) {
+ Assert.fail();
+ }
+ } catch (NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+
+ if (aClass.getSimpleName().equals(
+ "MerchandisersupervisorOpParam")) {
+ try {
+ Field field = aClass.getDeclaredField("supervisor");
+ field.setAccessible(true);
+ try {
+ assertEquals("abc", field.get(yangObject).toString());
+ } catch (IllegalAccessException e) {
+ Assert.fail();
+ }
+ } catch (NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+
+ if (aClass.getSimpleName().equals("WarehousesupervisorOpParam")) {
+ try {
+ Field field = aClass.getDeclaredField("supervisor");
+ field.setAccessible(true);
+ try {
+ ArrayList<String> arrayList =
+ (ArrayList<String>) field.get(yangObject);
+ assertEquals("1", arrayList.get(0));
+ assertEquals("2", arrayList.get(1));
+ assertEquals("3", arrayList.get(2));
+ assertEquals("4", arrayList.get(3));
+ assertEquals("5", arrayList.get(4));
+ } catch (IllegalAccessException e) {
+ Assert.fail();
+ }
+ } catch (NoSuchFieldException e) {
+ Assert.fail();
+ }
+ }
+ childCtx = childCtx.getNextSibling();
+ }
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobTestUtils.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobTestUtils.java
new file mode 100644
index 0000000..11818d8
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobTestUtils.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yms.app.yob;
+
+import org.onosproject.yms.app.ysr.TestYangSchemaNodeProvider;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+
+/**
+ * YOB test Utility.
+ */
+final class YobTestUtils {
+
+ /**
+ * Schema nodes.
+ */
+ static final String ROOT_DATA_RESOURCE = "/restconf/data";
+ static final String TOPOLOGY = "yms-topology";
+ static final String NODE = "node";
+ static final String LEAF_1A1 = "leaf1a1";
+ static final String LEAF_1A2 = "leaf1a2";
+ static final String LEAF_1BIA = "leaf1bia";
+ static final String LEAF_1BIB = "leaf1bib";
+ static final String ROUTER_ID = "router-id";
+ static final String ROUTER_IP = "router-ip";
+ static final String STR_LEAF_VALUE = "leaf value";
+ static final String YMS_IETF_NETWORK = "yms-ietf-network";
+ static final String NETWORKS_STATE = "networks-state";
+ static final String NETWORKS = "networks";
+ static final String NETWORK = "network";
+ static final String NETWORK_REF = "network-ref";
+ static final String IETF_TE_TOPOLOGY = "yms-ietf-te-topology";
+ static final String TE_NODE_EVENT = "te-node-event";
+ static final String TE_NODE_ATTRIBUTES = "te-node-attributes";
+ static final String ADMIN_STATUS = "admin-status";
+ static final String UP = "up";
+ static final String LINK = "link";
+ static final String YMS_NETWORK_TOPOLOGY = "yms-network-topology";
+ static final String TE = "te";
+ static final String CONFIG = "config";
+ static final String BUNDLED_LINKS = "bundled-links";
+ static final String BUNDLED_LINK = "bundled-link";
+ static final String SEQUENCE = "sequence";
+ static final String TE_LINK_TEMPLATE = "te-link-template";
+
+ private YobTestUtils() {
+ TEST_SCHEMA_PROVIDER.processSchemaRegistry(null);
+ }
+
+ private static final TestYangSchemaNodeProvider
+ TEST_SCHEMA_PROVIDER = new TestYangSchemaNodeProvider();
+
+ YangSchemaRegistry schemaRegistry() {
+ return TEST_SCHEMA_PROVIDER.getDefaultYangSchemaRegistry();
+ }
+
+ /**
+ * Returns the YANG object builder factory instance.
+ *
+ * @return YANG object builder factory instance
+ */
+ static YobTestUtils instance() {
+ return LazyHolder.INSTANCE;
+ }
+
+ /*
+ * Bill Pugh Singleton pattern. INSTANCE won't be instantiated until the
+ * LazyHolder class is loaded via a call to the instance() method below.
+ */
+ private static class LazyHolder {
+ private static final YobTestUtils INSTANCE = new YobTestUtils();
+ }
+}
diff --git a/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobUnionTest.java b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobUnionTest.java
new file mode 100644
index 0000000..1829286
--- /dev/null
+++ b/apps/yms/ut/src/test/java/org/onosproject/yms/app/yob/YobUnionTest.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yms.app.yob;
+
+import org.junit.Test;
+import org.onosproject.yang.gen.v1.ydt.uniontest.rev20160524.UniontestOpParam;
+import org.onosproject.yang.gen.v1.ydt.uniontest.rev20160524.uniontest.cont1.AugmentedCont1;
+import org.onosproject.yang.gen.v1.ydt.uniontest.rev20160524.uniontest.food.snack.Sportsarena;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.onosproject.yms.app.yob.YobTestUtils.ROOT_DATA_RESOURCE;
+
+/**
+ * Test the YANG object building for the YANG data tree based on the union.
+ */
+public class YobUnionTest {
+
+ private YobTestUtils utils = YobTestUtils.instance();
+
+ @Test
+ public void testUnionInLeaf() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addChild("unionList", null);
+ ydtBuilder.addLeaf("id", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam unionTestOpParam = ((UniontestOpParam) yangObject);
+
+ byte[] binaryValue = unionTestOpParam.unionList().get(0).id().binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+
+ @Test
+ public void testUnionInTypedef() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addLeaf("name", null, "bit1");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam unionTestOpParam = ((UniontestOpParam) yangObject);
+ assertThat(unionTestOpParam.name().union().bits().get(1), is(true));
+ }
+
+ @Test
+ public void testUnionInGrouping() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addChild("cont1", "ydt.uniontest");
+ ydtBuilder.addLeaf("surname", null, "yang");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam uniontestOpParam = ((UniontestOpParam) yangObject);
+ assertThat(uniontestOpParam.cont1().surname().string(), is("yang"));
+ }
+
+ @Test
+ public void testUnionInAugment() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addChild("cont1", "ydt.uniontest");
+ ydtBuilder.addLeaf("lastname", null, "bit0");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam uniontestOpParam = ((UniontestOpParam) yangObject);
+
+ AugmentedCont1 augmentedCont1 = (AugmentedCont1) uniontestOpParam
+ .cont1().yangAugmentedInfo(AugmentedCont1.class);
+ assertThat(augmentedCont1.lastname().bits().get(0), is(true));
+ }
+
+ @Test
+ public void testUnionInCase() throws IOException {
+ YangRequestWorkBench ydtBuilder = new YangRequestWorkBench(
+ ROOT_DATA_RESOURCE, null, null, utils.schemaRegistry(), true);
+ ydtBuilder.addChild("uniontest", "ydt.uniontest");
+ ydtBuilder.addChild("food", "ydt.uniontest");
+ ydtBuilder.addLeaf("pretzel", null, "YmluYXJ5");
+ ydtBuilder.traverseToParent();
+ ydtBuilder.traverseToParent();
+ YdtContext rootCtx = ydtBuilder.getRootNode();
+ YdtContext childCtx = rootCtx.getFirstChild();
+ DefaultYobBuilder builder = new DefaultYobBuilder();
+ Object yangObject = builder.getYangObject(
+ (YdtExtendedContext) childCtx, utils.schemaRegistry());
+ assertThat(yangObject, notNullValue());
+ UniontestOpParam uniontestOpParam = ((UniontestOpParam) yangObject);
+ Sportsarena sportsArena = ((Sportsarena) uniontestOpParam.food()
+ .snack());
+ byte[] binaryValue = sportsArena.pretzel().binary();
+ String value = new String(binaryValue);
+ assertThat(value, is("binary"));
+ }
+}
diff --git a/apps/yms/ut/src/test/resources/ydtTestYangFiles/binarytest.yang b/apps/yms/ut/src/test/resources/ydtTestYangFiles/binarytest.yang
index 71ada48..f6db459d 100644
--- a/apps/yms/ut/src/test/resources/ydtTestYangFiles/binarytest.yang
+++ b/apps/yms/ut/src/test/resources/ydtTestYangFiles/binarytest.yang
@@ -30,4 +30,45 @@
}
}
}
+
+ typedef percent {
+ type binary;
+ }
+
+ leaf name {
+ type percent;
+ }
+
+ grouping greeting {
+ leaf surname {
+ type binary;
+ }
+ }
+
+ container cont1 {
+ uses greeting;
+ }
+
+ augment "/cont1" {
+ leaf lastname {
+ type binary;
+ }
+ }
+
+ container food {
+ choice snack {
+ case sportsarena {
+ leaf pretzel {
+ type binary;
+ }
+ }
+ }
+ }
+
+ leaf middlename {
+ type union {
+ type int8;
+ type binary;
+ }
+ }
}
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ydtTestYangFiles/bit.yang b/apps/yms/ut/src/test/resources/ydtTestYangFiles/bit.yang
index 6d97ccc..8b4f0c3 100644
--- a/apps/yms/ut/src/test/resources/ydtTestYangFiles/bit.yang
+++ b/apps/yms/ut/src/test/resources/ydtTestYangFiles/bit.yang
@@ -13,22 +13,6 @@
revision "2016-05-24" {
description "Initial revision.";
}
-/*
- leaf mybits {
- type bits {
- bit disable-nagle {
- position 0;
- }
- bit auto-sense-speed {
- position 1;
- }
- bit 10-Mb-only {
- position 2;
- }
- }
- default "auto-sense-speed";
- }
- */
list bitList {
config false;
@@ -44,8 +28,80 @@
position 2;
}
}
- default "auto-sense-speed";
+ }
+ }
+ typedef percent {
+ type bits {
+ bit bit3 {
+ position 3;
+ }
+ bit bit4 {
+ position 4;
+ }
+ bit bit5 {
+ position 5;
+ }
+ }
+ }
+
+ leaf name {
+ type percent;
+ }
+
+ grouping greeting {
+ leaf surname {
+ type bits {
+ bit bit6 {
+ position 6;
+ }
+ bit bit7 {
+ position 7;
+ }
+ bit bit8 {
+ position 8;
+ }
+ }
+ }
+ }
+
+ container cont1 {
+ uses greeting;
+ }
+
+ augment "/cont1" {
+ leaf lastname {
+ type bits {
+ bit bit9 {
+ position 9;
+ }
+ bit bit10 {
+ position 10;
+ }
+ bit bit11 {
+ position 11;
+ }
+ }
+ }
+ }
+
+ container food {
+ choice snack {
+ case sportsarena {
+ leaf pretzel {
+ type bits {
+ bit bit12 {
+ position 12;
+ }
+ bit bit13 {
+ position 13;
+ }
+ bit bit14 {
+ position 14;
+ }
+ }
+ }
+ }
}
}
}
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ydtTestYangFiles/leafreftest.yang b/apps/yms/ut/src/test/resources/ydtTestYangFiles/leafreftest.yang
new file mode 100644
index 0000000..5191b72
--- /dev/null
+++ b/apps/yms/ut/src/test/resources/ydtTestYangFiles/leafreftest.yang
@@ -0,0 +1,71 @@
+module leafreftest {
+
+ yang-version 1;
+
+ namespace "ydt.leafreftest";
+
+ prefix "uniontest";
+
+ organization "ON-LAB";
+
+ description "This module defines for union classifier.";
+
+ revision "2016-05-24" {
+ description "Initial revision.";
+ }
+
+ leaf middlename {
+ type string;
+ }
+
+ list leafrefList {
+ config false;
+ leaf id {
+ type leafref {
+ path "/middlename";
+ }
+ }
+ }
+
+ typedef percent {
+ type leafref {
+ path "/middlename";
+ }
+ }
+
+ leaf name {
+ type percent;
+ }
+
+ grouping greeting {
+ leaf surname {
+ type leafref {
+ path "/middlename";
+ }
+ }
+ }
+
+ container cont1 {
+ uses greeting;
+ }
+
+ augment "/cont1" {
+ leaf lastname {
+ type leafref {
+ path "/middlename";
+ }
+ }
+ }
+
+ container food {
+ choice snack {
+ case sportsarena {
+ leaf pretzel {
+ type leafref {
+ path "/middlename";
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/yms/ut/src/test/resources/ydtTestYangFiles/uniontest.yang b/apps/yms/ut/src/test/resources/ydtTestYangFiles/uniontest.yang
new file mode 100644
index 0000000..4ab5801
--- /dev/null
+++ b/apps/yms/ut/src/test/resources/ydtTestYangFiles/uniontest.yang
@@ -0,0 +1,92 @@
+module uniontest {
+
+ yang-version 1;
+
+ namespace "ydt.uniontest";
+
+ prefix "uniontest";
+
+ organization "ON-LAB";
+
+ description "This module defines for union classifier.";
+
+ revision "2016-05-24" {
+ description "Initial revision.";
+ }
+
+ list unionList {
+ config false;
+ leaf id {
+ type union {
+ type int8;
+ type binary;
+ }
+ }
+ }
+
+ typedef percent {
+ type union {
+ type int8;
+ type bits {
+ bit bit0 {
+ position 0;
+ }
+ bit bit1 {
+ position 1;
+ }
+ bit bit2 {
+ position 2;
+ }
+ }
+ }
+ }
+
+ leaf name {
+ type percent;
+ }
+
+ grouping greeting {
+ leaf surname {
+ type union {
+ type int8;
+ type string;
+ }
+ }
+ }
+
+ container cont1 {
+ uses greeting;
+ }
+
+ augment "/cont1" {
+ leaf lastname {
+ type union {
+ type int8;
+ type bits {
+ bit bit0 {
+ position 0;
+ }
+ bit bit1 {
+ position 1;
+ }
+ bit bit2 {
+ position 2;
+ }
+ }
+ }
+ }
+ }
+
+ container food {
+ choice snack {
+ case sportsarena {
+ leaf pretzel {
+ type union {
+ type int8;
+ type binary;
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file