From 224d394cda8a832f8d8c9db03795343ac82f7058 Mon Sep 17 00:00:00 2001 From: Vidyashree Rama Date: Fri, 17 Aug 2018 17:15:20 +0530 Subject: Unit test and decode implementation properties node serializer decode implementation and unit test cases Issue-ID: CCSDK-378 Change-Id: I586fd534f441eb361e8d75af18cc778f7ad4cc67 Signed-off-by: Vidyashree Rama --- .../DefaultPropertiesNodeListener.java | 95 ++++++++++++++++++++++ .../yangserializers/pnserializer/InnerNode.java | 7 +- .../pnserializer/LeafListHolderNode.java | 1 + .../MdsalPropertiesNodeSerializer.java | 7 +- .../yangserializers/pnserializer/RootNode.java | 4 +- 5 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeListener.java (limited to 'restconf-client/provider/src/main/java') diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeListener.java new file mode 100644 index 00000000..a8a9b493 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeListener.java @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.MULTI_INSTANCE_LEAF_NODE; +import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.SINGLE_INSTANCE_LEAF_NODE; + +/** + * Represents implementation of PropertiesNodeListener. + */ +public class DefaultPropertiesNodeListener implements PropertiesNodeListener { + + private Map params = new HashMap<>(); + + @Override + public void start(PropertiesNode node) { + // do nothing + } + + @Override + public void end(PropertiesNode node) { + exitPropertiesNode(node); + } + + @Override + public void enterPropertiesNode(PropertiesNode node) { + /* + * Only if it is leaf node or leaf-list node, + * then create a property entry and add to map + */ + if (node.nodeType() == SINGLE_INSTANCE_LEAF_NODE + || node.nodeType() == MULTI_INSTANCE_LEAF_NODE) { + params.put(node.uri(), ((LeafNode) node).value()); + } + } + + @Override + public void exitPropertiesNode(PropertiesNode node) { + if (!node.augmentations().isEmpty()) { + for (Map.Entry> augmentationTochild + : node.augmentations().asMap().entrySet()) { + Collection childsFromAugmentations = augmentationTochild + .getValue(); + if (!childsFromAugmentations.isEmpty()) { + PropertiesNodeWalker walker = new DefaultPropertiesNodeWalker<>(); + for (PropertiesNode pNode : childsFromAugmentations) { + enterPropertiesNode(pNode); + walker.walk(this, pNode); + exitPropertiesNode(pNode); + } + } + } + } + } + + /** + * Returns properties. + * + * @return properties + */ + public Map params() { + return params; + } + + /** + * Sets properties. + * + * @param params properties + */ + public void params(Map params) { + this.params = params; + } +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java index 063c3d05..0711a7cf 100644 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java @@ -104,7 +104,7 @@ public abstract class InnerNode extends PropertiesNode { @Override public PropertiesNode addChild(String name, Namespace namespace, NodeType type, String value, - Namespace valuens, + Namespace valueNs, Object appInfo) throws SvcLogicException { LeafNode node = ((LeafNode) children.get(name)); if (node != null) { @@ -120,6 +120,7 @@ public abstract class InnerNode extends PropertiesNode { String uri = getUri(this, name, namespace); node = new LeafNode(name, namespace, uri, this, appInfo, type, value); + node.valueNs(valueNs); if (augSchema != null && !isNamespaceAsParent(this, node)) { addToAugmentations(augSchema, this, node); @@ -196,12 +197,12 @@ public abstract class InnerNode extends PropertiesNode { children.put(localName, ((T) node)); } - node = node.addChild(index, localName, namespace, type, value, null, appInfo); + node = node.addChild(index, localName, namespace, type, value, valueNs, appInfo); } else if (node instanceof LeafListHolderNode) { LeafNode child = ((LeafNode) ((HolderNode) node).child(index)); node = (child != null ? child : node.addChild(index, localName, namespace, type, - value, null, + value, valueNs, appInfo)); } else { throw new SvcLogicException("Duplicate node exist with same node"); diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/LeafListHolderNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/LeafListHolderNode.java index 94892dca..985bc1da 100644 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/LeafListHolderNode.java +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/LeafListHolderNode.java @@ -82,6 +82,7 @@ public class LeafListHolderNode extends HolderNode implemen String uri = this.uri() + "[" + index + "]"; node = (node != null) ? node : new LeafNode(name, namespace, uri, this, appInfo, type, value); + node.valueNs(valueNs); children().put(index, node); return node; } diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java index 405e2412..146e581f 100644 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java @@ -86,7 +86,10 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer decode(PropertiesNode propertiesNode) { - return null; + PropertiesNodeWalker walker = new DefaultPropertiesNodeWalker<>(); + DefaultPropertiesNodeListener listener = new DefaultPropertiesNodeListener(); + walker.walk(listener, propertiesNode); + return listener.params(); } private RootNode createRootNode(String lastNodeName, String rootUri) { @@ -128,6 +131,8 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer extends PropertiesNode { } else { children.put(localName, ((T) node)); } - node = node.addChild(index, localName, namespace, type, value, null, appInfo); + node = node.addChild(index, localName, namespace, type, value, valueNs, appInfo); } else if (node instanceof LeafListHolderNode) { LeafNode child = ((LeafNode) ((HolderNode) node).child(index)); node = (child != null ? child : node.addChild(index, localName, namespace, type, - value, null, + value, valueNs, appInfo)); } else { throw new SvcLogicException("Duplicate node exist with same node"); -- cgit 1.2.3-korg