[ONOS-6783] Data type handling in Data Node
Change-Id: I5d27e169f95e2a5af89a866c1d34281201c73c56
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DataTreeBuilderHelper.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DataTreeBuilderHelper.java
index a33e41f..667f958 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DataTreeBuilderHelper.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DataTreeBuilderHelper.java
@@ -22,16 +22,12 @@
import org.onosproject.yang.compiler.datamodel.YangAugmentableNode;
import org.onosproject.yang.compiler.datamodel.YangCase;
import org.onosproject.yang.compiler.datamodel.YangChoice;
-import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangLeafList;
-import org.onosproject.yang.compiler.datamodel.YangLeafRef;
import org.onosproject.yang.compiler.datamodel.YangLeavesHolder;
import org.onosproject.yang.compiler.datamodel.YangList;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
-import org.onosproject.yang.compiler.datamodel.YangType;
-import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.InnerNode;
import org.onosproject.yang.model.LeafNode;
@@ -39,7 +35,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -49,27 +44,26 @@
import static org.onosproject.yang.compiler.datamodel.TraversalType.ROOT;
import static org.onosproject.yang.compiler.datamodel.TraversalType.SIBLING;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.nonEmpty;
-import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
+import static org.onosproject.yang.runtime.RuntimeHelper.DEFAULT_CAPS;
+import static org.onosproject.yang.runtime.RuntimeHelper.PERIOD;
+import static org.onosproject.yang.runtime.RuntimeHelper.getCapitalCase;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getAttributeOfObject;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getAugmentObject;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getClassLoaderForAugment;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getInterfaceClassFromImplClass;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getJavaName;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getLeafListObject;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getLeafObject;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getParentObjectOfNode;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getStringFromType;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isAugmentNode;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isMultiInstanceNode;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isNodeProcessCompleted;
import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isNonProcessableNode;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isTypePrimitive;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isValueOrSelectLeafSet;
-import static org.onosproject.yang.runtime.RuntimeHelper.DEFAULT_CAPS;
-import static org.onosproject.yang.runtime.RuntimeHelper.PERIOD;
-import static org.onosproject.yang.runtime.RuntimeHelper.getCapitalCase;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isTypeEmpty;
/**
@@ -79,7 +73,6 @@
public class DataTreeBuilderHelper {
private static final String TRUE = "true";
- private static final String IS_LEAF_VALUE_SET_METHOD = "isLeafValueSet";
private static final String AUGMENTATIONS = "augmentations";
private static final String FALSE = "false";
@@ -759,8 +752,18 @@
} catch (NoSuchMethodException e) {
throw new ModelConvertorException(e);
}
-
- addLeafWithValue(yangNode, yangLeaf, parentObj, leafType);
+ Object obj = getLeafObject(yangNode, yangLeaf, parentObj,
+ leafType, false);
+ if (obj != null) {
+ if (isTypeEmpty(yangLeaf.getDataType())) {
+ String empty = String.valueOf(obj);
+ if (!empty.equals(TRUE)) {
+ continue;
+ }
+ obj = null;
+ }
+ createLeafNode(yangLeaf, obj);
+ }
}
}
}
@@ -815,43 +818,20 @@
throw new ModelConvertorException(e);
}
if (obj != null) {
- return addLeafListValue(yangNode, parentObj, leafList, obj);
- }
- return null;
- }
-
- /**
- * Adds the leaf list value to the data tree builder by taking the string
- * value from the data type.
- *
- * @param yangNode YANG node
- * @param parentObj parent object
- * @param leafList YANG leaf list
- * @param obj list of objects
- */
- List<DataNode.Builder> addLeafListValue(
- YangSchemaNode yangNode, Object parentObj,
- YangLeafList leafList, List<Object> obj) {
-
- Set<String> leafListVal = new LinkedHashSet<>();
- boolean isEmpty = false;
- for (Object object : obj) {
- String val = getStringFromType(yangNode, parentObj,
- getJavaName(leafList), object,
- leafList.getDataType());
- isEmpty = isTypeEmpty(val, leafList.getDataType());
- if (isEmpty) {
- if (val.equals(TRUE)) {
- addLeafList(leafListVal, leafList);
+ Set<Object> objects = getLeafListObject(yangNode, leafList,
+ parentObj, obj);
+ if (!objects.isEmpty()) {
+ Object o = objects.iterator().next();
+ if (isTypeEmpty(leafList.getDataType())) {
+ objects.clear();
+ String empty = String.valueOf(o);
+ if (!empty.equals(TRUE)) {
+ return null;
+ }
+ objects.add(null);
}
- break;
+ return addLeafList(objects, leafList);
}
- if (!val.equals("")) {
- leafListVal.add(val);
- }
- }
- if (!isEmpty && !leafListVal.isEmpty()) {
- return addLeafList(leafListVal, leafList);
}
return null;
}
@@ -863,13 +843,13 @@
* @param leafListVal set of values
* @param leafList YANG leaf list
*/
- private List<DataNode.Builder> addLeafList(Set<String> leafListVal, YangLeafList
- leafList) {
+ List<DataNode.Builder> addLeafList(Set<Object> leafListVal,
+ YangLeafList leafList) {
if (extBuilder != null) {
- for (String val : leafListVal) {
+ for (Object val : leafListVal) {
DataNode.Builder leaf = extBuilder.createChildBuilder(
- leafList.getName(), leafList.getNameSpace().getModuleNamespace(),
- val);
+ leafList.getName(), leafList.getNameSpace()
+ .getModuleNamespace(), val);
leaf.type(MULTI_INSTANCE_LEAF_VALUE_NODE);
leaf.addLeafListValue(val);
extBuilder = leaf.exitNode();
@@ -878,10 +858,10 @@
}
//In case of root node leaf lists.
List<DataNode.Builder> builders = new ArrayList<>();
- for (String val : leafListVal) {
+ for (Object val : leafListVal) {
DataNode.Builder leaf = LeafNode.builder(
- leafList.getName(), leafList.getNameSpace().getModuleNamespace())
- .value(val);
+ leafList.getName(), leafList.getNameSpace()
+ .getModuleNamespace()).value(val);
leaf.type(MULTI_INSTANCE_LEAF_VALUE_NODE);
leaf.addLeafListValue(val);
builders.add(leaf);
@@ -917,92 +897,17 @@
}
/**
- * Adds leaf to data tree when value is present. For primitive types, in
- * order to avoid default values, the value select is set or not is checked and
- * then added.
- *
- * @param holder leaf holder
- * @param yangLeaf YANG leaf node
- * @param parentObj leaf holder object
- * @param leafType object of leaf type
- */
- DataNode.Builder addLeafWithValue(YangSchemaNode holder, YangLeaf yangLeaf,
- Object parentObj, Object leafType) {
- String fieldValue = null;
- if (isTypePrimitive(yangLeaf.getDataType())) {
- fieldValue = getLeafValueFromValueSetFlag(holder, parentObj,
- yangLeaf, leafType);
- /*
- * Checks the object is present or not, when type is
- * non-primitive. And adds the value from the respective data type.
- */
- } else if (leafType != null) {
- fieldValue = getStringFromType(holder, parentObj,
- getJavaName(yangLeaf), leafType,
- yangLeaf.getDataType());
- }
-
- if (ModelConverterUtil.nonEmpty(fieldValue)) {
- boolean isEmpty = isTypeEmpty(fieldValue,
- yangLeaf.getDataType());
- if (isEmpty) {
- if (!fieldValue.equals(TRUE)) {
- return null;
- }
- fieldValue = null;
- }
-
- //Create leaf node.
- return createLeafNode(yangLeaf, fieldValue);
- }
- return null;
- }
-
- /**
- * Returns the value as true if direct or referred type from leaf-ref or
- * derived points to empty data type; false otherwise.
- *
- * @param fieldValue value of the leaf
- * @param dataType type of the leaf
- * @return true if type is empty; false otherwise.
- */
- private boolean isTypeEmpty(String fieldValue, YangType<?> dataType) {
- if (fieldValue.equals(TRUE) || fieldValue.equals(FALSE)) {
- switch (dataType.getDataType()) {
- case EMPTY:
- return true;
-
- case LEAFREF:
- YangLeafRef leafRef =
- (YangLeafRef) dataType.getDataTypeExtendedInfo();
- return isTypeEmpty(fieldValue,
- leafRef.getEffectiveDataType());
- case DERIVED:
- YangDerivedInfo info =
- (YangDerivedInfo) dataType
- .getDataTypeExtendedInfo();
- YangDataTypes type = info.getEffectiveBuiltInType();
- return type == EMPTY;
-
- default:
- return false;
- }
- }
- return false;
- }
-
- /**
* Creates data leaf node.
*
* @param yangLeaf YANG leaf
* @param val value for the leaf
*/
- private DataNode.Builder createLeafNode(YangLeaf yangLeaf, Object val) {
+ DataNode.Builder createLeafNode(YangLeaf yangLeaf, Object val) {
if (extBuilder != null) {
//Add leaf to key leaves.
if (yangLeaf.isKeyLeaf()) {
- extBuilder.addKeyLeaf(yangLeaf.getName(), yangLeaf.getNameSpace()
- .getModuleNamespace(), val);
+ extBuilder.addKeyLeaf(yangLeaf.getName(), yangLeaf
+ .getNameSpace().getModuleNamespace(), val);
}
//build leaf node and add to parent node.
DataNode.Builder leaf = extBuilder.createChildBuilder(
@@ -1020,35 +925,6 @@
}
/**
- * Returns the value of type, after checking the value leaf flag. If the
- * flag is set, then it takes the value else returns null.
- *
- * @param holder leaf holder
- * @param parentObj parent object
- * @param yangLeaf YANG leaf node
- * @param leafType object of leaf type
- * @return value of type
- */
- private String getLeafValueFromValueSetFlag(YangSchemaNode holder, Object parentObj,
- YangLeaf yangLeaf, Object leafType) {
-
- String valueOfLeaf;
- try {
- valueOfLeaf = isValueOrSelectLeafSet(holder, parentObj,
- getJavaName(yangLeaf),
- IS_LEAF_VALUE_SET_METHOD);
- } catch (NoSuchMethodException e) {
- throw new ModelConvertorException(e);
- }
- if (valueOfLeaf.equals(TRUE)) {
- return getStringFromType(holder, parentObj,
- getJavaName(yangLeaf), leafType,
- yangLeaf.getDataType());
- }
- return null;
- }
-
- /**
* Returns the node info which can be processed, by eliminating the nodes
* which need not to be processed at normal conditions such as RPC,
* notification and augment.
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilder.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilder.java
index bef158e..31e5147 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilder.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilder.java
@@ -33,6 +33,7 @@
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.DefaultResourceData;
+import org.onosproject.yang.model.DefaultResourceData.Builder;
import org.onosproject.yang.model.InnerNode;
import org.onosproject.yang.model.LeafModelObject;
import org.onosproject.yang.model.LeafNode;
@@ -44,6 +45,7 @@
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import static org.onosproject.yang.compiler.datamodel.YangSchemaNodeType.YANG_NON_DATA_NODE;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.nonEmpty;
@@ -53,11 +55,15 @@
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getAttributeOfObject;
-import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getJavaName;
import static org.onosproject.yang.runtime.RuntimeHelper.DEFAULT_CAPS;
import static org.onosproject.yang.runtime.RuntimeHelper.PERIOD;
import static org.onosproject.yang.runtime.RuntimeHelper.getCapitalCase;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.TRUE;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getAttributeOfObject;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getJavaName;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getLeafListObject;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.getLeafObject;
+import static org.onosproject.yang.runtime.impl.ModelConverterUtil.isTypeEmpty;
/**
* Representation of data tree builder which generates YANG data tree from the
@@ -106,7 +112,7 @@
List<ModelObject> modelObjects = modelData.modelObjects();
ModelObjectId id = modelData.identifier();
- DefaultResourceData.Builder rscData = DefaultResourceData.builder();
+ Builder rscData = DefaultResourceData.builder();
//Create resource identifier.
ModIdToRscIdConverter converter = new ModIdToRscIdConverter(reg);
@@ -169,7 +175,7 @@
*/
private void processDataNodeConversion(
YangNode curNode, DataTreeBuilderHelper helper,
- DefaultResourceData.Builder rscData, Object curObj) {
+ Builder rscData, Object curObj) {
if (curNode == null) {
return;
}
@@ -209,7 +215,7 @@
* @return input/output node
*/
private YangSchemaNode handleRpcChild(
- Object obj, YangNode parent, DefaultResourceData.Builder rscData) {
+ Object obj, YangNode parent, Builder rscData) {
if (obj != null && parent != null) {
//process all the node which are in data model tree.
String name = obj.getClass().getName();
@@ -410,54 +416,110 @@
/**
* Process leaf and leaf list information.
*
- * @param rootNode root node
- * @param rscData resource data
+ * @param holder holder node
+ * @param rscData resource data
+ * @param lObj leaf model object
*/
- private void processLeafObj(YangSchemaNode rootNode,
- DefaultResourceData.Builder rscData,
- LeafModelObject rootObj) {
+ private void processLeafObj(YangSchemaNode holder, Builder rscData,
+ LeafModelObject lObj) {
//handle leaf nodes.
- YangLeavesHolder holder = (YangLeavesHolder) rootNode;
- if (rootObj.leafIdentifier() != null) {
- String name = rootObj.leafIdentifier().toString().toLowerCase();
- List<Object> values = rootObj.values();
+ YangLeavesHolder lHolder = (YangLeavesHolder) holder;
+ if (lObj.leafIdentifier() != null) {
+ String name = lObj.leafIdentifier().toString().toLowerCase();
+ List<Object> values = lObj.values();
// handle all leaf nodes and add their data nodes to resource data.
- List<YangLeaf> leaves = holder.getListOfLeaf();
+ List<YangLeaf> leaves = lHolder.getListOfLeaf();
if (nonEmpty(leaves)) {
- for (YangLeaf leaf : leaves) {
- //Add node for leaf with value.
- if (name.equals(leaf.getJavaAttributeName().toLowerCase())) {
- DataNode node = LeafNode.builder(leaf.getName(), leaf
- .getNameSpace().getModuleNamespace())
- .value(values.get(0))
- .type(SINGLE_INSTANCE_LEAF_VALUE_NODE).build();
- rscData.addDataNode(node);
- break;
- }
- }
+ updateLeafDataNode(name, leaves, values.get(0), rscData,
+ holder, lObj);
}
- // handle all leaf list nodes and add their data nodes to resource data.
- List<YangLeafList> leafLists = holder.getListOfLeafList();
+ // handle all leaf-list nodes and add their data nodes to
+ // resource data.
+ List<YangLeafList> leafLists = lHolder.getListOfLeafList();
if (nonEmpty(leafLists)) {
- for (YangLeafList leafList : leafLists) {
- if (name.equals(leafList.getJavaAttributeName().toLowerCase())) {
- //for leaf list we need to add multi instance of leaf
- // node.
- for (Object o : values) {
- DataNode node = LeafNode
- .builder(leafList.getName(),
- leafList.getNameSpace().getModuleNamespace())
- .value(o)
- .type(MULTI_INSTANCE_LEAF_VALUE_NODE).build();
- rscData.addDataNode(node);
- }
- break;
- }
- }
+ updateLeafListDataNode(name, leafLists, values, rscData,
+ holder, lObj);
}
}
}
+ /**
+ * Updates the processed leaf-list objects from the leaf-list type to the
+ * data node.
+ *
+ * @param name leaf-list name
+ * @param leafLists YANG leaf-lists
+ * @param values leaf-list objects
+ * @param rscData data node
+ * @param holder leaf-list holder
+ * @param lObj leaf model object
+ */
+ private void updateLeafListDataNode(String name, List<YangLeafList> leafLists,
+ List<Object> values, Builder rscData,
+ YangSchemaNode holder, LeafModelObject lObj) {
+ for (YangLeafList leafList : leafLists) {
+ if (name.equals(leafList.getJavaAttributeName().toLowerCase())) {
+ Set<Object> objects = getLeafListObject(holder, leafList,
+ lObj, values);
+ if (!objects.isEmpty()) {
+ Object o = objects.iterator().next();
+ if (isTypeEmpty(leafList.getDataType())) {
+ objects.clear();
+ String empty = String.valueOf(o);
+ if (!empty.equals(TRUE)) {
+ break;
+ }
+ objects.add(null);
+ }
+ for (Object obj : objects) {
+ DataNode node = LeafNode
+ .builder(leafList.getName(), leafList
+ .getNameSpace().getModuleNamespace())
+ .value(obj)
+ .type(MULTI_INSTANCE_LEAF_VALUE_NODE).build();
+ rscData.addDataNode(node);
+ }
+ }
+ break;
+ }
+ }
+ }
+
+ /**
+ * Updates the processed leaf object from the leaf type to the data node.
+ *
+ * @param lName leaf name
+ * @param leaves YANG leaves
+ * @param val leaf object
+ * @param rscData data node
+ * @param rootNode holder node
+ * @param lObj leaf model object
+ */
+ private void updateLeafDataNode(String lName, List<YangLeaf> leaves,
+ Object val, Builder rscData,
+ YangSchemaNode rootNode, LeafModelObject lObj) {
+ for (YangLeaf leaf : leaves) {
+ if (lName.equals(leaf.getJavaAttributeName().toLowerCase())) {
+ Object obj = getLeafObject(rootNode, leaf, lObj,
+ val, true);
+ if (obj != null) {
+ if (isTypeEmpty(leaf.getDataType())) {
+ String empty = String.valueOf(obj);
+ if (!empty.equals(TRUE)) {
+ break;
+ }
+ obj = null;
+ }
+ DataNode node = LeafNode.builder(leaf.getName(), leaf
+ .getNameSpace().getModuleNamespace())
+ .value(obj)
+ .type(SINGLE_INSTANCE_LEAF_VALUE_NODE).build();
+ rscData.addDataNode(node);
+ break;
+ }
+ }
+ }
+ }
/**
* Process single instance/multi instance nodes and build there data nodes.
@@ -494,7 +556,7 @@
* @param yangObj object for node
*/
private void processModelObjects(DataTreeBuilderHelper modYo, YangSchemaNode lastIndexNode,
- DefaultResourceData.Builder rscData, Object
+ Builder rscData, Object
yangObj) {
//Process all the leaf nodes of root node.
processRootLeafInfo(modYo, lastIndexNode, rscData, yangObj);
@@ -510,59 +572,114 @@
/**
* Process leaf and leaf list information.
*
- * @param modYo module builder
- * @param rootNode root node
- * @param rscData resource data
+ * @param modYo module builder
+ * @param holder root node
+ * @param rscData resource data
*/
- private void processRootLeafInfo(
- DataTreeBuilderHelper modYo, YangSchemaNode rootNode,
- DefaultResourceData.Builder rscData, Object rootObj) {
+ private void processRootLeafInfo(DataTreeBuilderHelper modYo,
+ YangSchemaNode holder, Builder rscData,
+ Object hObj) {
//handle leaf nodes.
- YangLeavesHolder holder = (YangLeavesHolder) rootNode;
- if (rootNode instanceof YangCase) {
- if (((YangCase) rootNode).getParent().getParent() instanceof
+ YangLeavesHolder lHolder = (YangLeavesHolder) holder;
+ if (holder instanceof YangCase) {
+ if (((YangCase) holder).getParent().getParent() instanceof
RpcNotificationContainer) {
modYo.setExtBuilder(null);
}
}
// handle all leaf nodes and add their data nodes to resource data.
- List<YangLeaf> leaves = holder.getListOfLeaf();
- DataNode.Builder builder;
+ List<YangLeaf> leaves = lHolder.getListOfLeaf();
if (nonEmpty(leaves)) {
- for (YangLeaf leaf : leaves) {
- try {
- //Add node for leaf with value.
- builder = modYo.addLeafWithValue(
- rootNode, leaf, rootObj, getAttributeOfObject(
- rootObj, leaf.getJavaAttributeName()));
- addDataNode(builder, rscData);
- } catch (NoSuchMethodException e) {
- throw new ModelConvertorException("failed to create data node for " +
- "leaf " + leaf.getName());
- }
- }
+ updateLeaf(leaves, modYo, holder, hObj, rscData);
}
// handle all leaf list nodes and add their data nodes to resource data.
- List<YangLeafList> leafLists = holder.getListOfLeafList();
- List<DataNode.Builder> nodes;
+ List<YangLeafList> leafLists = lHolder.getListOfLeafList();
if (nonEmpty(leafLists)) {
- List<Object> obj;
- for (YangLeafList leafList : leafLists) {
- try {
- obj = (List<Object>) getAttributeOfObject(
- rootObj, getJavaName(leafList));
- if (obj != null) {
- nodes = modYo.addLeafListValue(rootNode, rootObj,
- leafList, obj);
+ updateLeafList(leafLists, modYo, holder, hObj, rscData);
+ }
+ }
+
+ /**
+ * Updates leaf values inside the holder node by taking the processed
+ * leaf object and checking for empty type.
+ *
+ * @param leafLists list of leaf-list
+ * @param modYo data tree builder
+ * @param holder leaf-list holder
+ * @param hObj holder object
+ * @param rscData resource data
+ */
+ private void updateLeafList(List<YangLeafList> leafLists,
+ DataTreeBuilderHelper modYo, YangSchemaNode holder,
+ Object hObj, Builder rscData) {
+ List<Object> obj;
+ List<DataNode.Builder> nodes;
+ for (YangLeafList leafList : leafLists) {
+ try {
+ obj = (List<Object>) getAttributeOfObject(
+ hObj, getJavaName(leafList));
+ if (obj != null) {
+ Set<Object> objects = getLeafListObject(holder, leafList,
+ hObj, obj);
+ if (!objects.isEmpty()) {
+ Object o = objects.iterator().next();
+ if (isTypeEmpty(leafList.getDataType())) {
+ objects.clear();
+ String empty = String.valueOf(o);
+ if (!empty.equals(TRUE)) {
+ continue;
+ }
+ objects.add(null);
+ }
+ nodes = modYo.addLeafList(objects, leafList);
if (nodes != null) {
for (DataNode.Builder node : nodes) {
rscData.addDataNode(node.build());
}
}
}
- } catch (NoSuchMethodException e) {
- throw new ModelConvertorException(e);
}
+ } catch (NoSuchMethodException e) {
+ throw new ModelConvertorException(e);
+ }
+ }
+ }
+
+ /**
+ * Updates leaf values inside the holder node by taking the processed
+ * leaf object and checking for empty type.
+ *
+ * @param leaves list of leaf
+ * @param modYo data tree builder
+ * @param holder leaf holder
+ * @param hObj holder object
+ * @param rscData resource data
+ */
+ private void updateLeaf(List<YangLeaf> leaves, DataTreeBuilderHelper modYo,
+ YangSchemaNode holder, Object hObj, Builder rscData) {
+ DataNode.Builder builder;
+ for (YangLeaf leaf : leaves) {
+ try {
+ Object leafObj = getAttributeOfObject(
+ hObj, leaf.getJavaAttributeName());
+ Object obj = getLeafObject(holder, leaf, hObj, leafObj,
+ false);
+
+ if (obj != null) {
+ if (isTypeEmpty(leaf.getDataType())) {
+ String empty = String.valueOf(obj);
+ if (!empty.equals(TRUE)) {
+ continue;
+ }
+ obj = null;
+ }
+ builder = modYo.createLeafNode(leaf, obj);
+ addDataNode(builder, rscData);
+ }
+ } catch (NoSuchMethodException e) {
+ throw new ModelConvertorException(
+ "Failed to create data node for leaf "
+ + leaf.getName());
}
}
}
@@ -578,7 +695,7 @@
*/
private void processRootLevelListNode(
DataTreeBuilderHelper helper, YangSchemaNode curRootNode,
- DefaultResourceData.Builder rscData, Object curRootObj) {
+ Builder rscData, Object curRootObj) {
YangNode curNode = ((YangNode) curRootNode).getChild();
DataTreeNodeInfo parentInfo = new DataTreeNodeInfo();
@@ -646,7 +763,7 @@
*/
private void processRootLevelSingleInNode(
DataTreeBuilderHelper helper, YangSchemaNode rootNode,
- DefaultResourceData.Builder rscData, Object rootObj) {
+ Builder rscData, Object rootObj) {
YangNode curNode = ((YangNode) rootNode).getChild();
@@ -723,7 +840,7 @@
* @return single instance node
*/
private YangNode verifyAndDoNotGetList(YangNode curNode, DataTreeBuilderHelper
- helper, DataTreeNodeInfo info, DefaultResourceData.Builder rscData) {
+ helper, DataTreeNodeInfo info, Builder rscData) {
if (curNode == null) {
return null;
}
@@ -762,7 +879,7 @@
*/
private YangNode processReCheckSibling(
YangNode curNode, DataTreeBuilderHelper helper, DataTreeNodeInfo info,
- DefaultResourceData.Builder rscData) {
+ Builder rscData) {
curNode = curNode.getNextSibling();
curNode = verifyAndDoNotGetList(curNode, helper, info, rscData);
return curNode;
@@ -778,7 +895,7 @@
*/
private void handleChoiceNode(
YangNode curNode, DataTreeNodeInfo info, DataTreeBuilderHelper helper,
- DefaultResourceData.Builder rscData) {
+ Builder rscData) {
// get the choice object.
Object childObj = helper.processChoiceNode(curNode, info);
YangNode tempNode = curNode;
@@ -820,7 +937,7 @@
*/
private void processCaseNode(
YangNode curNode, DataTreeNodeInfo info, DataTreeBuilderHelper helper,
- DefaultResourceData.Builder rscData) {
+ Builder rscData) {
Object childObj = helper.processCaseNode(curNode, info);
if (childObj != null) {
processModelObjects(helper, curNode, rscData, childObj);
@@ -839,7 +956,7 @@
*/
private void handleCaseNode(
YangNode curNode, DataTreeNodeInfo info, DataTreeBuilderHelper yo,
- DefaultResourceData.Builder rscData) {
+ Builder rscData) {
Object obj = info.getYangObject();
if (obj != null) {
@@ -854,7 +971,7 @@
* @param builder resource data builder
*/
private void addDataNode(DataNode.Builder node,
- DefaultResourceData.Builder builder) {
+ Builder builder) {
if (node != null) {
builder.addDataNode(node.build());
}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModelConverterUtil.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModelConverterUtil.java
index 9ffbedd..9324b89 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModelConverterUtil.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/ModelConverterUtil.java
@@ -20,8 +20,11 @@
import org.onosproject.yang.compiler.datamodel.TraversalType;
import org.onosproject.yang.compiler.datamodel.YangAugment;
import org.onosproject.yang.compiler.datamodel.YangCase;
+import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
import org.onosproject.yang.compiler.datamodel.YangIdentity;
import org.onosproject.yang.compiler.datamodel.YangIdentityRef;
+import org.onosproject.yang.compiler.datamodel.YangLeaf;
+import org.onosproject.yang.compiler.datamodel.YangLeafList;
import org.onosproject.yang.compiler.datamodel.YangLeafRef;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangNotification;
@@ -31,6 +34,7 @@
import org.onosproject.yang.compiler.datamodel.YangType;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.model.AtomicPath;
+import org.onosproject.yang.model.LeafSchemaContext;
import org.onosproject.yang.model.MultiInstanceLeaf;
import org.onosproject.yang.model.MultiInstanceNode;
import org.onosproject.yang.model.SingleInstanceLeaf;
@@ -39,8 +43,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
-import java.util.Base64;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -71,13 +75,15 @@
* Static attribute for string value having null.
*/
static final String STR_NULL = "null";
-
+ static final String FALSE = "false";
+ static final String TRUE = "true";
private static final int ONE = 1;
private static final String ENUM_LEAF_IDENTIFIER = "$LeafIdentifier";
private static final Set<YangDataTypes> PRIMITIVE_TYPES =
new HashSet<>(Arrays.asList(INT8, INT16, INT32, INT64, UINT8,
UINT16, UINT32, BOOLEAN, EMPTY));
private static final String TO_STRING = "toString";
+ private static final String IS_VAL_SET = "isLeafValueSet";
// No instantiation.
private ModelConverterUtil() {
@@ -214,19 +220,15 @@
}
/**
- * Returns the string true, if the leaf data is actually set; false
- * otherwise.
+ * Returns true, if the leaf data is actually set; false otherwise.
*
- * @param holder leaf holder
- * @param nodeObj object if the node
- * @param javaName java name of the leaf
- * @param methodName getter method name
- * @return string value of the boolean method
- * @throws NoSuchMethodException if the method is not present
+ * @param holder leaf holder
+ * @param nodeObj object if the node
+ * @param javaName java name of the leaf
+ * @return status of the value set flag
*/
- static String isValueOrSelectLeafSet(YangSchemaNode holder, Object nodeObj,
- String javaName, String methodName)
- throws NoSuchMethodException {
+ static boolean isLeafValueSet(YangSchemaNode holder, Object nodeObj,
+ String javaName) {
Class<?> nodeClass = nodeObj.getClass();
@@ -239,13 +241,13 @@
Class leafEnum;
try {
leafEnum = classLoader.loadClass(enumPackage);
- Method getterMethod = nodeClass.getMethod(methodName, leafEnum);
+ Method getterMethod = nodeClass.getMethod(IS_VAL_SET, leafEnum);
// Gets the value of the enum.
Enum<?> value = Enum.valueOf(leafEnum, javaName.toUpperCase());
// Invokes the method with the value of enum as param.
- return String.valueOf(getterMethod.invoke(nodeObj, value));
+ return (boolean) getterMethod.invoke(nodeObj, value);
} catch (IllegalAccessException | InvocationTargetException |
- ClassNotFoundException e) {
+ ClassNotFoundException | NoSuchMethodException e) {
throw new ModelConvertorException(e);
}
}
@@ -259,13 +261,15 @@
* @param name leaf/leaf-list name
* @param fieldObj object of the leaf/leaf-list field
* @param dataType type of the leaf/leaf-list
- * @return string value from the type
+ * @return finalized object
*/
- static String getStringFromType(YangSchemaNode holder, Object holderObj,
- String name, Object fieldObj, YangType dataType) {
+ static Object getObjFromType(YangSchemaNode holder, Object holderObj,
+ Object leaf, String name, Object fieldObj,
+ YangType dataType) {
if (fieldObj == null) {
- throw new ModelConvertorException("Value of " + holder.getName() + " is null");
+ throw new ModelConvertorException("Value of " + holder.getName()
+ + " is null");
}
YangDataTypes type = dataType.getDataType();
@@ -278,39 +282,44 @@
case UINT16:
case UINT32:
case UINT64:
- case EMPTY:
case STRING:
- case DECIMAL64:
- case INSTANCE_IDENTIFIER:
- case DERIVED:
- case UNION:
- case ENUMERATION:
case BOOLEAN:
+ case DECIMAL64:
+ case EMPTY:
+ return fieldObj;
+
+ case INSTANCE_IDENTIFIER:
+ case ENUMERATION:
return String.valueOf(fieldObj).trim();
+ case BINARY:
+ return new String((byte[]) fieldObj);
+
case BITS:
return getBitsValue(holder, holderObj, name, fieldObj).trim();
- case BINARY:
- return Base64.getEncoder().encodeToString((byte[]) fieldObj);
-
case IDENTITYREF:
- YangIdentityRef ir =
- (YangIdentityRef) dataType.getDataTypeExtendedInfo();
+ YangIdentityRef ir = (YangIdentityRef) dataType
+ .getDataTypeExtendedInfo();
if (ir.isInGrouping()) {
return String.valueOf(fieldObj).trim();
}
return getIdentityRefValue(fieldObj, ir, holderObj);
case LEAFREF:
- YangLeafRef leafRef =
- (YangLeafRef) dataType.getDataTypeExtendedInfo();
- return getStringFromType(holder, holderObj, name, fieldObj,
- leafRef.getEffectiveDataType());
+ YangLeafRef leafRef = (YangLeafRef) dataType
+ .getDataTypeExtendedInfo();
+ return getObjFromType(holder, holderObj, leaf, name, fieldObj,
+ leafRef.getEffectiveDataType());
+
+ case DERIVED:
+ case UNION:
+ String val = String.valueOf(fieldObj).trim();
+ return ((LeafSchemaContext) leaf).fromString(val);
default:
- throw new ModelConvertorException("Unsupported data type. Cannot be " +
- "processed.");
+ throw new ModelConvertorException(
+ "Unsupported data type. Cannot be processed.");
}
}
@@ -532,4 +541,85 @@
}
return builder.toString();
}
+
+ /**
+ * Returns leaf object when value is present. For primitive types, in
+ * order to avoid default values, the value select is set or not is checked
+ * and then returned.
+ *
+ * @param holder leaf holder
+ * @param leaf YANG leaf
+ * @param parentObj leaf holder object
+ * @param leafObj object of leaf type
+ * @param isRoot if it is root leaf object
+ * @return processed leaf object
+ */
+ static Object getLeafObject(YangSchemaNode holder, YangLeaf leaf,
+ Object parentObj, Object leafObj,
+ boolean isRoot) {
+ String jLeaf = getJavaName(leaf);
+ YangType<?> type = leaf.getDataType();
+ if (!isRoot && isTypePrimitive(type)) {
+ if (!isLeafValueSet(holder, parentObj, jLeaf)) {
+ return null;
+ }
+ }
+
+ if (leafObj == null) {
+ return null;
+ }
+ return getObjFromType(holder, parentObj, leaf, jLeaf,
+ leafObj, type);
+ }
+
+ /**
+ * Returns processed leaf-list objects from the data type.
+ *
+ * @param holder leaf-list holder
+ * @param leafList YANG leaf-list
+ * @param parentObj leaf-list holder object
+ * @param objects leaf-list objects
+ * @return processed leaf-list objects
+ */
+ static Set<Object> getLeafListObject(YangSchemaNode holder,
+ YangLeafList leafList,
+ Object parentObj,
+ List<Object> objects) {
+ Set<Object> leafListVal = new LinkedHashSet<>();
+ YangType<?> type = leafList.getDataType();
+ for (Object object : objects) {
+ Object obj = getObjFromType(holder, parentObj, leafList,
+ getJavaName(leafList), object, type);
+ leafListVal.add(obj);
+ }
+ return leafListVal;
+ }
+
+
+ /**
+ * Returns the value as true if direct or referred type from leaf-ref or
+ * derived points to empty data type; false otherwise.
+ *
+ * @param dataType type of the leaf
+ * @return true if type is empty; false otherwise.
+ */
+ static boolean isTypeEmpty(YangType<?> dataType) {
+ switch (dataType.getDataType()) {
+ case EMPTY:
+ return true;
+
+ case LEAFREF:
+ YangLeafRef leafRef = (YangLeafRef) dataType
+ .getDataTypeExtendedInfo();
+ return isTypeEmpty(leafRef.getEffectiveDataType());
+ case DERIVED:
+ YangDerivedInfo info = (YangDerivedInfo) dataType
+ .getDataTypeExtendedInfo();
+ YangDataTypes type = info.getEffectiveBuiltInType();
+ return type == EMPTY;
+
+ default:
+ return false;
+ }
+ }
}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java
index 6dfdfd5..6aff30d 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java
@@ -51,7 +51,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
@@ -80,8 +79,8 @@
*/
final class YobUtils {
- private static final Logger log = LoggerFactory.getLogger(YobUtils.class);
public static final String FORWARD_SLASH = "/";
+ private static final Logger log = LoggerFactory.getLogger(YobUtils.class);
private static final String ENUM_LEAF_IDENTIFIER = "$LeafIdentifier";
// no instantiation
@@ -120,20 +119,20 @@
case INT64:
case UINT64:
case BOOLEAN:
- case EMPTY:
case STRING:
+ case DECIMAL64:
+ case INSTANCE_IDENTIFIER:
parentSetter.invoke(parentObj, value);
break;
+
case BINARY:
parentSetter.invoke(parentObj, ((String) value).getBytes());
break;
+
case BITS:
parseBitSetTypeInfo(parentSetter, parentObj, value,
schemaNode, parentSchema);
break;
- case DECIMAL64:
- parentSetter.invoke(parentObj, new BigDecimal(value.toString()));
- break;
case DERIVED:
parseDerivedTypeInfo(parentSetter, parentObj, value.toString(),
@@ -160,6 +159,12 @@
true, schemaNode);
break;
+ case EMPTY:
+ if (value == null) {
+ parentSetter.invoke(parentObj, true);
+ }
+ break;
+
default:
log.error(E_DATA_TYPE_NOT_SUPPORT);
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataTreeContextSwitchTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataTreeContextSwitchTest.java
index a6a05ec..171ca85 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataTreeContextSwitchTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DataTreeContextSwitchTest.java
@@ -18,24 +18,6 @@
import org.junit.Test;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.ChoiceContainer;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.DefaultChoiceContainer;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.DefaultPredict;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.Predict;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.DefaultReproduce;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.Reproduce;
-import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.currentvalue.DefaultYtbAbsent;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.DefaultCont1;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.DefaultCont2;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.DefaultAugmentedCont2;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.Cont1s;
-import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.DefaultCont1s;
-import org.onosproject.yang.gen.v1.ytbsimplechoicecase.rev20160826.ytbsimplechoicecase.DefaultYtbFood;
-import org.onosproject.yang.gen.v1.ytbsimplechoicecase.rev20160826.ytbsimplechoicecase.ytbfood.ytbsnack.DefaultYtbLateNight;
-import org.onosproject.yang.gen.v1.modulelistandkey.rev20160826.modulelistandkey.DefaultModKey;
-import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.DefaultAugmentedSchModKey;
-import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.augmentedschmodkey.AugListModKey;
-import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.augmentedschmodkey.DefaultAugListModKey;
import org.onosproject.yang.gen.v1.modeldatatoresourcedata.rev20160826.modeldatatoresourcedata.BinaryTypedef;
import org.onosproject.yang.gen.v1.modeldatatoresourcedata.rev20160826.modeldatatoresourcedata.DefaultFirstLevel;
import org.onosproject.yang.gen.v1.modeldatatoresourcedata.rev20160826.modeldatatoresourcedata.UnionTypedef;
@@ -57,6 +39,24 @@
import org.onosproject.yang.gen.v1.modeldatatoresourcedata.rev20160826.modeldatatoresourcedata.group1.DefaultGroupContainer;
import org.onosproject.yang.gen.v1.modeldatatoresourcedatainterfile.rev20160826.modeldatatoresourcedatainterfile.firstlevel.containerchoice.choicecase.augmentedschchoicecase.DefaultLeafInterAug;
import org.onosproject.yang.gen.v1.modeldatatoresourcedatainterfile.rev20160826.modeldatatoresourcedatainterfile.firstlevel.containerchoice.choicecase.leafcase.DefaultAugmentedSchLeafCase;
+import org.onosproject.yang.gen.v1.modulelistandkey.rev20160826.modulelistandkey.DefaultModKey;
+import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.DefaultAugmentedSchModKey;
+import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.augmentedschmodkey.AugListModKey;
+import org.onosproject.yang.gen.v1.modulelistandkeyaugment.rev20160826.modulelistandkeyaugment.modkey.augmentedschmodkey.DefaultAugListModKey;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.ChoiceContainer;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.DefaultChoiceContainer;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.DefaultPredict;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.Predict;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.DefaultReproduce;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.contenttest.choicecontainer.choicecontainer.predict.Reproduce;
+import org.onosproject.yang.gen.v1.ytbchoicewithcontainerandleaflist.rev20160826.ytbchoicewithcontainerandleaflist.currentvalue.DefaultYtbAbsent;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.DefaultCont1;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.DefaultCont2;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.DefaultAugmentedCont2;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.Cont1s;
+import org.onosproject.yang.gen.v1.ytbsimpleaugment.rev20160826.ytbsimpleaugment.cont1.cont2.augmentedcont2.DefaultCont1s;
+import org.onosproject.yang.gen.v1.ytbsimplechoicecase.rev20160826.ytbsimplechoicecase.DefaultYtbFood;
+import org.onosproject.yang.gen.v1.ytbsimplechoicecase.rev20160826.ytbsimplechoicecase.ytbfood.ytbsnack.DefaultYtbLateNight;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.DefaultModelObjectData;
import org.onosproject.yang.model.InnerNode;
@@ -91,6 +91,8 @@
private static final String CHOC = "choc";
private static final String VAL = "val";
private static final String IND = "ind";
+ private final TestYangSchemaNodeProvider schemaProvider = new
+ TestYangSchemaNodeProvider();
private ResourceData rscData;
private DefaultDataTreeBuilder treeBuilder;
private ResourceId id;
@@ -101,8 +103,6 @@
private DataNode node;
private ModelObjectId mid;
private DefaultModelObjectData.Builder data;
- private final TestYangSchemaNodeProvider schemaProvider = new
- TestYangSchemaNodeProvider();
/**
* Do the prior setup for each UT.
@@ -1191,7 +1191,7 @@
c1.leaf3(120);
DefaultAugmentedLeafCase aug1 = new DefaultAugmentedLeafCase();
- aug1.leafAug(BinaryTypedef.fromString("1011"));
+ aug1.leafAug(BinaryTypedef.fromString("MTAxMQ=="));
c1.addAugmentation(aug1);
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
index a016fda..3951a26 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultDataTreeBuilderTest.java
@@ -29,6 +29,18 @@
import org.onosproject.yang.gen.v1.yrtietfte.rev20170310.yrtietfte.tunnelsgrouping.DefaultTunnels;
import org.onosproject.yang.gen.v1.yrtietfte.rev20170310.yrtietfte.tunnelsgrouping.tunnels.DefaultTunnel;
import org.onosproject.yang.gen.v1.yrtietftetypes.rev20160320.yrtietftetypes.TunnelP2p;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Cont1;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def1;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Def3;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.DefaultCont1;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Physical;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.Virtual;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.Cont2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.DefaultCont2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.cont2.AugmentedCont2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.cont1.cont2.DefaultAugmentedCont2;
+import org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.def1.Def1Union;
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.YtbIetfSchedule;
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.ytbietfschedule.Enum1Enum;
import org.onosproject.yang.gen.v1.ytbietfschedule.rev20160826.ytbietfschedule.Enum2Enum;
@@ -46,12 +58,15 @@
import org.onosproject.yang.gen.v1.ytbtreebuilderforlisthavinglist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.multiplexes.DefaultApplicationAreas;
import org.onosproject.yang.gen.v1.ytbtreebuilderforlisthavinglist.rev20160826.ytbtreebuilderforlisthavinglist.carrier.multiplexes.TypesEnum;
import org.onosproject.yang.model.DataNode;
-import org.onosproject.yang.model.DefaultModelObjectData;
+import org.onosproject.yang.model.DefaultModelObjectData.Builder;
+import org.onosproject.yang.model.InnerModelObject;
import org.onosproject.yang.model.InnerNode;
import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.LeafIdentifier;
import org.onosproject.yang.model.LeafListKey;
import org.onosproject.yang.model.LeafModelObject;
import org.onosproject.yang.model.ListKey;
+import org.onosproject.yang.model.ModelObject;
import org.onosproject.yang.model.ModelObjectId;
import org.onosproject.yang.model.NodeKey;
import org.onosproject.yang.model.ResourceData;
@@ -64,6 +79,8 @@
import java.math.BigDecimal;
import java.util.ArrayList;
+import java.util.Base64;
+import java.util.BitSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -73,6 +90,31 @@
import static org.hamcrest.core.Is.is;
import static org.onosproject.yang.gen.v1.simpledatatypes.rev20131112.simpledatatypes.Cont.LeafIdentifier.LFENUM1;
import static org.onosproject.yang.gen.v1.simpledatatypes.rev20131112.simpledatatypes.tpdfun0.Tpdfun0Enum.SUCCESSFUL_EXIT;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF1;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF10;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF11;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF12;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF2;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF3;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF4;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF5;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF6;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF7;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF8;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LEAF9;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL1;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL10;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL11;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL12;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL2;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL3;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL4;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL5;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL6;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL7;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL8;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.YtbDataTypes.LeafIdentifier.LL9;
+import static org.onosproject.yang.gen.v1.ytbdatatypes.rev20160826.ytbdatatypes.def1.def1union.Def1UnionEnum1.of;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE;
import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE;
import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE;
@@ -111,7 +153,7 @@
private List<DataNode> dataNodes;
private DataNode node;
private ModelObjectId mid;
- private DefaultModelObjectData.Builder data;
+ private Builder data;
/**
* Do the prior setup for each UT.
@@ -140,7 +182,7 @@
objects.add(9);
modelObject.values(objects);
// Builds YANG tree in YTB.
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(modelObject);
rscData = treeBuilder.getResourceData(data.build());
@@ -183,7 +225,7 @@
modelObject.values(objects);
//Builds YANG tree in YTB.
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(modelObject);
rscData = treeBuilder.getResourceData(data.build());
@@ -226,7 +268,7 @@
DefaultModKey m1 = new DefaultModKey();
m1.types(1);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(m1);
rscData = treeBuilder.getResourceData(data.build());
@@ -280,7 +322,7 @@
DefaultModKey m3 = new DefaultModKey();
m3.types(3);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(m1).addModelObject(m2).addModelObject(m3);
rscData = treeBuilder.getResourceData(data.build());
@@ -358,7 +400,7 @@
setUp();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
LeafModelObject object = new LeafModelObject();
object.leafIdentifier(ModKey.LeafIdentifier.TYPES);
@@ -447,8 +489,7 @@
setUp();
- data = new DefaultModelObjectData
- .Builder();
+ data = new Builder();
ModKeyKeys keyKeys = new ModKeyKeys();
keyKeys.types(10);
mid = ModelObjectId.builder()
@@ -502,7 +543,7 @@
public void processWithTypeEnum() {
setUp();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
//As an application, creates the object.
LeafModelObject object = new LeafModelObject();
object.leafIdentifier(YtbIetfSchedule.LeafIdentifier.TIME);
@@ -582,7 +623,7 @@
sched.predict(dec);
// Builds YANG tree in YTB.
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(sched);
rscData = treeBuilder.getResourceData(data.build());
@@ -625,7 +666,7 @@
public void processModuleWithContainerModId() {
setUp();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
//As an application, creates the object.
LeafModelObject object = new LeafModelObject();
object.leafIdentifier(DefaultSched.LeafIdentifier.PREDICT);
@@ -671,14 +712,14 @@
setUp();
// Creates two binary leaf -lists for two list app areas.
List<byte[]> destArea1 = new ArrayList<>();
- byte[] arr = new byte[]{1, 6, 3};
- byte[] arr1 = new byte[]{2, 7, 4};
+ byte[] arr = Base64.getDecoder().decode("QXdnRQ==");
+ byte[] arr1 = Base64.getDecoder().decode("QlFZQg==");
destArea1.add(arr);
destArea1.add(arr1);
List<byte[]> destArea2 = new ArrayList<>();
- byte[] arr2 = new byte[]{3, 8, 4};
- byte[] arr3 = new byte[]{5, 6, 1};
+ byte[] arr2 = Base64.getDecoder().decode("QndjSA==");
+ byte[] arr3 = Base64.getDecoder().decode("QUFFPQ==");
destArea2.add(arr2);
destArea2.add(arr3);
@@ -699,14 +740,14 @@
//Creates two binary leaf -lists for two list app areas.
List<byte[]> destArea3 = new ArrayList<>();
- byte[] arrB = new byte[]{0, 0, 1};
- byte[] arr1B = new byte[]{1, 0, 0};
+ byte[] arrB = Base64.getDecoder().decode("QUtqaA==");
+ byte[] arr1B = Base64.getDecoder().decode("TkJGag==");
destArea3.add(arrB);
destArea3.add(arr1B);
List<byte[]> destArea4 = new ArrayList<>();
- byte[] arr2B = new byte[]{7, 7, 7};
- byte[] arr3B = new byte[]{0, 1};
+ byte[] arr2B = Base64.getDecoder().decode("SkhJOA==");
+ byte[] arr3B = Base64.getDecoder().decode("MTExMQ==");
destArea4.add(arr2B);
destArea4.add(arr3B);
@@ -733,7 +774,7 @@
DefaultCarrier carrier = new DefaultCarrier();
carrier.multiplexes(multiplexList);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(carrier);
rscData = treeBuilder.getResourceData(data.build());
nameSpace = "yms:test:ytb:tree:builder:for:list:having:list";
@@ -793,7 +834,7 @@
assertThat(true, is(key instanceof LeafListKey));
LeafListKey leafListKey = (LeafListKey) key;
- assertThat("AwgE", is(leafListKey.value()));
+ assertThat("BwcH", is(leafListKey.value()));
sid = key.schemaId();
assertThat("destination-areas", is(sid.name()));
@@ -804,7 +845,7 @@
assertThat(true, is(key instanceof LeafListKey));
leafListKey = (LeafListKey) key;
- assertThat("BQYB", is(leafListKey.value()));
+ assertThat("AAE=", is(leafListKey.value()));
sid = key.schemaId();
assertThat("destination-areas", is(sid.name()));
@@ -846,7 +887,7 @@
assertThat(true, is(key instanceof LeafListKey));
leafListKey = (LeafListKey) key;
- assertThat("BwcH", is(leafListKey.value()));
+ assertThat("JHI8", is(leafListKey.value()));
sid = key.schemaId();
assertThat("destination-areas", is(sid.name()));
@@ -857,7 +898,7 @@
assertThat(true, is(key instanceof LeafListKey));
leafListKey = (LeafListKey) key;
- assertThat("AAE=", is(leafListKey.value()));
+ assertThat("1111", is(leafListKey.value()));
sid = key.schemaId();
assertThat("destination-areas", is(sid.name()));
@@ -876,7 +917,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithNotification();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
mid = ModelObjectId.builder()
.addChild(DefaultTestNotification.class).build();
data.identifier(mid);
@@ -913,7 +954,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithNotification();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
mid = ModelObjectId.builder()
.addChild(DefaultTestNotification.class).build();
data.identifier(mid);
@@ -957,7 +998,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithRpc();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
mid = ModelObjectId.builder()
.addChild(DefaultTestInput.class).build();
data.identifier(mid);
@@ -1000,7 +1041,7 @@
DefaultTestInput input = new DefaultTestInput();
input.testContainer(new DefaultTestContainer());
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(input);
registry = ut.reg;
@@ -1040,7 +1081,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithRpc();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(new DefaultTestOutput());
registry = ut.reg;
@@ -1080,7 +1121,7 @@
MoIdToRscIdTest ut = new MoIdToRscIdTest();
ut.addMockModWithRpc();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
mid = ModelObjectId.builder()
.addChild(DefaultTestInput.class).build();
data.identifier(mid);
@@ -1124,7 +1165,7 @@
@Test
public void processEnumeration() {
setUp();
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
ModelObjectId.Builder moIdBdlr = ModelObjectId.builder()
.addChild(DefaultCont.class);
LeafModelObject mo = new LeafModelObject();
@@ -1171,7 +1212,7 @@
DefaultTe te = new DefaultTe();
te.tunnels(tunnels);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(te);
DefaultDataTreeBuilder builder = new DefaultDataTreeBuilder(registry);
rscData = builder.getResourceData(data.build());
@@ -1203,7 +1244,7 @@
con.conIn(typedef);
input.in(con);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(input);
rscData = treeBuilder.getResourceData(data.build());
@@ -1232,7 +1273,7 @@
first.call(ll);
output.outCh(first);
- data = new DefaultModelObjectData.Builder();
+ data = new Builder();
data.addModelObject(output);
rscData = treeBuilder.getResourceData(data.build());
@@ -1252,4 +1293,394 @@
node = inDn.get(0);
validateDataNode(node, "output", ns, SINGLE_INSTANCE_NODE, true, null);
}
+
+ /**
+ * Unit test for proper conversion of data types to data node.
+ */
+ @Test
+ public void processDataTypesToDataNode() {
+ setUp();
+ data = new Builder();
+ data = buildRootLeafAndLeafList(data);
+ data = buildContainer(data);
+ rscData = treeBuilder.getResourceData(data.build());
+
+ List<DataNode> inDn = rscData.dataNodes();
+ String ns = "yms:test:ytb:data:types";
+ Iterator<DataNode> it = inDn.iterator();
+
+ it = validate(it, ns);
+
+ DataNode cont1 = it.next();
+ validateDataNode(cont1, "cont1", ns, SINGLE_INSTANCE_NODE, true, null);
+
+ Map<NodeKey, DataNode> c1 = ((InnerNode) cont1).childNodes();
+ List<DataNode> cont1DN = new LinkedList<>();
+ for (Map.Entry<NodeKey, DataNode> c : c1.entrySet()) {
+ cont1DN.add(c.getValue());
+ }
+ Iterator<DataNode> it1 = cont1DN.iterator();
+ it1 = validate(it1, ns);
+
+ DataNode cont2 = it1.next();
+ validateDataNode(cont2, "cont2", ns, SINGLE_INSTANCE_NODE, true, null);
+
+ Map<NodeKey, DataNode> c2 = ((InnerNode) cont2).childNodes();
+ List<DataNode> cont2DN = new LinkedList<>();
+ for (Map.Entry<NodeKey, DataNode> c : c2.entrySet()) {
+ cont2DN.add(c.getValue());
+ }
+ Iterator<DataNode> it2 = cont2DN.iterator();
+ validate(it2, ns);
+ }
+
+ /**
+ * Validates the leaf and leaf-list value under the specified node.
+ *
+ * @param it data node iterator
+ * @param ns name space
+ * @return data node iterator
+ */
+ private Iterator<DataNode> validate(Iterator<DataNode> it, String ns) {
+
+ validateDataNode(it.next(), "leaf1", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "leaf1");
+ validateDataNode(it.next(), "leaf2", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "thousand");
+ validateDataNode(it.next(), "leaf3", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "11011");
+ validateDataNode(it.next(), "leaf4", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "thousand");
+ validateDataNode(it.next(), "leaf5", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "physical");
+ validateDataNode(it.next(), "leaf6", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "/cont1");
+ validateDataNode(it.next(), "leaf7", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2");
+ validateDataNode(it.next(), "leaf8", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, null);
+ validateDataNode(it.next(), "leaf9", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2");
+ validateDataNode(it.next(), "leaf11", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, null);
+ validateDataNode(it.next(), "leaf12", ns,
+ SINGLE_INSTANCE_LEAF_VALUE_NODE, true, "11011");
+ validateDataNode(it.next(), "ll1", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "leaf-list1");
+ validateDataNode(it.next(), "ll1", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "leaf-list1-2");
+ validateDataNode(it.next(), "ll2", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "thousand");
+ validateDataNode(it.next(), "ll2", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "ten");
+ validateDataNode(it.next(), "ll3", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "11011");
+ validateDataNode(it.next(), "ll3", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "110111");
+ validateDataNode(it.next(), "ll4", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "thousand");
+ validateDataNode(it.next(), "ll4", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "ten");
+ validateDataNode(it.next(), "ll5", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "physical");
+ validateDataNode(it.next(), "ll5", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "virtual");
+ validateDataNode(it.next(), "ll6", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "/cont1");
+ validateDataNode(it.next(), "ll6", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "/cont1/cont2");
+ validateDataNode(it.next(), "ll7", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2");
+ validateDataNode(it.next(), "ll7", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2 b3");
+ validateDataNode(it.next(), "ll8", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, null);
+ validateDataNode(it.next(), "ll9", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2");
+ validateDataNode(it.next(), "ll9", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "b1 b2 b3");
+ validateDataNode(it.next(), "ll11", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, null);
+ validateDataNode(it.next(), "ll12", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "11011");
+ validateDataNode(it.next(), "ll12", ns,
+ MULTI_INSTANCE_LEAF_VALUE_NODE, true, "110111");
+ return it;
+ }
+
+ /**
+ * Builds the container node with required value and returns the model
+ * object data.
+ *
+ * @param data model object data
+ * @return model object data builder
+ */
+ private Builder buildContainer(Builder data) {
+ Cont2 cont2 = buildAugmentForCont2();
+ Def1Union union = new Def1Union(of(1000));
+ Def1 def1 = new Def1(union);
+ Def1Union union2 = new Def1Union(of(10));
+ Def1 def12 = new Def1(union2);
+ byte[] arr = Base64.getDecoder().decode("MTEwMTE=");
+ byte[] arr1 = Base64.getDecoder().decode("MTEwMTEx");
+ BitSet bits = new BitSet();
+ bits.set(0, 2, true);
+ BitSet bits1 = new BitSet();
+ bits1.set(0, 3, true);
+ Def2 def2 = new Def2(bits);
+ Def2 def21 = new Def2(bits1);
+ Def3 def3 = new Def3(false);
+ Def3 def31 = new Def3(true);
+ Cont1 cont1 = new DefaultCont1();
+ cont1.leaf1("leaf1");
+ cont1.leaf2(def1);
+ cont1.leaf3(arr);
+ cont1.leaf4(def1);
+ cont1.leaf5(Physical.class);
+ cont1.leaf6("/cont1");
+ cont1.leaf7(bits);
+ cont1.leaf8(true);
+ cont1.leaf9(def2);
+ cont1.leaf10(def3);
+ cont1.leaf11(true);
+ cont1.leaf12(arr);
+ cont1.addToLl1("leaf-list1");
+ cont1.addToLl1("leaf-list1-2");
+ cont1.addToLl2(def1);
+ cont1.addToLl2(def12);
+ cont1.addToLl3(arr);
+ cont1.addToLl3(arr1);
+ cont1.addToLl4(def1);
+ cont1.addToLl4(def12);
+ cont1.addToLl5(Physical.class);
+ cont1.addToLl5(Virtual.class);
+ cont1.addToLl6("/cont1");
+ cont1.addToLl6("/cont1/cont2");
+ cont1.addToLl7(bits);
+ cont1.addToLl7(bits1);
+ cont1.addToLl8(true);
+ cont1.addToLl8(false);
+ cont1.addToLl9(def2);
+ cont1.addToLl9(def21);
+ cont1.addToLl10(def3);
+ cont1.addToLl10(def31);
+ cont1.addToLl11(true);
+ cont1.addToLl11(true);
+ cont1.addToLl12(arr);
+ cont1.addToLl12(arr1);
+ cont1.cont2(cont2);
+ data.addModelObject((ModelObject) cont1);
+ return data;
+ }
+
+ /**
+ * Builds the augment node with required value and updates it in the
+ * container cont2.
+ *
+ * @return cont2
+ */
+ private Cont2 buildAugmentForCont2() {
+ Cont2 cont2 = new DefaultCont2();
+ AugmentedCont2 augC = new DefaultAugmentedCont2();
+ Def1Union union = new Def1Union(of(1000));
+ Def1 def1 = new Def1(union);
+ Def1Union union2 = new Def1Union(of(10));
+ Def1 def12 = new Def1(union2);
+ byte[] arr = Base64.getDecoder().decode("MTEwMTE=");
+ byte[] arr1 = Base64.getDecoder().decode("MTEwMTEx");
+ BitSet bits = new BitSet();
+ bits.set(0, 2, true);
+ BitSet bits1 = new BitSet();
+ bits1.set(0, 3, true);
+ Def2 def2 = new Def2(bits);
+ Def2 def21 = new Def2(bits1);
+ Def3 def3 = new Def3(false);
+ Def3 def31 = new Def3(true);
+ augC.leaf1("leaf1");
+ augC.leaf2(def1);
+ augC.leaf3(arr);
+ augC.leaf4(def1);
+ augC.leaf5(Physical.class);
+ augC.leaf6("/cont1");
+ augC.leaf7(bits);
+ augC.leaf8(true);
+ augC.leaf9(def2);
+ augC.leaf10(def3);
+ augC.leaf11(true);
+ augC.leaf12(arr);
+ augC.addToLl1("leaf-list1");
+ augC.addToLl1("leaf-list1-2");
+ augC.addToLl2(def1);
+ augC.addToLl2(def12);
+ augC.addToLl3(arr);
+ augC.addToLl3(arr1);
+ augC.addToLl4(def1);
+ augC.addToLl4(def12);
+ augC.addToLl5(Physical.class);
+ augC.addToLl5(Virtual.class);
+ augC.addToLl6("/cont1");
+ augC.addToLl6("/cont1/cont2");
+ augC.addToLl7(bits);
+ augC.addToLl7(bits1);
+ augC.addToLl8(true);
+ augC.addToLl8(false);
+ augC.addToLl9(def2);
+ augC.addToLl9(def21);
+ augC.addToLl10(def3);
+ augC.addToLl10(def31);
+ augC.addToLl11(true);
+ augC.addToLl11(true);
+ augC.addToLl12(arr);
+ augC.addToLl12(arr1);
+ cont2.addAugmentation((InnerModelObject) augC);
+ return cont2;
+ }
+
+ /**
+ * Builds the root leaf and leaf-list and adds it in the model object
+ * data builder.
+ *
+ * @param data model object data
+ * @return model object data builder
+ */
+ private Builder buildRootLeafAndLeafList(Builder data) {
+
+ data = addLeafModelObject(LEAF1, "leaf1", data);
+
+ Def1Union union = new Def1Union(of("thousand"));
+ Def1 def1 = new Def1(union);
+ data = addLeafModelObject(LEAF2, def1, data);
+
+ byte[] arr = Base64.getDecoder().decode("MTEwMTE=");
+ data = addLeafModelObject(LEAF3, arr, data);
+
+ data = addLeafModelObject(LEAF4, def1, data);
+
+ data = addLeafModelObject(LEAF5, Physical.class, data);
+
+ data = addLeafModelObject(LEAF6, "/cont1", data);
+
+ BitSet bits = new BitSet();
+ bits.set(0, 2, true);
+ data = addLeafModelObject(LEAF7, bits, data);
+
+ data = addLeafModelObject(LEAF8, true, data);
+
+ Def2 def2 = new Def2(bits);
+ data = addLeafModelObject(LEAF9, def2, data);
+
+ Def3 def3 = new Def3(false);
+ data = addLeafModelObject(LEAF10, def3, data);
+
+ data = addLeafModelObject(LEAF11, true, data);
+
+ data = addLeafModelObject(LEAF12, arr, data);
+
+ List<Object> objs = new LinkedList<>();
+ objs.add("leaf-list1");
+ objs.add("leaf-list1-2");
+ data = addLeafListModelObject(LL1, objs, data);
+
+ Def1Union union2 = new Def1Union(of("ten"));
+ Def1 def12 = new Def1(union2);
+ objs = new LinkedList<>();
+ objs.add(def1);
+ objs.add(def12);
+ data = addLeafListModelObject(LL2, objs, data);
+
+ byte[] arr1 = Base64.getDecoder().decode("MTEwMTEx");
+ objs = new LinkedList<>();
+ objs.add(arr);
+ objs.add(arr1);
+ data = addLeafListModelObject(LL3, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(def1);
+ objs.add(def12);
+ data = addLeafListModelObject(LL4, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(Physical.class);
+ objs.add(Virtual.class);
+ data = addLeafListModelObject(LL5, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add("/cont1");
+ objs.add("/cont1/cont2");
+ data = addLeafListModelObject(LL6, objs, data);
+
+ BitSet bits2 = new BitSet();
+ bits2.set(0, 3, true);
+ objs = new LinkedList<>();
+ objs.add(bits);
+ objs.add(bits2);
+ data = addLeafListModelObject(LL7, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(true);
+ objs.add(false);
+ data = addLeafListModelObject(LL8, objs, data);
+
+ Def2 def21 = new Def2(bits2);
+ objs = new LinkedList<>();
+ objs.add(def2);
+ objs.add(def21);
+ data = addLeafListModelObject(LL9, objs, data);
+
+ Def3 def31 = new Def3(true);
+ objs = new LinkedList<>();
+ objs.add(def3);
+ objs.add(def31);
+ data = addLeafListModelObject(LL10, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(true);
+ objs.add(true);
+ data = addLeafListModelObject(LL11, objs, data);
+
+ objs = new LinkedList<>();
+ objs.add(arr);
+ objs.add(arr1);
+ data = addLeafListModelObject(LL12, objs, data);
+
+ return data;
+ }
+
+ /**
+ * Adds the leaf model object to the model object data builder with leaf
+ * value.
+ *
+ * @param lId leaf identifier
+ * @param object leaf object
+ * @param data model object data
+ * @return model object data builder
+ */
+ private Builder addLeafModelObject(LeafIdentifier lId, Object object,
+ Builder data) {
+ LeafModelObject obj = new LeafModelObject();
+ obj.leafIdentifier(lId);
+ obj.addValue(object);
+ data.addModelObject(obj);
+ return data;
+ }
+
+ /**
+ * Adds the leaf-list model objects to the model object data builder with
+ * leaf-list values.
+ *
+ * @param lId leaf-list identifier
+ * @param object leaf-list object
+ * @param data model object data
+ * @return model object data builder
+ */
+ private Builder addLeafListModelObject(LeafIdentifier lId,
+ List<Object> object, Builder data) {
+ LeafModelObject obj = new LeafModelObject();
+ obj.leafIdentifier(lId);
+ for (Object o : object) {
+ obj.addValue(o);
+ }
+ data.addModelObject(obj);
+ return data;
+ }
}
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java
index 2e8c1f5..ceffa46 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/YobSimpleDataTypeTest.java
@@ -17,8 +17,8 @@
package org.onosproject.yang.runtime.impl;
import org.junit.Test;
-import org.onosproject.yang.gen.v1.simpledatatypesll.rev20131112.simpledatatypesll.DefaultCont1;
import org.onosproject.yang.gen.v1.simpledatatypes.rev20131112.simpledatatypes.DefaultCont;
+import org.onosproject.yang.gen.v1.simpledatatypesll.rev20131112.simpledatatypesll.DefaultCont1;
import org.onosproject.yang.model.DataNode;
import org.onosproject.yang.model.DefaultResourceData;
import org.onosproject.yang.model.ModelObject;
@@ -29,8 +29,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
-import static org.onosproject.yang.gen.v1.simpledatatypesll.rev20131112.simpledatatypesll.cont1.Lfenum1Enum.GRACE_PERIOD_EXPIRED;
import static org.onosproject.yang.gen.v1.simpledatatypes.rev20131112.simpledatatypes.tpdfun0.Tpdfun0Enum.SUCCESSFUL_EXIT;
+import static org.onosproject.yang.gen.v1.simpledatatypesll.rev20131112.simpledatatypesll.cont1.Lfenum1Enum.GRACE_PERIOD_EXPIRED;
import static org.onosproject.yang.runtime.SerializerHelper.addDataNode;
import static org.onosproject.yang.runtime.SerializerHelper.exitDataNode;
import static org.onosproject.yang.runtime.SerializerHelper.initializeDataNode;
@@ -40,10 +40,10 @@
*/
public class YobSimpleDataTypeTest {
- TestYangSerializerContext context = new TestYangSerializerContext();
private static final String DATA_TYPE_NAME_SPACE = "simple:data:types";
private static final String DATA_TYPE_NAME_SPACE_LL =
"simple:data:types:ll";
+ TestYangSerializerContext context = new TestYangSerializerContext();
private DataNode.Builder dBlr;
private String value;
@@ -219,6 +219,11 @@
value = "successful exit";
dBlr = addDataNode(dBlr, "lfenum1", DATA_TYPE_NAME_SPACE, value, null);
dBlr = exitDataNode(dBlr);
+
+ value = "/cont";
+ dBlr = addDataNode(dBlr, "inst-iden", null, value, null);
+ dBlr = exitDataNode(dBlr);
+
dBlr = exitDataNode(dBlr);
return dBlr.build();
}
@@ -469,6 +474,7 @@
assertThat(cont.lfunion14().toString(), is("one"));
assertThat(cont.identityref1().getSimpleName(), is("Iden"));
assertThat(cont.lfenum1().enumeration(), is(SUCCESSFUL_EXIT));
+ assertThat(cont.instIden(), is("/cont"));
}
diff --git a/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang b/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang
index f6b64d2..599649f 100644
--- a/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang
+++ b/runtime/src/test/resources/yobTestYangFiles/simple-data-types.yang
@@ -267,5 +267,9 @@
leaf lfenum1 {
type tpdfun0;
}
+
+ leaf inst-iden {
+ type instance-identifier;
+ }
}
}
diff --git a/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang b/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang
new file mode 100644
index 0000000..b966b8f
--- /dev/null
+++ b/runtime/src/test/resources/ytbTestYangFiles/YtbDataTypes.yang
@@ -0,0 +1,413 @@
+module YtbDataTypes {
+ yang-version 1;
+ namespace "yms:test:ytb:data:types";
+ prefix "data-types";
+ revision "2016-08-26";
+ // Enum with all combinations.
+
+ typedef def1 {
+ type union {
+ type uint64;
+ type enumeration {
+ enum ten {
+ value "10";
+ }
+ enum hundred {
+ value "100";
+ }
+ enum thousand {
+ value "1000";
+ }
+ }
+ }
+ }
+
+ typedef def2 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ typedef def3 {
+ type empty;
+ }
+
+ typedef def4 {
+ type empty;
+ }
+
+ typedef def5 {
+ type leafref {
+ path "/leaf3";
+ }
+ }
+
+ identity type {
+ description "type value";
+ }
+
+ identity physical {
+ base type;
+ }
+
+ identity virtual {
+ base type;
+ }
+
+ leaf leaf1 {
+ type string;
+ }
+
+ leaf leaf2 {
+ type def1;
+ }
+
+ leaf leaf3 {
+ type binary;
+ }
+
+ leaf leaf4 {
+ type leafref {
+ path "/leaf2";
+ }
+ }
+
+ leaf leaf5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf leaf6 {
+ type instance-identifier;
+ }
+
+ leaf leaf7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf leaf8 {
+ type empty;
+ }
+
+ leaf leaf9 {
+ type def2;
+ }
+
+ leaf leaf10 {
+ type def3;
+ }
+
+ leaf leaf11 {
+ type leafref {
+ path "/leaf8";
+ }
+ }
+
+ leaf leaf12 {
+ type def5;
+ }
+
+ container cont1 {
+ leaf leaf1 {
+ type string;
+ }
+
+ leaf leaf2 {
+ type def1;
+ }
+
+ leaf leaf3 {
+ type binary;
+ }
+
+ leaf leaf4 {
+ type leafref {
+ path "/leaf2";
+ }
+ }
+
+ leaf leaf5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf leaf6 {
+ type instance-identifier;
+ }
+
+ leaf leaf7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf leaf8 {
+ type empty;
+ }
+
+ leaf leaf9 {
+ type def2;
+ }
+
+ leaf leaf10 {
+ type def3;
+ }
+
+ leaf leaf11 {
+ type leafref {
+ path "/leaf8";
+ }
+ }
+
+ leaf leaf12 {
+ type def5;
+ }
+
+ leaf-list ll1 {
+ type string;
+ }
+
+ leaf-list ll2 {
+ type def1;
+ }
+
+ leaf-list ll3 {
+ type binary;
+ }
+
+ leaf-list ll4 {
+ type leafref {
+ path "/ll2";
+ }
+ }
+
+ leaf-list ll5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf-list ll6 {
+ type instance-identifier;
+ }
+
+ leaf-list ll7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf-list ll8 {
+ type empty;
+ }
+
+ leaf-list ll9 {
+ type def2;
+ }
+
+ leaf-list ll10 {
+ type def3;
+ }
+
+ leaf-list ll11 {
+ type leafref {
+ path "/ll8";
+ }
+ }
+
+ leaf-list ll12 {
+ type def5;
+ }
+
+ container cont2 {
+ }
+ }
+
+ leaf-list ll1 {
+ type string;
+ }
+
+ leaf-list ll2 {
+ type def1;
+ }
+
+ leaf-list ll3 {
+ type binary;
+ }
+
+ leaf-list ll4 {
+ type leafref {
+ path "/ll2";
+ }
+ }
+
+ leaf-list ll5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf-list ll6 {
+ type instance-identifier;
+ }
+
+ leaf-list ll7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf-list ll8 {
+ type empty;
+ }
+
+ leaf-list ll9 {
+ type def2;
+ }
+
+ leaf-list ll10 {
+ type def3;
+ }
+
+ leaf-list ll11 {
+ type leafref {
+ path "/ll8";
+ }
+ }
+
+ leaf-list ll12 {
+ type def5;
+ }
+
+ augment "/cont1/cont2" {
+ leaf leaf1 {
+ type string;
+ }
+
+ leaf leaf2 {
+ type def1;
+ }
+
+ leaf leaf3 {
+ type binary;
+ }
+
+ leaf leaf4 {
+ type leafref {
+ path "/leaf2";
+ }
+ }
+
+ leaf leaf5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf leaf6 {
+ type instance-identifier;
+ }
+
+ leaf leaf7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf leaf8 {
+ type empty;
+ }
+
+ leaf leaf9 {
+ type def2;
+ }
+
+ leaf leaf10 {
+ type def3;
+ }
+
+ leaf leaf11 {
+ type leafref {
+ path "/leaf8";
+ }
+ }
+
+ leaf leaf12 {
+ type def5;
+ }
+
+ leaf-list ll1 {
+ type string;
+ }
+
+ leaf-list ll2 {
+ type def1;
+ }
+
+ leaf-list ll3 {
+ type binary;
+ }
+
+ leaf-list ll4 {
+ type leafref {
+ path "/ll2";
+ }
+ }
+
+ leaf-list ll5 {
+ type identityref {
+ base type;
+ }
+ }
+
+ leaf-list ll6 {
+ type instance-identifier;
+ }
+
+ leaf-list ll7 {
+ type bits {
+ bit b1;
+ bit b2;
+ bit b3;
+ }
+ }
+
+ leaf-list ll8 {
+ type empty;
+ }
+
+ leaf-list ll9 {
+ type def2;
+ }
+
+ leaf-list ll10 {
+ type def3;
+ }
+
+ leaf-list ll11 {
+ type leafref {
+ path "/ll8";
+ }
+ }
+
+ leaf-list ll12 {
+ type def5;
+ }
+ }
+}