summaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service')
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java48
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java26
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java2
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java67
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/YangUtils.java26
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy22
-rwxr-xr-xcps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy9
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy94
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/utils/JsonParserStreamSpec.groovy27
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy21
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/yang/YangTextSchemaSourceSetBuilderSpec.groovy4
-rw-r--r--cps-service/src/test/resources/data-with-choice-node.json8
-rw-r--r--cps-service/src/test/resources/yang-with-choice-node.yang27
13 files changed, 265 insertions, 116 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
index b08d8c1eba..732b494994 100755
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
@@ -3,6 +3,7 @@
* Copyright (C) 2021-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +28,7 @@ import static org.onap.cps.notification.Operation.DELETE;
import static org.onap.cps.notification.Operation.UPDATE;
import java.time.OffsetDateTime;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -45,7 +47,7 @@ import org.onap.cps.spi.model.DataNode;
import org.onap.cps.spi.model.DataNodeBuilder;
import org.onap.cps.spi.utils.CpsValidator;
import org.onap.cps.utils.YangUtils;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.springframework.stereotype.Service;
@@ -67,8 +69,9 @@ public class CpsDataServiceImpl implements CpsDataService {
public void saveData(final String dataspaceName, final String anchorName, final String jsonData,
final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final DataNode dataNode = buildDataNode(dataspaceName, anchorName, ROOT_NODE_XPATH, jsonData);
- cpsDataPersistenceService.storeDataNode(dataspaceName, anchorName, dataNode);
+ final Collection<DataNode> dataNodes =
+ buildDataNodes(dataspaceName, anchorName, ROOT_NODE_XPATH, jsonData);
+ cpsDataPersistenceService.storeDataNodes(dataspaceName, anchorName, dataNodes);
processDataUpdatedEventAsync(dataspaceName, anchorName, ROOT_NODE_XPATH, CREATE, observedTimestamp);
}
@@ -76,8 +79,9 @@ public class CpsDataServiceImpl implements CpsDataService {
public void saveData(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData, final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final DataNode dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData);
- cpsDataPersistenceService.addChildDataNode(dataspaceName, anchorName, parentNodeXpath, dataNode);
+ final Collection<DataNode> dataNodes =
+ buildDataNodes(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ cpsDataPersistenceService.addChildDataNodes(dataspaceName, anchorName, parentNodeXpath, dataNodes);
processDataUpdatedEventAsync(dataspaceName, anchorName, parentNodeXpath, CREATE, observedTimestamp);
}
@@ -161,8 +165,10 @@ public class CpsDataServiceImpl implements CpsDataService {
final String parentNodeXpath, final String jsonData,
final OffsetDateTime observedTimestamp) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- final DataNode dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData);
- cpsDataPersistenceService.updateDataNodeAndDescendants(dataspaceName, anchorName, dataNode);
+ final Collection<DataNode> dataNodes =
+ buildDataNodes(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ final ArrayList<DataNode> nodes = new ArrayList<>(dataNodes);
+ cpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, nodes);
processDataUpdatedEventAsync(dataspaceName, anchorName, parentNodeXpath, UPDATE, observedTimestamp);
}
@@ -226,15 +232,16 @@ public class CpsDataServiceImpl implements CpsDataService {
final SchemaContext schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
if (ROOT_NODE_XPATH.equals(parentNodeXpath)) {
- final NormalizedNode normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext);
- return new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).build();
+ final ContainerNode containerNode = YangUtils.parseJsonData(jsonData, schemaContext);
+ return new DataNodeBuilder().withContainerNode(containerNode).build();
}
- final NormalizedNode normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath);
+ final ContainerNode containerNode = YangUtils
+ .parseJsonData(jsonData, schemaContext, parentNodeXpath);
return new DataNodeBuilder()
- .withParentNodeXpath(parentNodeXpath)
- .withNormalizedNodeTree(normalizedNode)
- .build();
+ .withParentNodeXpath(parentNodeXpath)
+ .withContainerNode(containerNode)
+ .build();
}
private List<DataNode> buildDataNodes(final String dataspaceName, final String anchorName,
@@ -251,11 +258,20 @@ public class CpsDataServiceImpl implements CpsDataService {
final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
final SchemaContext schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
-
- final NormalizedNode normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath);
+ if (ROOT_NODE_XPATH.equals(parentNodeXpath)) {
+ final ContainerNode containerNode = YangUtils.parseJsonData(jsonData, schemaContext);
+ final Collection<DataNode> dataNodes = new DataNodeBuilder()
+ .withContainerNode(containerNode)
+ .buildCollection();
+ if (dataNodes.isEmpty()) {
+ throw new DataValidationException("Invalid data.", "No data nodes provided");
+ }
+ return dataNodes;
+ }
+ final ContainerNode containerNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath);
final Collection<DataNode> dataNodes = new DataNodeBuilder()
.withParentNodeXpath(parentNodeXpath)
- .withNormalizedNodeTree(normalizedNode)
+ .withContainerNode(containerNode)
.buildCollection();
if (dataNodes.isEmpty()) {
throw new DataValidationException("Invalid data.", "No data nodes provided");
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
index 8d4df20b81..b9da4af025 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2022 Bell Canada
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +23,7 @@
package org.onap.cps.spi;
+import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -34,16 +36,27 @@ import org.onap.cps.spi.model.DataNode;
*/
public interface CpsDataPersistenceService {
+
/**
* Store a datanode.
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
* @param dataNode data node
+ * @deprecated Please use {@link #storeDataNodes(String, String, Collection)} as it supports multiple data nodes.
*/
+ @Deprecated
void storeDataNode(String dataspaceName, String anchorName, DataNode dataNode);
/**
+ * Store multiple datanodes at once.
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param dataNodes data nodes
+ */
+ void storeDataNodes(String dataspaceName, String anchorName, Collection<DataNode> dataNodes);
+
+ /**
* Add a child to a Fragment.
*
* @param dataspaceName dataspace name
@@ -54,6 +67,16 @@ public interface CpsDataPersistenceService {
void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
/**
+ * Add multiple children to a Fragment.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param parentXpath parent xpath
+ * @param dataNodes collection of dataNodes
+ */
+ void addChildDataNodes(String dataspaceName, String anchorName, String parentXpath, Collection<DataNode> dataNodes);
+
+ /**
* Adds list child elements to a Fragment.
*
* @param dataspaceName dataspace name
@@ -61,7 +84,6 @@ public interface CpsDataPersistenceService {
* @param parentNodeXpath parent node xpath
* @param listElementsCollection collection of data nodes representing list elements
*/
-
void addListElements(String dataspaceName, String anchorName, String parentNodeXpath,
Collection<DataNode> listElementsCollection);
@@ -97,7 +119,7 @@ public interface CpsDataPersistenceService {
* @param xpath xpath
* @param leaves the leaves as a map where key is a leaf name and a value is a leaf value
*/
- void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Object> leaves);
+ void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Serializable> leaves);
/**
* Replaces an existing data node's content including descendants.
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java
index 8170db3dad..76f33bbc14 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java
@@ -46,7 +46,7 @@ public class DataNode implements Serializable {
private ModuleReference moduleReference;
private String xpath;
private String moduleNamePrefix;
- private Map<String, Object> leaves = Collections.emptyMap();
+ private Map<String, Serializable> leaves = Collections.emptyMap();
private Collection<String> xpathsChildren;
private Collection<DataNode> childDataNodes = Collections.emptySet();
}
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
index eaa2d77f47..b23cdfc8d1 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
@@ -3,6 +3,7 @@
* Copyright (C) 2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +24,7 @@ package org.onap.cps.spi.model;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -33,6 +35,8 @@ import lombok.extern.slf4j.Slf4j;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.utils.YangUtils;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
@@ -44,11 +48,11 @@ import org.opendaylight.yangtools.yang.data.api.schema.ValueNode;
@Slf4j
public class DataNodeBuilder {
- private NormalizedNode normalizedNodeTree;
+ private ContainerNode containerNode;
private String xpath;
private String moduleNamePrefix;
private String parentNodeXpath = "";
- private Map<String, Object> leaves = Collections.emptyMap();
+ private Map<String, Serializable> leaves = Collections.emptyMap();
private Collection<DataNode> childDataNodes = Collections.emptySet();
/**
@@ -62,15 +66,14 @@ public class DataNodeBuilder {
return this;
}
-
/**
- * To use {@link NormalizedNode} for creating {@link DataNode}.
+ * To use {@link Collection} of Normalized Nodes for creating {@link DataNode}.
*
- * @param normalizedNodeTree used for creating the Data Node
+ * @param containerNode used for creating the Data Node
* @return this {@link DataNodeBuilder} object
*/
- public DataNodeBuilder withNormalizedNodeTree(final NormalizedNode normalizedNodeTree) {
- this.normalizedNodeTree = normalizedNodeTree;
+ public DataNodeBuilder withContainerNode(final ContainerNode containerNode) {
+ this.containerNode = containerNode;
return this;
}
@@ -102,7 +105,7 @@ public class DataNodeBuilder {
* @param leaves for the data node
* @return DataNodeBuilder
*/
- public DataNodeBuilder withLeaves(final Map<String, Object> leaves) {
+ public DataNodeBuilder withLeaves(final Map<String, Serializable> leaves) {
this.leaves = leaves;
return this;
}
@@ -126,11 +129,10 @@ public class DataNodeBuilder {
* @return {@link DataNode}
*/
public DataNode build() {
- if (normalizedNodeTree != null) {
- return buildFromNormalizedNodeTree();
- } else {
- return buildFromAttributes();
+ if (containerNode != null) {
+ return buildFromContainerNode();
}
+ return buildFromAttributes();
}
/**
@@ -139,11 +141,10 @@ public class DataNodeBuilder {
* @return {@link DataNode} {@link Collection}
*/
public Collection<DataNode> buildCollection() {
- if (normalizedNodeTree != null) {
- return buildCollectionFromNormalizedNodeTree();
- } else {
- return Set.of(buildFromAttributes());
+ if (containerNode != null) {
+ return buildCollectionFromContainerNode();
}
+ return Collections.emptySet();
}
private DataNode buildFromAttributes() {
@@ -155,8 +156,8 @@ public class DataNodeBuilder {
return dataNode;
}
- private DataNode buildFromNormalizedNodeTree() {
- final Collection<DataNode> dataNodeCollection = buildCollectionFromNormalizedNodeTree();
+ private DataNode buildFromContainerNode() {
+ final Collection<DataNode> dataNodeCollection = buildCollectionFromContainerNode();
if (!dataNodeCollection.iterator().hasNext()) {
throw new DataValidationException(
"Unsupported xpath: ", "Unsupported xpath as it is referring to one element");
@@ -164,23 +165,29 @@ public class DataNodeBuilder {
return dataNodeCollection.iterator().next();
}
- private Collection<DataNode> buildCollectionFromNormalizedNodeTree() {
+ private Collection<DataNode> buildCollectionFromContainerNode() {
final var parentDataNode = new DataNodeBuilder().withXpath(parentNodeXpath).build();
- addDataNodeFromNormalizedNode(parentDataNode, normalizedNodeTree);
+ if (containerNode.body() != null) {
+ for (final NormalizedNode normalizedNode: containerNode.body()) {
+ addDataNodeFromNormalizedNode(parentDataNode, normalizedNode);
+ }
+ }
return parentDataNode.getChildDataNodes();
}
private static void addDataNodeFromNormalizedNode(final DataNode currentDataNode,
final NormalizedNode normalizedNode) {
- if (normalizedNode instanceof DataContainerNode) {
+ if (normalizedNode instanceof ChoiceNode) {
+ addChoiceNode(currentDataNode, (ChoiceNode) normalizedNode);
+ } else if (normalizedNode instanceof DataContainerNode) {
addYangContainer(currentDataNode, (DataContainerNode) normalizedNode);
} else if (normalizedNode instanceof MapNode) {
addDataNodeForEachListElement(currentDataNode, (MapNode) normalizedNode);
} else if (normalizedNode instanceof ValueNode) {
final ValueNode<NormalizedNode> valuesNode = (ValueNode) normalizedNode;
addYangLeaf(currentDataNode, valuesNode.getIdentifier().getNodeType().getLocalName(),
- valuesNode.body());
+ (Serializable) valuesNode.body());
} else if (normalizedNode instanceof LeafSetNode) {
addYangLeafList(currentDataNode, (LeafSetNode<?>) normalizedNode);
} else {
@@ -199,8 +206,9 @@ public class DataNodeBuilder {
}
}
- private static void addYangLeaf(final DataNode currentDataNode, final String leafName, final Object leafValue) {
- final Map<String, Object> leaves = new ImmutableMap.Builder<String, Object>()
+ private static void addYangLeaf(final DataNode currentDataNode, final String leafName,
+ final Serializable leafValue) {
+ final Map<String, Serializable> leaves = new ImmutableMap.Builder<String, Serializable>()
.putAll(currentDataNode.getLeaves())
.put(leafName, leafValue)
.build();
@@ -213,7 +221,7 @@ public class DataNodeBuilder {
.stream()
.map(normalizedNode -> (normalizedNode).body())
.collect(Collectors.toUnmodifiableList());
- addYangLeaf(currentDataNode, leafListName, leafListValues);
+ addYangLeaf(currentDataNode, leafListName, (Serializable) leafListValues);
}
private static void addDataNodeForEachListElement(final DataNode currentDataNode, final MapNode mapNode) {
@@ -236,4 +244,13 @@ public class DataNodeBuilder {
return newChildDataNode;
}
+ private static void addChoiceNode(final DataNode currentDataNode, final ChoiceNode choiceNode) {
+
+ final Collection<DataContainerChild> normalizedChildNodes = choiceNode.body();
+ for (final NormalizedNode normalizedNode : normalizedChildNodes) {
+ addDataNodeFromNormalizedNode(currentDataNode, normalizedNode);
+ }
+ }
+
+
}
diff --git a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
index 48241ed392..9a61579b12 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2021 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,13 +40,14 @@ import lombok.extern.slf4j.Slf4j;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactory;
import org.opendaylight.yangtools.yang.data.codec.gson.JSONCodecFactorySupplier;
import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@@ -62,38 +64,40 @@ public class YangUtils {
private static final String XPATH_NODE_KEY_ATTRIBUTES_REGEX = "\\[.*?\\]";
/**
- * Parses jsonData into NormalizedNode according to given schema context.
+ * Parses jsonData into Collection of NormalizedNode according to given schema context.
*
* @param jsonData json data as string
* @param schemaContext schema context describing associated data model
- * @return the NormalizedNode object
+ * @return the Collection of NormalizedNode object
*/
- public static NormalizedNode parseJsonData(final String jsonData, final SchemaContext schemaContext) {
+ public static ContainerNode parseJsonData(final String jsonData, final SchemaContext schemaContext) {
return parseJsonData(jsonData, schemaContext, Optional.empty());
}
/**
- * Parses jsonData into NormalizedNode according to given schema context.
+ * Parses jsonData into Collection of NormalizedNode according to given schema context.
*
* @param jsonData json data fragment as string
* @param schemaContext schema context describing associated data model
* @param parentNodeXpath the xpath referencing the parent node current data fragment belong to
* @return the NormalizedNode object
*/
- public static NormalizedNode parseJsonData(final String jsonData, final SchemaContext schemaContext,
+ public static ContainerNode parseJsonData(final String jsonData, final SchemaContext schemaContext,
final String parentNodeXpath) {
final Collection<QName> dataSchemaNodeIdentifiers =
getDataSchemaNodeIdentifiersByXpath(parentNodeXpath, schemaContext);
return parseJsonData(jsonData, schemaContext, Optional.of(dataSchemaNodeIdentifiers));
}
- private static NormalizedNode parseJsonData(final String jsonData, final SchemaContext schemaContext,
+ private static ContainerNode parseJsonData(final String jsonData, final SchemaContext schemaContext,
final Optional<Collection<QName>> dataSchemaNodeIdentifiers) {
final JSONCodecFactory jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02
.getShared((EffectiveModelContext) schemaContext);
- final NormalizedNodeResult normalizedNodeResult = new NormalizedNodeResult();
+ final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> dataContainerNodeBuilder =
+ Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()));
final NormalizedNodeStreamWriter normalizedNodeStreamWriter = ImmutableNormalizedNodeStreamWriter
- .from(normalizedNodeResult);
+ .from(dataContainerNodeBuilder);
final JsonReader jsonReader = new JsonReader(new StringReader(jsonData));
final JsonParserStream jsonParserStream;
@@ -119,7 +123,7 @@ public class YangUtils {
"Failed to parse json data. Unsupported xpath or json data:" + jsonData, illegalStateException
.getMessage(), illegalStateException);
}
- return normalizedNodeResult.getResult();
+ return dataContainerNodeBuilder.build();
}
/**
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
index b60e7e86e0..b78ab8a451 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
@@ -3,6 +3,7 @@
* Copyright (C) 2021-2022 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2021-2022 Bell Canada.
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,17 +63,22 @@ class CpsDataServiceImplSpec extends Specification {
def 'Saving json data.'() {
given: 'schema set for given anchor and dataspace references test-tree model'
- setupSchemaSetMocks('test-tree.yang')
+ setupSchemaSetMocks('multipleDataTree.yang')
when: 'save data method is invoked with test-tree json data'
- def jsonData = TestUtils.getResourceFileContent('test-tree.json')
+ def jsonData = TestUtils.getResourceFileContent('multiple-object-data.json')
objectUnderTest.saveData(dataspaceName, anchorName, jsonData, observedTimestamp)
then: 'the persistence service method is invoked with correct parameters'
- 1 * mockCpsDataPersistenceService.storeDataNode(dataspaceName, anchorName,
- { dataNode -> dataNode.xpath == '/test-tree' })
+ 1 * mockCpsDataPersistenceService.storeDataNodes(dataspaceName, anchorName,
+ { dataNode -> dataNode.xpath[index] == xpath })
and: 'the CpsValidator is called on the dataspaceName and AnchorName'
1 * mockCpsValidator.validateNameCharacters(dataspaceName, anchorName)
and: 'data updated event is sent to notification service'
1 * mockNotificationService.processDataUpdatedEvent(dataspaceName, anchorName, '/', Operation.CREATE, observedTimestamp)
+ where:
+ index | xpath
+ 0 | '/first-container'
+ 1 | '/last-container'
+
}
def 'Saving child data fragment under existing node.'() {
@@ -82,8 +88,8 @@ class CpsDataServiceImplSpec extends Specification {
def jsonData = '{"branch": [{"name": "New"}]}'
objectUnderTest.saveData(dataspaceName, anchorName, '/test-tree', jsonData, observedTimestamp)
then: 'the persistence service method is invoked with correct parameters'
- 1 * mockCpsDataPersistenceService.addChildDataNode(dataspaceName, anchorName, '/test-tree',
- { dataNode -> dataNode.xpath == '/test-tree/branch[@name=\'New\']' })
+ 1 * mockCpsDataPersistenceService.addChildDataNodes(dataspaceName, anchorName, '/test-tree',
+ { dataNode -> dataNode.xpath[0] == '/test-tree/branch[@name=\'New\']' })
and: 'the CpsValidator is called on the dataspaceName and AnchorName'
1 * mockCpsValidator.validateNameCharacters(dataspaceName, anchorName)
and: 'data updated event is sent to notification service'
@@ -207,8 +213,8 @@ class CpsDataServiceImplSpec extends Specification {
when: 'replace data method is invoked with json data #jsonData and parent node xpath #parentNodeXpath'
objectUnderTest.updateDataNodeAndDescendants(dataspaceName, anchorName, parentNodeXpath, jsonData, observedTimestamp)
then: 'the persistence service method is invoked with correct parameters'
- 1 * mockCpsDataPersistenceService.updateDataNodeAndDescendants(dataspaceName, anchorName,
- { dataNode -> dataNode.xpath == expectedNodeXpath })
+ 1 * mockCpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName,
+ { dataNode -> dataNode.xpath[0] == expectedNodeXpath })
and: 'data updated event is sent to notification service'
1 * mockNotificationService.processDataUpdatedEvent(dataspaceName, anchorName, parentNodeXpath, Operation.UPDATE, observedTimestamp)
and: 'the CpsValidator is called on the dataspaceName and AnchorName'
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy
index 2fc85aa5a4..ccfb23b449 100755
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy
@@ -3,6 +3,7 @@
* Copyright (C) 2021-2022 Nordix Foundation.
* Modifications Copyright (C) 2021-2022 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,9 +91,9 @@ class E2ENetworkSliceSpec extends Specification {
when: 'saveData method is invoked'
cpsDataServiceImpl.saveData(dataspaceName, anchorName, jsonData, noTimestamp)
then: 'Parameters are validated and processing is delegated to persistence service'
- 1 * mockDataStoreService.storeDataNode('someDataspace', 'someAnchor', _) >>
+ 1 * mockDataStoreService.storeDataNodes('someDataspace', 'someAnchor', _) >>
{ args -> dataNodeStored = args[2]}
- def child = dataNodeStored.childDataNodes[0]
+ def child = dataNodeStored[0].childDataNodes[0]
assert child.childDataNodes.size() == 1
and: 'list of Tracking Area for a Coverage Area are stored with correct xpath and child nodes '
def listOfTAForCoverageArea = child.childDataNodes[0]
@@ -122,10 +123,10 @@ class E2ENetworkSliceSpec extends Specification {
when: 'saveData method is invoked'
cpsDataServiceImpl.saveData('someDataspace', 'someAnchor', jsonData, noTimestamp)
then: 'parameters are validated and processing is delegated to persistence service'
- 1 * mockDataStoreService.storeDataNode('someDataspace', 'someAnchor', _) >>
+ 1 * mockDataStoreService.storeDataNodes('someDataspace', 'someAnchor', _) >>
{ args -> dataNodeStored = args[2]}
and: 'the size of the tree is correct'
- def cpsRanInventory = TestUtils.getFlattenMapByXpath(dataNodeStored)
+ def cpsRanInventory = TestUtils.getFlattenMapByXpath(dataNodeStored[0])
assert cpsRanInventory.size() == 4
and: 'ran-inventory contains the correct child node'
def ranInventory = cpsRanInventory.get('/ran-inventory')
diff --git a/cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy
index fcfb4826d9..1559783e97 100644
--- a/cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/spi/model/DataNodeBuilderSpec.groovy
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2021-2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,18 +22,15 @@
package org.onap.cps.spi.model
import org.onap.cps.TestUtils
-import org.onap.cps.spi.model.DataNodeBuilder
import org.onap.cps.utils.DataMapUtils
import org.onap.cps.utils.YangUtils
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
-import org.opendaylight.yangtools.yang.common.QName
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode
import spock.lang.Specification
class DataNodeBuilderSpec extends Specification {
- Map<String, Map<String, Object>> expectedLeavesByXpathMap = [
+ Map<String, Map<String, Serializable>> expectedLeavesByXpathMap = [
'/test-tree' : [],
'/test-tree/branch[@name=\'Left\']' : [name: 'Left'],
'/test-tree/branch[@name=\'Left\']/nest' : [name: 'Small', birds: ['Sparrow', 'Robin', 'Finch']],
@@ -50,17 +48,17 @@ class DataNodeBuilderSpec extends Specification {
'ietf/ietf-inet-types@2013-07-15.yang'
]
- def 'Converting NormalizedNode (tree) to a DataNode (tree).'() {
+ def 'Converting ContainerNode (tree) to a DataNode (tree).'() {
given: 'the schema context for expected model'
def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
- and: 'the json data parsed into normalized node object'
+ and: 'the json data parsed into container node object'
def jsonData = TestUtils.getResourceFileContent('test-tree.json')
- def normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext)
- when: 'the normalized node is converted to a data node'
- def result = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).build()
+ def containerNode = YangUtils.parseJsonData(jsonData, schemaContext)
+ when: 'the container node is converted to a data node'
+ def result = new DataNodeBuilder().withContainerNode(containerNode).build()
def mappedResult = TestUtils.getFlattenMapByXpath(result)
- then: '5 DataNode objects with unique xpath were created in total'
+ then: '6 DataNode objects with unique xpath were created in total'
mappedResult.size() == 6
and: 'all expected xpaths were built'
mappedResult.keySet().containsAll(expectedLeavesByXpathMap.keySet())
@@ -70,16 +68,16 @@ class DataNodeBuilderSpec extends Specification {
}
}
- def 'Converting NormalizedNode (tree) to a DataNode (tree) for known parent node.'() {
+ def 'Converting ContainerNode (tree) to a DataNode (tree) for known parent node.'() {
given: 'a schema context for expected model'
def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
- and: 'the json data parsed into normalized node object'
+ and: 'the json data parsed into container node object'
def jsonData = '{ "branch": [{ "name": "Branch", "nest": { "name": "Nest", "birds": ["bird"] } }] }'
- def normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, "/test-tree")
- when: 'the normalized node is converted to a data node with parent node xpath defined'
+ def containerNode = YangUtils.parseJsonData(jsonData, schemaContext, "/test-tree")
+ when: 'the container node is converted to a data node with parent node xpath defined'
def result = new DataNodeBuilder()
- .withNormalizedNodeTree(normalizedNode)
+ .withContainerNode(containerNode)
.withParentNodeXpath("/test-tree")
.build()
def mappedResult = TestUtils.getFlattenMapByXpath(result)
@@ -90,15 +88,15 @@ class DataNodeBuilderSpec extends Specification {
.containsAll(['/test-tree/branch[@name=\'Branch\']', '/test-tree/branch[@name=\'Branch\']/nest'])
}
- def 'Converting NormalizedNode (tree) to a DataNode (tree) -- augmentation case.'() {
+ def 'Converting ContainerNode (tree) to a DataNode (tree) -- augmentation case.'() {
given: 'a schema context for expected model'
def yangResourceNameToContent = TestUtils.getYangResourcesAsMap(networkTopologyModelRfc8345)
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
- and: 'the json data parsed into normalized node object'
+ and: 'the json data parsed into container node object'
def jsonData = TestUtils.getResourceFileContent('ietf/data/ietf-network-topology-sample-rfc8345.json')
- def normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext)
- when: 'the normalized node is converted to a data node '
- def result = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).build()
+ def containerNode = YangUtils.parseJsonData(jsonData, schemaContext)
+ when: 'the container node is converted to a data node '
+ def result = new DataNodeBuilder().withContainerNode(containerNode).build()
def mappedResult = TestUtils.getFlattenMapByXpath(result)
then: 'all expected data nodes are populated'
mappedResult.size() == 32
@@ -122,17 +120,17 @@ class DataNodeBuilderSpec extends Specification {
])
}
- def 'Converting NormalizedNode (tree) to a DataNode (tree) for known parent node -- augmentation case.'() {
+ def 'Converting ContainerNode (tree) to a DataNode (tree) for known parent node -- augmentation case.'() {
given: 'a schema context for expected model'
def yangResourceNameToContent = TestUtils.getYangResourcesAsMap(networkTopologyModelRfc8345)
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
and: 'parent node xpath referencing augmentation node within a model'
def parentNodeXpath = "/networks/network[@network-id='otn-hc']/link[@link-id='D1,1-2-1,D2,2-1-1']"
- and: 'the json data fragment parsed into normalized node object for given parent node xpath'
+ and: 'the json data fragment parsed into container node object for given parent node xpath'
def jsonData = '{"source": {"source-node": "D1", "source-tp": "1-2-1"}}'
- def normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath)
- when: 'the normalized node is converted to a data node with given parent node xpath'
- def result = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode)
+ def containerNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath)
+ when: 'the container node is converted to a data node with given parent node xpath'
+ def result = new DataNodeBuilder().withContainerNode(containerNode)
.withParentNodeXpath(parentNodeXpath).build()
then: 'the resulting data node represents a child of augmentation node'
assert result.xpath == "/networks/network[@network-id='otn-hc']/link[@link-id='D1,1-2-1,D2,2-1-1']/source"
@@ -140,16 +138,35 @@ class DataNodeBuilderSpec extends Specification {
assert result.leaves['source-tp'] == '1-2-1'
}
- def 'Converting NormalizedNode into DataNode collection: #scenario.'() {
+ def 'Converting ContainerNode (tree) to a DataNode (tree) -- with ChoiceNode.'() {
+ given: 'a schema context for expected model'
+ def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('yang-with-choice-node.yang')
+ def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
+ and: 'the json data fragment parsed into container node object'
+ def jsonData = TestUtils.getResourceFileContent('data-with-choice-node.json')
+ def containerNode = YangUtils.parseJsonData(jsonData, schemaContext)
+ when: 'the container node is converted to a data node'
+ def result = new DataNodeBuilder().withContainerNode(containerNode).build()
+ def mappedResult = TestUtils.getFlattenMapByXpath(result)
+ then: 'the resulting data node contains only one xpath with 3 leaves'
+ mappedResult.keySet().containsAll([
+ "/container-with-choice-leaves"
+ ])
+ assert result.leaves['leaf-1'] == "test"
+ assert result.leaves['choice-case1-leaf-a'] == "test"
+ assert result.leaves['choice-case1-leaf-b'] == "test"
+ }
+
+ def 'Converting ContainerNode into DataNode collection: #scenario.'() {
given: 'a schema context for expected model'
def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
and: 'parent node xpath referencing parent of list element'
def parentNodeXpath = "/test-tree"
- and: 'the json data fragment (list element) parsed into normalized node object'
- def normalizedNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath)
- when: 'the normalized node is converted to a data node collection'
- def result = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode)
+ and: 'the json data fragment (list element) parsed into container node object'
+ def containerNode = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath)
+ when: 'the container node is converted to a data node collection'
+ def result = new DataNodeBuilder().withContainerNode(containerNode)
.withParentNodeXpath(parentNodeXpath).buildCollection()
def resultXpaths = result.collect { it.getXpath() }
then: 'the resulting collection contains data nodes for expected list elements'
@@ -161,16 +178,15 @@ class DataNodeBuilderSpec extends Specification {
'multiple entries' | '{"branch": [{"name": "One"}, {"name": "Two"}]}' | 2 | ['/test-tree/branch[@name=\'One\']', '/test-tree/branch[@name=\'Two\']']
}
- def 'Converting NormalizedNode to a DataNode collection -- edge cases: #scenario.'() {
- when: 'the normalized node is #node'
- def result = new DataNodeBuilder().withNormalizedNodeTree(normalizedNode).buildCollection()
+ def 'Converting ContainerNode to a DataNode collection -- edge cases: #scenario.'() {
+ when: 'the container node is #node'
+ def result = new DataNodeBuilder().withContainerNode(containerNode).buildCollection()
then: 'the resulting collection contains data nodes for expected list elements'
- assert result.size() == expectedSize
- assert result.containsAll(expectedNodes)
+ assert result.isEmpty()
where: 'following parameters are used'
- scenario | node | normalizedNode | expectedSize | expectedNodes
- 'NormalizedNode is null' | 'null' | null | 1 | [ new DataNode() ]
- 'NormalizedNode is an unsupported type' | 'not supported' | Mock(NormalizedNode) | 0 | [ ]
+ scenario | containerNode
+ 'ContainerNode is null' | null
+ 'ContainerNode is an unsupported type' | Mock(ContainerNode)
}
def 'Use of adding the module name prefix attribute of data node.'() {
diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/JsonParserStreamSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/JsonParserStreamSpec.groovy
index 40f0e0a2ae..2eede23913 100644
--- a/cps-service/src/test/groovy/org/onap/cps/utils/JsonParserStreamSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/utils/JsonParserStreamSpec.groovy
@@ -1,3 +1,24 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.cps.utils
import com.google.gson.stream.JsonReader
@@ -26,10 +47,10 @@ class JsonParserStreamSpec extends Specification{
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
and: 'variable to store the result of parsing'
DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> builder =
- Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()));
- def normalizedNodeStreamWriter = ImmutableNormalizedNodeStreamWriter.from(builder);
+ Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()))
+ def normalizedNodeStreamWriter = ImmutableNormalizedNodeStreamWriter.from(builder)
def jsonCodecFactory = JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02
- .getShared((EffectiveModelContext) schemaContext);
+ .getShared((EffectiveModelContext) schemaContext)
and: 'JSON parser stream'
def jsonParserStream = JsonParserStream.create(normalizedNodeStreamWriter, jsonCodecFactory)
when: 'parsing is invoked with the given JSON reader'
diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy
index 65aa3af7d8..990b7186f7 100644
--- a/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/utils/YangUtilsSpec.groovy
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,14 +32,20 @@ import spock.lang.Specification
class YangUtilsSpec extends Specification {
def 'Parsing a valid Json String.'() {
given: 'a yang model (file)'
- def jsonData = org.onap.cps.TestUtils.getResourceFileContent('bookstore.json')
+ def jsonData = org.onap.cps.TestUtils.getResourceFileContent('multiple-object-data.json')
and: 'a model for that data'
- def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
+ def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('multipleDataTree.yang')
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
when: 'the json data is parsed'
- NormalizedNode result = YangUtils.parseJsonData(jsonData, schemaContext)
- then: 'the result is a normalized node of the correct type'
- result.getIdentifier().nodeType == QName.create('org:onap:ccsdk:sample', '2020-09-15', 'bookstore')
+ def result = YangUtils.parseJsonData(jsonData, schemaContext)
+ then: 'a ContainerNode holding collection of normalized nodes is returned'
+ result.body().getAt(index) instanceof NormalizedNode == true
+ then: 'qualified name of children created is as expected'
+ result.body().getAt(index).getIdentifier().nodeType == QName.create('org:onap:ccsdk:multiDataTree', '2020-09-15', nodeName)
+ where:
+ index | nodeName
+ 0 | 'first-container'
+ 1 | 'last-container'
}
def 'Parsing invalid data: #description.'() {
@@ -62,8 +69,10 @@ class YangUtilsSpec extends Specification {
def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
when: 'json string is parsed'
def result = YangUtils.parseJsonData(jsonData, schemaContext, parentNodeXpath)
+ then: 'a ContainerNode holding collection of normalized nodes is returned'
+ result.body().getAt(0) instanceof NormalizedNode == true
then: 'result represents a node of expected type'
- result.getIdentifier().nodeType == QName.create('org:onap:cps:test:test-tree', '2020-02-02', nodeName)
+ result.body().getAt(0).getIdentifier().nodeType == QName.create('org:onap:cps:test:test-tree', '2020-02-02', nodeName)
where:
scenario | jsonData | parentNodeXpath || nodeName
'list element as container' | '{ "branch": { "name": "B", "nest": { "name": "N", "birds": ["bird"] } } }' | '/test-tree' || 'branch'
diff --git a/cps-service/src/test/groovy/org/onap/cps/yang/YangTextSchemaSourceSetBuilderSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/yang/YangTextSchemaSourceSetBuilderSpec.groovy
index 236221aca7..6d570d6432 100644
--- a/cps-service/src/test/groovy/org/onap/cps/yang/YangTextSchemaSourceSetBuilderSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/yang/YangTextSchemaSourceSetBuilderSpec.groovy
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2021 Bell Canada.
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,11 +21,12 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.yang
+package org.onap.cps.utils.yang
import org.onap.cps.TestUtils
import org.onap.cps.spi.exceptions.ModelValidationException
+import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
import org.opendaylight.yangtools.yang.common.Revision
import spock.lang.Specification
diff --git a/cps-service/src/test/resources/data-with-choice-node.json b/cps-service/src/test/resources/data-with-choice-node.json
new file mode 100644
index 0000000000..5f81ed8ed7
--- /dev/null
+++ b/cps-service/src/test/resources/data-with-choice-node.json
@@ -0,0 +1,8 @@
+{
+ "container-with-choice-leaves": {
+ "leaf-1": "test",
+ "choice-case1-leaf-a": "test",
+ "choice-case1-leaf-b": "test"
+ }
+}
+
diff --git a/cps-service/src/test/resources/yang-with-choice-node.yang b/cps-service/src/test/resources/yang-with-choice-node.yang
new file mode 100644
index 0000000000..55c0bfbe62
--- /dev/null
+++ b/cps-service/src/test/resources/yang-with-choice-node.yang
@@ -0,0 +1,27 @@
+module yang-with-choice-node {
+ yang-version 1.1;
+ namespace "org:onap:cps:test:yang-with-choice-node";
+ prefix "yang-with-choice-node";
+
+ container container-with-choice-leaves {
+ leaf leaf-1 {
+ type string;
+ }
+
+ choice choicenode {
+ case case-1 {
+ leaf choice-case1-leaf-a {
+ type string;
+ }
+ leaf choice-case1-leaf-b {
+ type string;
+ }
+ }
+ case case-2 {
+ leaf choice-case2-leaf-a {
+ type string;
+ }
+ }
+ }
+ }
+}