[ONOS-5080] YANG object builder coding
Change-Id: Ibef332b58f197a2f6626ee9b6d791b80002e2dfd
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/DefaultYobBuilder.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/DefaultYobBuilder.java
new file mode 100755
index 0000000..c77bbaa
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/DefaultYobBuilder.java
@@ -0,0 +1,53 @@
+/*
+ * 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.ydt.DefaultYdtWalker;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ydt.YdtExtendedListener;
+import org.onosproject.yms.app.ydt.YdtExtendedWalker;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+
+import static org.onosproject.yms.app.ydt.AppType.YOB;
+
+/**
+ * Represents implementation of interfaces to build and obtain YANG objects
+ * from YDT.
+ */
+public class DefaultYobBuilder implements YobBuilder {
+
+ /**
+ * Creates an instance of DefaultYobBuilder.
+ */
+ public DefaultYobBuilder() {
+ }
+
+ @Override
+ public Object getYangObject(YdtExtendedContext ydtRootNode,
+ YangSchemaRegistry schemaRegistry) {
+ YdtExtendedWalker ydtExtendedWalker = new DefaultYdtWalker();
+ YdtExtendedListener yobListener =
+ new YobListener(ydtRootNode, schemaRegistry);
+ if (ydtRootNode != null) {
+ ydtExtendedWalker.walk(yobListener, ydtRootNode);
+ YobWorkBench yobWorkBench =
+ (YobWorkBench) ydtRootNode.getAppInfo(YOB);
+ return yobWorkBench.getBuilderOrBuiltObject().getBuiltObject();
+ }
+ return null;
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobBuilder.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobBuilder.java
new file mode 100644
index 0000000..0d0cf44
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobBuilder.java
@@ -0,0 +1,39 @@
+/*
+ * 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.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+
+/**
+ * Abstraction of an entity which provides interfaces to YANG object
+ * builder.
+ */
+interface YobBuilder {
+
+ /**
+ * Returns the YANG object. This will be called by NBI broker.
+ *
+ * @param ydtExtendedContext ydtExtendedContext is used to get application
+ * related information maintained in YDT
+ * @param schemaRegistry schema registry
+ * @return YANG builder object
+ */
+ Object getYangObject(YdtExtendedContext ydtExtendedContext,
+ YangSchemaRegistry schemaRegistry);
+}
+
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
new file mode 100644
index 0000000..4caa212
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobBuilderOrBuiltObject.java
@@ -0,0 +1,130 @@
+/*
+ * 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.yob.exception.YobExceptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.onosproject.yms.app.yob.YobConstants.BUILDER_IS_NOT_SET;
+import static org.onosproject.yms.app.yob.YobConstants.BUILT_OBJ_IS_NOT_SET;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_CREATE_OBJ;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_LOAD_CLASS;
+import static org.onosproject.yms.app.yob.YobConstants.OBJ_BUILDING_WITHOUT_BUILDER;
+import static org.onosproject.yms.app.yob.YobConstants.OBJ_IS_ALREADY_BUILT_NOT_BUILD;
+import static org.onosproject.yms.app.yob.YobConstants.OBJ_IS_ALREADY_BUILT_NOT_FETCH;
+import static org.onosproject.yms.app.yob.YobConstants.OBJ_IS_NOT_SET_NOT_FETCH;
+import static org.onosproject.yms.app.yob.YobConstants.REFLECTION_FAIL_TO_CREATE_OBJ;
+
+/**
+ * Represents the container of YANG object being built or the builder.
+ */
+class YobBuilderOrBuiltObject {
+ private static final Logger log = LoggerFactory.getLogger(YobWorkBench.class);
+
+ /**
+ * Is the contained object a built object.
+ */
+ private boolean isBuilt;
+
+ /**
+ * Builder or built object.
+ */
+ private Object builderOrBuiltObject;
+
+ /**
+ * Default / op param builder class.
+ */
+ Class<?> yangBuilderClass;
+
+ /**
+ * Default Class.
+ */
+ Class<?> yangDefaultClass;
+
+ YobBuilderOrBuiltObject(String qualifiedClassName,
+ ClassLoader registeredAppClassLoader) {
+ try {
+ yangDefaultClass =
+ registeredAppClassLoader.loadClass(qualifiedClassName);
+ yangBuilderClass = yangDefaultClass.getDeclaredClasses()[0];
+ builderOrBuiltObject = yangBuilderClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ log.error(FAIL_TO_LOAD_CLASS + qualifiedClassName);
+ } catch (InstantiationException | IllegalAccessException e) {
+ log.error(FAIL_TO_CREATE_OBJ + qualifiedClassName);
+ } catch (NullPointerException e) {
+ log.error(REFLECTION_FAIL_TO_CREATE_OBJ + qualifiedClassName);
+ }
+ }
+
+ /**
+ * Returns the builder object if it is set.
+ *
+ * @return builder object
+ * @throws YobExceptions if builder object is not available
+ */
+ Object getBuilderObject() {
+ if (isBuilt) {
+ throw new YobExceptions(OBJ_IS_ALREADY_BUILT_NOT_FETCH);
+ }
+
+ if (builderOrBuiltObject == null) {
+ throw new YobExceptions(BUILDER_IS_NOT_SET);
+ }
+
+ return builderOrBuiltObject;
+ }
+
+ /**
+ * Returns the built object.
+ *
+ * @return built object
+ * @throws YobExceptions if built object is not available
+ */
+ Object getBuiltObject() {
+ if (!isBuilt) {
+ throw new YobExceptions(OBJ_IS_NOT_SET_NOT_FETCH);
+ }
+
+ if (builderOrBuiltObject == null) {
+ throw new YobExceptions(BUILT_OBJ_IS_NOT_SET);
+ }
+
+ return builderOrBuiltObject;
+ }
+
+ /**
+ * Check if the built object is being initialized for the 1st time and
+ * set it.
+ *
+ * @param builtObject new built object
+ * @throws YobExceptions if builder or built object is not available
+ */
+ void setBuiltObject(Object builtObject) {
+ if (isBuilt) {
+ throw new YobExceptions(OBJ_IS_ALREADY_BUILT_NOT_BUILD);
+ }
+
+ if (builderOrBuiltObject == null) {
+ throw new YobExceptions(OBJ_BUILDING_WITHOUT_BUILDER);
+ }
+
+ isBuilt = true;
+ builderOrBuiltObject = builtObject;
+ }
+}
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
new file mode 100644
index 0000000..2fc1343
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobConstants.java
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+/**
+ * Represents common constant utility for YANG object builder.
+ */
+final class YobConstants {
+ private YobConstants() {
+ }
+
+ static final String FROM_STRING = "fromString";
+ static final String BUILD = "build";
+ static final String OP_PARAM = "OpParam";
+ 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 OF = "of";
+ static final String PERIOD = ".";
+ static final String NO_HANDLE_FOR_YDT = "No handler for YDT node";
+ static final String HAS_NO_CHILD = " does not have child ";
+ static final String SET_OP_TYPE_FAIL = "Failed to set Operation Type";
+ static final String FAIL_TO_BUILD = "Failed to build the object ";
+ static final String FAIL_TO_GET_FIELD = "Failed to get field for class ";
+ static final String FAIL_TO_GET_METHOD = "Failed to get method for class ";
+ static final String FAIL_TO_LOAD_CLASS = "Failed to load class for class ";
+ static final String YDT_TYPE_IS_NOT_SUPPORT =
+ "Given YDT type is not supported.";
+ static final String FAIL_TO_CREATE_OBJ =
+ "Failed to create an object for class ";
+ static final String REFLECTION_FAIL_TO_CREATE_OBJ =
+ "Reflection failed to create an object for class ";
+ static final String FAIL_TO_LOAD_CONSTRUCTOR =
+ "Failed to load constructor for class ";
+ static final String FAIL_TO_INVOKE_METHOD =
+ "Failed to invoke method for class ";
+ static final String DATA_TYPE_NOT_SUPPORT =
+ "Given data type is not supported.";
+ static final String OBJ_IS_ALREADY_BUILT_NOT_FETCH =
+ "Object is already built, cannot fetch builder";
+ static final String BUILDER_IS_NOT_SET =
+ "Builder is not yet set, cannot fetch it";
+ static final String BUILT_OBJ_IS_NOT_SET =
+ "Built object is not set";
+ static final String OBJ_IS_NOT_SET_NOT_FETCH =
+ "Builder is not yet set, cannot fetch it";
+ static final String OBJ_IS_ALREADY_BUILT_NOT_BUILD =
+ "Object is already built, cannot build again";
+ static final String OBJ_BUILDING_WITHOUT_BUILDER =
+ "Object building without builder";
+}
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
new file mode 100755
index 0000000..7e12be3
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobHandler.java
@@ -0,0 +1,337 @@
+/*
+ * 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.yangutils.datamodel.RpcNotificationContainer;
+import org.onosproject.yangutils.datamodel.YangBinary;
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+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.DATA_TYPE_NOT_SUPPORT;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_LOAD_CLASS;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_LOAD_CONSTRUCTOR;
+import static org.onosproject.yms.app.yob.YobConstants.FROM_STRING;
+import static org.onosproject.yms.app.yob.YobConstants.OF;
+import static org.onosproject.yms.app.yob.YobConstants.PERIOD;
+import static org.onosproject.yms.app.yob.YobWorkBench.getQualifiedDefaultClassName;
+
+/**
+ * Represents a YANG object builder handler to process the ydt content and
+ * build yang object.
+ */
+abstract class YobHandler {
+
+ private static final Logger log = LoggerFactory.getLogger(YobHandler.class);
+
+ /**
+ * reference to YANG schema registry.
+ */
+ private YangSchemaRegistry registry;
+
+ /**
+ * Creates a YANG builder object.
+ *
+ * @param curYdtNode ydtExtendedContext is used to get
+ * application related information maintained
+ * in YDT
+ * @param rootYdtNode ydtRootNode is refers to module node
+ * @param registry registry
+ */
+ public void createYangBuilderObject(YdtExtendedContext curYdtNode,
+ YdtExtendedContext rootYdtNode,
+ YangSchemaRegistry registry) {
+ String setterName = null;
+ YangSchemaNode node = curYdtNode.getYangSchemaNode();
+
+ String qualName = getQualifiedDefaultClassName(node);
+ ClassLoader classLoader = getClassLoader(registry, qualName,
+ curYdtNode);
+
+ if (curYdtNode != rootYdtNode) {
+ setterName = node.getJavaAttributeName();
+ }
+
+ Object builderObject = new YobWorkBench(node, classLoader,
+ qualName, setterName);
+
+ curYdtNode.addAppInfo(YOB, builderObject);
+ }
+
+ /**
+ * Sets the YANG built object in corresponding parent class method.
+ *
+ * @param ydtNode ydtExtendedContext is used to get application
+ * related information maintained in YDT
+ * @param schemaRegistry YANG schema registry
+ */
+ public void setObjectInParent(YdtExtendedContext ydtNode,
+ YangSchemaRegistry schemaRegistry) {
+ }
+
+ /**
+ * Builds the object.
+ *
+ * @param ydtNode ydtExtendedContext is used to get
+ * application related
+ * information maintained in YDT
+ * @param ydtRootNode ydtRootNode
+ * @param schemaRegistry YANG schema registry
+ */
+ public void buildObjectFromBuilder(YdtExtendedContext ydtNode,
+ YdtExtendedContext ydtRootNode,
+ YangSchemaRegistry schemaRegistry) {
+ YobWorkBench yobWorkBench = (YobWorkBench) ydtNode.getAppInfo(YOB);
+ yobWorkBench.buildObject(ydtNode, ydtRootNode);
+ }
+
+ /**
+ * This method is used to set data from string value in parent method.
+ *
+ * @param type refers to YANG 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
+ * @throws InvocationTargetException throws InvocationTargetException
+ * @throws IllegalAccessException throws IllegalAccessException
+ * @throws NoSuchMethodException throws NoSuchMethodException
+ */
+ void setDataFromStringValue(YangType<?> type, String leafValue,
+ Method parentSetterMethod,
+ Object parentBuilderObject,
+ YdtExtendedContext ydtExtendedContext)
+ throws InvocationTargetException, IllegalAccessException,
+ NoSuchMethodException {
+ switch (type.getDataType()) {
+ case INT8: {
+ parentSetterMethod.invoke(parentBuilderObject,
+ Byte.parseByte(leafValue));
+ break;
+ }
+ case UINT8:
+ case INT16: {
+ parentSetterMethod.invoke(parentBuilderObject,
+ Short.parseShort(leafValue));
+ break;
+ }
+ case UINT16:
+ case INT32: {
+ parentSetterMethod.invoke(parentBuilderObject,
+ Integer.parseInt(leafValue));
+ break;
+ }
+ case UINT32:
+ case INT64: {
+ parentSetterMethod.invoke(parentBuilderObject,
+ Long.parseLong(leafValue));
+ break;
+ }
+ case UINT64: {
+ parentSetterMethod.invoke(parentBuilderObject,
+ new BigInteger(leafValue));
+ break;
+ }
+ case EMPTY:
+ case BOOLEAN: {
+ parentSetterMethod.invoke(parentBuilderObject,
+ Boolean.parseBoolean(leafValue));
+ break;
+ }
+ case STRING: {
+ parentSetterMethod.invoke(parentBuilderObject, leafValue);
+ break;
+ }
+ case BINARY: {
+ parentSetterMethod.invoke(parentBuilderObject,
+ new YangBinary(leafValue));
+ break;
+ }
+ case BITS: {
+ //TODO
+ break;
+ }
+ case DECIMAL64: {
+ parentSetterMethod.invoke(parentBuilderObject,
+ new BigDecimal(leafValue));
+ break;
+ }
+ case DERIVED: {
+ parseDerivedTypeInfo(ydtExtendedContext, parentSetterMethod,
+ parentBuilderObject, leafValue, false);
+ break;
+ }
+ case UNION: {
+ // TODO
+ break;
+ }
+ case LEAFREF: {
+ // TODO
+ break;
+ }
+ case ENUMERATION: {
+ parseDerivedTypeInfo(ydtExtendedContext, parentSetterMethod,
+ parentBuilderObject, leafValue, true);
+ break;
+ }
+ default: {
+ log.error(DATA_TYPE_NOT_SUPPORT);
+ }
+ }
+ }
+
+ /**
+ * 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
+ * @throws InvocationTargetException throws InvocationTargetException
+ * @throws IllegalAccessException throws IllegalAccessException
+ * @throws NoSuchMethodException throws NoSuchMethodException
+ */
+ private void parseDerivedTypeInfo(YdtExtendedContext ydtExtendedContext,
+ Method parentSetterMethod,
+ Object parentBuilderObject,
+ String leafValue, boolean isEnum)
+ throws InvocationTargetException, IllegalAccessException,
+ NoSuchMethodException {
+ Class<?> childSetClass = null;
+ Constructor<?> childConstructor = null;
+ Object childValue = null;
+ Object childObject = null;
+ Method childMethod = null;
+
+ YangSchemaNode yangJavaModule = ydtExtendedContext.getYangSchemaNode();
+ String packageName = yangJavaModule.getJavaPackage();
+ String className = getCapitalCase(
+ yangJavaModule.getJavaClassNameOrBuiltInType());
+ String qualifiedClassName = packageName + PERIOD + className;
+ ClassLoader classLoader = getClassLoader(registry,
+ qualifiedClassName,
+ ydtExtendedContext);
+ try {
+ childSetClass = classLoader.loadClass(qualifiedClassName);
+ } catch (ClassNotFoundException e) {
+ log.error(FAIL_TO_LOAD_CLASS + packageName + PERIOD + className);
+ }
+ if (!isEnum) {
+
+ if (childSetClass != null) {
+ childConstructor = childSetClass.getDeclaredConstructor();
+ }
+
+ if (childConstructor != null) {
+ childConstructor.setAccessible(true);
+ }
+ try {
+ if (childConstructor != null) {
+ childObject = childConstructor.newInstance();
+ }
+ } catch (InstantiationException e) {
+ log.error(FAIL_TO_LOAD_CONSTRUCTOR + className);
+ }
+ if (childSetClass != null) {
+ childMethod = childSetClass
+ .getDeclaredMethod(FROM_STRING, String.class);
+ }
+ } else {
+ 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);
+ }
+
+ /**
+ * Updates class loader for all the classes.
+ *
+ * @param registry YANG schema registry
+ * @param context YDT context
+ * @param qualifiedClassName qualified class name
+ * @return current class loader
+ */
+ private ClassLoader getClassLoader(YangSchemaRegistry registry,
+ String qualifiedClassName,
+ YdtExtendedContext context) {
+
+ YangSchemaNode yangSchemaNode = context.getYangSchemaNode();
+ if (yangSchemaNode instanceof RpcNotificationContainer) {
+ Class<?> regClass = registry.getRegisteredClass(yangSchemaNode,
+ qualifiedClassName);
+ return regClass.getClassLoader();
+ } else {
+
+ YdtExtendedContext parent =
+ (YdtExtendedContext) context.getParent();
+ YobWorkBench parentBuilderContainer =
+ (YobWorkBench) parent.getAppInfo(YOB);
+ Object parentObj =
+ parentBuilderContainer.getParentBuilder(context, registry);
+ return parentObj.getClass().getClassLoader();
+ }
+ }
+
+ /**
+ * Returns the YANG schema registry.
+ *
+ * @return registry YANG schema registry
+ */
+ public YangSchemaRegistry getRegistry() {
+ return registry;
+ }
+
+ /**
+ * Sets the YANG schema registry.
+ *
+ * @param registry YANG schema registry
+ */
+ public void setRegistry(YangSchemaRegistry registry) {
+ this.registry = registry;
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobHandlerFactory.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobHandlerFactory.java
new file mode 100755
index 0000000..254edd9
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobHandlerFactory.java
@@ -0,0 +1,101 @@
+/*
+ * 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.ydt.YdtExtendedContext;
+import org.onosproject.yms.ydt.YdtType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.onosproject.yms.app.yob.YobConstants.YDT_TYPE_IS_NOT_SUPPORT;
+import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_NODE;
+import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_NODE;
+
+/**
+ * Represents an YANG object builder factory to create different types
+ * of YANG data tree node.
+ */
+final class YobHandlerFactory {
+
+ private static final Logger log =
+ LoggerFactory.getLogger(YobSingleInstanceLeafHandler.class);
+
+ /**
+ * Creates single instance node handler.
+ */
+ private static YobSingleInstanceHandler singleInstanceNode =
+ new YobSingleInstanceHandler();
+
+ /**
+ * Creates multi instance node handler.
+ */
+ private static YobMultiInstanceHandler multiInstanceNode =
+ new YobMultiInstanceHandler();
+
+ /**
+ * Creates single instance leaf node handler.
+ */
+ private static YobSingleInstanceLeafHandler singleInstanceLeaf =
+ new YobSingleInstanceLeafHandler();
+
+ /**
+ * Creates multi instance leaf node handler.
+ */
+ private static YobMultiInstanceLeafHandler multiInstanceLeaf =
+ new YobMultiInstanceLeafHandler();
+
+ /**
+ * Map of YANG object builder handler.
+ */
+ private static Map<YdtType, YobHandler> yobHandlerHashMap =
+ new HashMap<>();
+
+ /**
+ * Create instance of YobHandlerFactory.
+ */
+ YobHandlerFactory() {
+ yobHandlerHashMap.put(SINGLE_INSTANCE_NODE, singleInstanceNode);
+ yobHandlerHashMap.put(MULTI_INSTANCE_NODE, multiInstanceNode);
+ yobHandlerHashMap.put(SINGLE_INSTANCE_LEAF_VALUE_NODE,
+ singleInstanceLeaf);
+ yobHandlerHashMap.put(MULTI_INSTANCE_LEAF_VALUE_NODE,
+ multiInstanceLeaf);
+ }
+
+ /**
+ * Returns the corresponding YOB handler for current context.
+ *
+ * @param ydtExtendedContext ydtExtendedContext is used to get application
+ * related information maintained in YDT
+ * @return YANG object builder node
+ */
+ YobHandler getYobHandlerForContext(
+ YdtExtendedContext ydtExtendedContext) {
+ YobHandler yobHandler =
+ yobHandlerHashMap.get(ydtExtendedContext.getYdtType());
+ if (yobHandler == null) {
+ log.error(YDT_TYPE_IS_NOT_SUPPORT);
+ return null;
+ }
+ return yobHandler;
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobListener.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobListener.java
new file mode 100755
index 0000000..be52325
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobListener.java
@@ -0,0 +1,96 @@
+/*
+ * 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.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ydt.YdtExtendedListener;
+import org.onosproject.yms.app.yob.exception.YobExceptions;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.onosproject.yms.ydt.YdtContext;
+
+import static org.onosproject.yms.app.yob.YobConstants.NO_HANDLE_FOR_YDT;
+
+/**
+ * Represents implementation of YANG object builder listener.
+ */
+class YobListener implements YdtExtendedListener {
+
+ /**
+ * Reference to the ydt root node.
+ */
+ private YdtExtendedContext ydtRootNode;
+
+ /**
+ * Reference to YANG schema registry.
+ */
+ private YangSchemaRegistry schemaRegistry;
+
+ /**
+ * Reference to YOB handler.
+ */
+ private YobHandlerFactory yobHandlerFactory;
+
+ /**
+ * Creates an instance of YANG object builder listener.
+ *
+ * @param ydtRootExtendedContext refers to YDT context
+ * @param schemaRegistry refers to YANG schema registry
+ */
+ YobListener(YdtExtendedContext ydtRootExtendedContext,
+ YangSchemaRegistry schemaRegistry) {
+ this.ydtRootNode = ydtRootExtendedContext;
+ this.schemaRegistry = schemaRegistry;
+ this.yobHandlerFactory = new YobHandlerFactory();
+ }
+
+ @Override
+ public void enterYdtNode(YdtExtendedContext ydtExtendedContext) {
+
+ YobHandler nodeHandler =
+ yobHandlerFactory.getYobHandlerForContext(ydtExtendedContext);
+
+ if (nodeHandler == null) {
+ throw new YobExceptions(NO_HANDLE_FOR_YDT);
+ }
+ nodeHandler.createYangBuilderObject(ydtExtendedContext,
+ ydtRootNode, schemaRegistry);
+
+ }
+
+ @Override
+ public void exitYdtNode(YdtExtendedContext ydtExtendedContext) {
+ YobHandler nodeHandler =
+ yobHandlerFactory.getYobHandlerForContext(ydtExtendedContext);
+ if (nodeHandler != null) {
+ nodeHandler.buildObjectFromBuilder(ydtExtendedContext,
+ ydtRootNode, schemaRegistry);
+ // The current ydt context node and root node are same then return.
+ if (!ydtExtendedContext.equals(ydtRootNode)) {
+ nodeHandler.setObjectInParent(ydtExtendedContext,
+ schemaRegistry);
+ }
+ }
+ }
+
+ @Override
+ public void enterYdtNode(YdtContext ydtContext) {
+ }
+
+ @Override
+ public void exitYdtNode(YdtContext ydtContext) {
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobMultiInstanceHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobMultiInstanceHandler.java
new file mode 100755
index 0000000..7e217cb
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobMultiInstanceHandler.java
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+/**
+ * Represents a multi instance node handler in YANG object builder.
+ */
+class YobMultiInstanceHandler extends YobHandler {
+}
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
new file mode 100755
index 0000000..9ad458b
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobMultiInstanceLeafHandler.java
@@ -0,0 +1,102 @@
+/*
+ * 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.yangutils.datamodel.YangLeafList;
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfoContainer;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.util.Set;
+
+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;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_INVOKE_METHOD;
+
+/**
+ * Represents a multi instance leaf node handler in YANG object builder.
+ */
+class YobMultiInstanceLeafHandler
+ extends YobHandler {
+
+ private static final Logger log =
+ LoggerFactory.getLogger(YobMultiInstanceLeafHandler.class);
+
+ @Override
+ public void createYangBuilderObject(YdtExtendedContext curYdtNode,
+ YdtExtendedContext rootYdtNode,
+ YangSchemaRegistry registry) {
+ // For multi instance leaf no need to create an object.
+ }
+
+ @Override
+ public void buildObjectFromBuilder(YdtExtendedContext ydtNode,
+ YdtExtendedContext ydtRootNode,
+ YangSchemaRegistry schemaRegistry) {
+ // For multi instance leaf no need to build object.
+ }
+
+ @Override
+ public void setObjectInParent(YdtExtendedContext leafListYdtNode,
+ YangSchemaRegistry schemaRegistry) {
+ Class<?> parentBuilderClass = null;
+ YangSchemaNode yangSchemaNode = leafListYdtNode.getYangSchemaNode();
+ YdtExtendedContext parentYdtNode =
+ (YdtExtendedContext) leafListYdtNode.getParent();
+ YobWorkBench parentYobWorkBench =
+ (YobWorkBench) parentYdtNode.getAppInfo(YOB);
+ Set<String> valueSet = leafListYdtNode.getValueSet();
+
+ for (String value : valueSet) {
+ try {
+ String setterInParent = yangSchemaNode.getJavaAttributeName();
+ Object parentBuilderObject = parentYobWorkBench
+ .getParentBuilder(leafListYdtNode, schemaRegistry);
+ parentBuilderClass = parentBuilderObject.getClass();
+ Field leafName = parentBuilderClass
+ .getDeclaredField(setterInParent);
+ ParameterizedType genericListType =
+ (ParameterizedType) leafName.getGenericType();
+ Class<?> genericListClass =
+ (Class<?>) genericListType.getActualTypeArguments()[0];
+ Method parentSetterMethod =
+ parentBuilderClass.getDeclaredMethod(
+ ADD_TO + getCapitalCase(setterInParent),
+ genericListClass);
+ JavaQualifiedTypeInfoContainer javaQualifiedType =
+ (JavaQualifiedTypeInfoContainer) yangSchemaNode;
+ YangType<?> yangType =
+ ((YangLeafList) javaQualifiedType).getDataType();
+ setDataFromStringValue(yangType, value, parentSetterMethod,
+ parentBuilderObject, leafListYdtNode);
+ } catch (NoSuchMethodException | InvocationTargetException
+ | IllegalAccessException | NoSuchFieldException e) {
+ log.error(FAIL_TO_INVOKE_METHOD + parentBuilderClass.getName());
+ }
+ }
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobSingleInstanceHandler.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobSingleInstanceHandler.java
new file mode 100755
index 0000000..eeb5b66
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobSingleInstanceHandler.java
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+/**
+ * Represents a single instance node handler in YANG object builder.
+ */
+class YobSingleInstanceHandler extends YobHandler {
+}
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
new file mode 100755
index 0000000..f6d8642
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobSingleInstanceLeafHandler.java
@@ -0,0 +1,87 @@
+/*
+ * 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.yangutils.datamodel.YangLeaf;
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangType;
+import org.onosproject.yangutils.datamodel.javadatamodel
+ .JavaQualifiedTypeInfoContainer;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import static org.onosproject.yms.app.ydt.AppType.YOB;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_INVOKE_METHOD;
+
+/**
+ * Represents a single instance leaf node handler in YANG object builder.
+ */
+class YobSingleInstanceLeafHandler extends YobHandler {
+
+ private static final Logger log =
+ LoggerFactory.getLogger(YobSingleInstanceLeafHandler.class);
+
+ @Override
+ public void createYangBuilderObject(YdtExtendedContext curYdtNode,
+ YdtExtendedContext rootYdtNode,
+ YangSchemaRegistry registry) {
+ // For single instance leaf no need to create an object.
+ }
+
+ @Override
+ public void buildObjectFromBuilder(YdtExtendedContext ydtNode,
+ YdtExtendedContext ydtRootNode,
+ YangSchemaRegistry schemaRegistry) {
+ // For single instance leaf no need to build an object.
+ }
+
+ @Override
+ public void setObjectInParent(YdtExtendedContext leafNode,
+ YangSchemaRegistry schemaRegistry) {
+ Class<?> parentBldrClass = null;
+ YangSchemaNode yangSchemaNode = leafNode.getYangSchemaNode();
+ YdtExtendedContext parentYdtNode =
+ (YdtExtendedContext) leafNode.getParent();
+ YobWorkBench parentYobWorkBench =
+ (YobWorkBench) parentYdtNode.getAppInfo(YOB);
+ String value = leafNode.getValue();
+
+ try {
+ String setterInParent = yangSchemaNode.getJavaAttributeName();
+ Object parentBuilderObject = parentYobWorkBench
+ .getParentBuilder(leafNode, schemaRegistry);
+ parentBldrClass = parentBuilderObject.getClass();
+ Field leafName = parentBldrClass.getDeclaredField(setterInParent);
+ Method parentSetterMethod = parentBldrClass
+ .getDeclaredMethod(setterInParent, leafName.getType());
+ JavaQualifiedTypeInfoContainer javaQualifiedType =
+ (JavaQualifiedTypeInfoContainer) yangSchemaNode;
+ YangType<?> yangType = ((YangLeaf) javaQualifiedType).getDataType();
+ setDataFromStringValue(yangType, value, parentSetterMethod,
+ parentBuilderObject, leafNode);
+ } catch (NoSuchMethodException | InvocationTargetException |
+ IllegalAccessException | NoSuchFieldException e) {
+ log.error(FAIL_TO_INVOKE_METHOD + parentBldrClass.getName());
+ }
+ }
+}
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
new file mode 100644
index 0000000..89720f4
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/YobWorkBench.java
@@ -0,0 +1,392 @@
+/*
+ * 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.yangutils.datamodel.RpcNotificationContainer;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeContextInfo;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.yob.exception.YobExceptions;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.util.HashMap;
+import java.util.Map;
+
+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_TO;
+import static org.onosproject.yms.app.yob.YobConstants.BUILD;
+import static org.onosproject.yms.app.yob.YobConstants.DEFAULT;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_BUILD;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_GET_FIELD;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_GET_METHOD;
+import static org.onosproject.yms.app.yob.YobConstants.FAIL_TO_INVOKE_METHOD;
+import static org.onosproject.yms.app.yob.YobConstants.HAS_NO_CHILD;
+import static org.onosproject.yms.app.yob.YobConstants.OPERATION_TYPE;
+import static org.onosproject.yms.app.yob.YobConstants.OP_PARAM;
+import static org.onosproject.yms.app.yob.YobConstants.OP_TYPE;
+import static org.onosproject.yms.app.yob.YobConstants.PERIOD;
+import static org.onosproject.yms.app.yob.YobConstants.SET_OP_TYPE_FAIL;
+import static org.onosproject.yms.app.yob.YobConstants.VALUE_OF;
+import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_NODE;
+
+/**
+ * Represents the YANG object builder's work bench corresponding to a YANG data
+ * tree node.
+ */
+class YobWorkBench {
+
+ private static final Logger log
+ = LoggerFactory.getLogger(YobWorkBench.class);
+
+ /**
+ * Class loader to be used to load the class.
+ */
+ private ClassLoader classLoader;
+
+ /**
+ * Map of the non schema descendant objects.
+ */
+ private Map<YangSchemaNodeIdentifier, YobWorkBench> attributeMap
+ = new HashMap<>();
+
+ /**
+ * Reference for data-model schema node.
+ */
+ private YangSchemaNode yangSchemaNode;
+
+ /**
+ * builder object or the built object corresponding to the current schema
+ * node.
+ */
+ private YobBuilderOrBuiltObject builderOrBuiltObject;
+
+ /**
+ * Setter method to be used in parent builder.
+ */
+ private String setterInParent;
+
+ /**
+ * Returns the builder container with the mapping schema being initialized.
+ *
+ * @param yangSchemaNode mapping schema node
+ * @param classLoader class loader
+ * @param qualifiedClassName qualified class name
+ * @param setterInParent setter method in parent
+ */
+ YobWorkBench(YangSchemaNode yangSchemaNode, ClassLoader classLoader,
+ String qualifiedClassName, String setterInParent) {
+ this.yangSchemaNode = yangSchemaNode;
+ this.classLoader = classLoader;
+ this.setterInParent = setterInParent;
+ this.builderOrBuiltObject
+ = new YobBuilderOrBuiltObject(qualifiedClassName, classLoader);
+ }
+
+ /**
+ * 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 childNode child YDT node
+ * @param registry schema registry
+ * @return parent builder object
+ * @throws YobExceptions schema node does not have child
+ */
+ Object getParentBuilder(YdtExtendedContext childNode,
+ YangSchemaRegistry registry) {
+
+ // Descendant schema node for whom the builder is required.
+ YangSchemaNodeIdentifier targetNode = childNode
+ .getYangSchemaNode().getYangSchemaNodeIdentifier();
+
+ //Current builder container
+ YobWorkBench curWorkBench = this;
+
+ //Current Schema node context
+ YangSchemaNodeContextInfo schemaContext;
+ do {
+
+ try {
+ //Find the new schema context node.
+ schemaContext = curWorkBench.yangSchemaNode.getChildSchema(
+ targetNode);
+
+ } catch (DataModelException e) {
+ throw new YobExceptions(yangSchemaNode.getName() +
+ HAS_NO_CHILD +
+ targetNode.getName());
+ }
+
+ //If the descendant schema node is in switched context
+ if (schemaContext.getContextSwitchedNode() != null) {
+
+ //check if the descendant builder container is already available
+ YobWorkBench childWorkBench
+ = curWorkBench.attributeMap.get(targetNode);
+
+ if (childWorkBench == null) {
+ YobWorkBench newWorkBench = getNewChildWorkBench(
+ schemaContext, targetNode, curWorkBench, registry);
+
+ //TODO: When choice and case support is added, confirm with
+ // UT, the workbench is for case and not for choice
+
+ curWorkBench.attributeMap.put(targetNode, newWorkBench);
+ curWorkBench = newWorkBench;
+ } else {
+ curWorkBench = childWorkBench;
+ }
+ }
+
+ } while (schemaContext.getContextSwitchedNode() != null);
+
+ return curWorkBench.builderOrBuiltObject.getBuilderObject();
+ }
+
+ /**
+ * Creates a new builder container object corresponding to a context
+ * switch schema node.
+ *
+ * @param childContext schema context of immediate child
+ * @param targetNode final node whose parent builder is
+ * required
+ * @param curWorkBench current context builder container
+ * @param registry schema registry
+ * @return new builder container object corresponding to a context
+ * switch schema node
+ */
+ private YobWorkBench getNewChildWorkBench(
+ YangSchemaNodeContextInfo childContext,
+ YangSchemaNodeIdentifier targetNode, YobWorkBench curWorkBench,
+ YangSchemaRegistry registry) {
+
+ YangSchemaNode ctxSwitchedNode = childContext.getContextSwitchedNode();
+
+ /*This is the first child trying to set its object in the
+ current context. */
+ String setterInParent = ctxSwitchedNode.getJavaAttributeName();
+
+ /* If current switched context is choice, then case class needs to be
+ used. */
+ if (ctxSwitchedNode.getYangSchemaNodeType() == YANG_CHOICE_NODE) {
+ try {
+ childContext = ctxSwitchedNode.getChildSchema(targetNode);
+ } catch (DataModelException e) {
+ throw new YobExceptions(yangSchemaNode.getName() +
+ HAS_NO_CHILD +
+ targetNode.getName());
+ }
+ }
+
+ ClassLoader newClassesLoader = getTargetClassLoader(
+ curWorkBench.classLoader, childContext, registry);
+
+ return new YobWorkBench(ctxSwitchedNode, newClassesLoader,
+ getQualifiedDefaultClassName(
+ childContext.getSchemaNode()),
+ setterInParent);
+ }
+
+ /**
+ * Returns the qualified default / op param class.
+ *
+ * @param schemaNode schema node of the required class
+ * @return qualified default / op param class name
+ */
+ static String getQualifiedDefaultClassName(YangSchemaNode schemaNode) {
+ String packageName = schemaNode.getJavaPackage();
+ String className = getCapitalCase(
+ schemaNode.getJavaClassNameOrBuiltInType());
+
+ if (schemaNode instanceof RpcNotificationContainer) {
+ return packageName + PERIOD + className + OP_PARAM;
+ }
+
+ return packageName + PERIOD + DEFAULT + className;
+ }
+
+ /**
+ * Returns the class loader to be used for the switched context schema node.
+ *
+ * @param currentClassLoader current context class loader
+ * @param switchedContext switched context
+ * @param registry schema registry
+ * @return class loader to be used for the switched context schema node
+ */
+ private ClassLoader getTargetClassLoader(
+ ClassLoader currentClassLoader,
+ YangSchemaNodeContextInfo switchedContext,
+ YangSchemaRegistry registry) {
+ YangSchemaNode augmentSchemaNode = switchedContext.getSchemaNode();
+ if (augmentSchemaNode.getYangSchemaNodeType() ==
+ YANG_AUGMENT_NODE) {
+ YangSchemaNode parentSchemaNode =
+ ((YangNode) augmentSchemaNode).getParent();
+
+ Class<?> regClass = registry.getRegisteredClass(
+ parentSchemaNode, getCapitalCase(
+ parentSchemaNode.getJavaClassNameOrBuiltInType()));
+ return regClass.getClassLoader();
+ }
+
+ return currentClassLoader;
+ }
+
+ /**
+ * Set the operation type attribute and build the object from the builder
+ * object, by invoking the build method.
+ *
+ * @param ydtNode data tree node
+ * @param ydtRootNode root node
+ */
+ void buildObject(YdtExtendedContext ydtNode,
+ YdtExtendedContext ydtRootNode) {
+ Object builderObject = builderOrBuiltObject.getBuilderObject();
+ Class<?> defaultBuilderClass = builderOrBuiltObject.yangBuilderClass;
+ Class<?> interfaceClass = builderOrBuiltObject.yangDefaultClass;
+ Object operationType;
+
+ // Setting the value into YANG node operation type from ydtContext
+ // operation type.
+ try {
+ 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(SET_OP_TYPE_FAIL);
+ throw new YobExceptions(SET_OP_TYPE_FAIL);
+ }
+
+
+ // Invoking the build method to get built object from build method.
+ try {
+ Method method = defaultBuilderClass.getDeclaredMethod(BUILD);
+ if (method == null) {
+ log.error(FAIL_TO_GET_METHOD + defaultBuilderClass.getName());
+ throw new YobExceptions(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(FAIL_TO_BUILD + defaultBuilderClass.getName());
+ throw new YobExceptions(FAIL_TO_BUILD +
+ defaultBuilderClass.getName());
+ }
+
+ // The current ydt context node and root node are same then return.
+ if (!ydtNode.equals(ydtRootNode)) {
+ invokeSetObjectInParent(ydtNode);
+ }
+ }
+
+ /**
+ * Sets the YANG built object in corresponding parent class method.
+ *
+ * @param ydtNode ydtExtendedContext is used to get application
+ * related information maintained in YDT
+ */
+ private void invokeSetObjectInParent(YdtExtendedContext ydtNode) {
+ Class<?> classType = null;
+ Method method;
+
+ Object objectToSetInParent = builderOrBuiltObject.getBuiltObject();
+
+ YdtExtendedContext parentNode = (YdtExtendedContext) ydtNode
+ .getParent();
+ if (parentNode != null) {
+ YobWorkBench parentYobWorkBench = (YobWorkBench)
+ parentNode.getAppInfo(YOB);
+ Object parentBuilderObject = parentYobWorkBench
+ .builderOrBuiltObject.getBuilderObject();
+
+ Class<?> parentBuilderClass = parentBuilderObject.getClass();
+ String parentBuilderClassName = parentBuilderClass.getName();
+
+ try {
+ Field fieldName = parentBuilderClass
+ .getDeclaredField(setterInParent);
+ if (fieldName != null) {
+ classType = fieldName.getType();
+ }
+
+ if (ydtNode.getYdtType() == MULTI_INSTANCE_NODE) {
+ if (fieldName != null) {
+ ParameterizedType genericListType =
+ (ParameterizedType) fieldName.getGenericType();
+ classType = (Class<?>) genericListType
+ .getActualTypeArguments()[0];
+ }
+ method = parentBuilderClass.getDeclaredMethod(
+ ADD_TO + getCapitalCase(setterInParent), classType);
+ } else {
+ method = parentBuilderClass.getDeclaredMethod(
+ setterInParent, classType);
+ }
+
+ if (method != null) {
+ method.invoke(parentBuilderObject, objectToSetInParent);
+ }
+ } catch (NoSuchFieldException e) {
+ log.error(FAIL_TO_GET_FIELD + parentBuilderClassName);
+ } catch (NoSuchMethodException e) {
+ log.error(FAIL_TO_GET_METHOD + parentBuilderClassName);
+ } catch (InvocationTargetException | IllegalAccessException e) {
+ log.error(FAIL_TO_INVOKE_METHOD + parentBuilderClassName);
+ }
+ }
+ ydtNode.addAppInfo(YOB, this);
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/exception/YobExceptions.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/exception/YobExceptions.java
new file mode 100644
index 0000000..b7e5bb5
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/exception/YobExceptions.java
@@ -0,0 +1,35 @@
+/*
+ * 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.exception;
+
+/**
+ * Represents base class for exceptions in YOB operations.
+ */
+public class YobExceptions
+ extends RuntimeException {
+
+ private static final long serialVersionUID = 20160211L;
+
+ /**
+ * Creates a new YOB exception with given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public YobExceptions(String message) {
+ super(message);
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/exception/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/exception/package-info.java
new file mode 100644
index 0000000..bfd1528
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/exception/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * YANG object builder exceptions.
+ */
+package org.onosproject.yms.app.yob.exception;
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/package-info.java
new file mode 100755
index 0000000..9c63d69
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/yob/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Provides implementation of YANG object builder. YOB handles creation of YANG
+ * modeled objects from YDT.
+ */
+package org.onosproject.yms.app.yob;
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobBitTest.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobBitTest.java
new file mode 100644
index 0000000..6b4b526
--- /dev/null
+++ b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobBitTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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 java.io.IOException;
+
+public class YobBitTest {
+
+/*
+ BINARY
+
+ Positive scenario
+ input with position 0
+ input with position 1
+ input with position 2
+*/
+
+
+ @Test
+ public void positiveTest() throws IOException {
+
+ //TODO for getYangObject
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobBooleanTest.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobBooleanTest.java
new file mode 100644
index 0000000..83ce3f6
--- /dev/null
+++ b/apps/yms/app/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.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.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+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) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobDecimal64Test.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobDecimal64Test.java
new file mode 100644
index 0000000..b069ad2
--- /dev/null
+++ b/apps/yms/app/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.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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+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 (NoSuchFieldException | IllegalAccessException e) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobEmptyTest.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobEmptyTest.java
new file mode 100644
index 0000000..55c416e
--- /dev/null
+++ b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobEmptyTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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;
+
+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(false, invalidInterval.get(booleanList.get(0)));
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobEnumTest.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobEnumTest.java
new file mode 100644
index 0000000..c479afa
--- /dev/null
+++ b/apps/yms/app/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.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;
+
+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 (NoSuchFieldException | IllegalAccessException e) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobIetfNetworkTest.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobIetfNetworkTest.java
new file mode 100644
index 0000000..462dccb
--- /dev/null
+++ b/apps/yms/app/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.YangRequestWorkBench;
+import org.onosproject.yms.app.ydt.YdtExtendedContext;
+import org.onosproject.yms.app.ydt.YdtTestUtils;
+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/app/src/test/java/org/onosproject/yms/app/yob/YobInteger16Test.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobInteger16Test.java
new file mode 100644
index 0000000..39281b7
--- /dev/null
+++ b/apps/yms/app/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.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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+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 (NoSuchFieldException | IllegalAccessException e) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobInteger32Test.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobInteger32Test.java
new file mode 100644
index 0000000..d97f783
--- /dev/null
+++ b/apps/yms/app/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.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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+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 (NoSuchFieldException | IllegalAccessException e) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobInteger64Test.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobInteger64Test.java
new file mode 100644
index 0000000..a3ee166
--- /dev/null
+++ b/apps/yms/app/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.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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+
+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) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobInteger8Test.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobInteger8Test.java
new file mode 100644
index 0000000..11bd8e5
--- /dev/null
+++ b/apps/yms/app/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.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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+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 (NoSuchFieldException | IllegalAccessException e) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobListTest.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobListTest.java
new file mode 100644
index 0000000..47ec8ef
--- /dev/null
+++ b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobListTest.java
@@ -0,0 +1,131 @@
+/*
+ * 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.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.assertTrue;
+import static org.junit.Assert.fail;
+
+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);
+ assertEquals(true, listwithcontainer.isEmpty());
+ 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) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+
+ @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);
+ assertEquals(true, listwithoutcontainer.isEmpty());
+ 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) {
+ fail("No such field or illegal access exception: " + e);
+ }
+ }
+}
diff --git a/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobLogisticsManagerTest.java b/apps/yms/app/src/test/java/org/onosproject/yms/app/yob/YobLogisticsManagerTest.java
new file mode 100644
index 0000000..c66f555
--- /dev/null
+++ b/apps/yms/app/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.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.io.IOException;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+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("onosYangNodeOperationType");
+ field.setAccessible(true);
+ onosYangNodeOperationType.setAccessible(true);
+ try {
+ assertEquals("abc", field.get(yangObject).toString());
+ assertEquals("MERGE", onosYangNodeOperationType
+ .get(yangObject).toString());
+ } catch (IllegalAccessException e) {
+ fail("Illegal access exception: " + e);
+ }
+ } catch (NoSuchFieldException e) {
+ fail("No such field exception: " + e);
+ }
+ }
+
+ if (aClass.getSimpleName().equals(
+ "MerchandisersupervisorOpParam")) {
+ try {
+ Field field = aClass.getDeclaredField("supervisor");
+ field.setAccessible(true);
+ try {
+ assertEquals("abc", field.get(yangObject).toString());
+ } catch (IllegalAccessException e) {
+ fail("Illegal access exception: " + e);
+ }
+ } catch (NoSuchFieldException e) {
+ fail("No such field found exception: " + e);
+ }
+ }
+
+ 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) {
+ fail("Illegal access exception: " + e);
+ }
+ } catch (NoSuchFieldException e) {
+ fail("No such field exception: " + e);
+ }
+ }
+ childCtx = childCtx.getNextSibling();
+ }
+ }
+}