aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java16
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java7
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy20
3 files changed, 43 insertions, 0 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
index 54d9258918..8552c6c0d8 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
@@ -22,6 +22,8 @@ package org.onap.cps.api;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.spi.FetchDescendantsOption;
+import org.onap.cps.spi.exceptions.AlreadyDefinedException;
+import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.model.DataNode;
@@ -41,6 +43,20 @@ public interface CpsDataService {
void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String jsonData);
/**
+ * Persists child data fragment under existing data node for the given anchor and dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param parentNodeXpath parent node xpath
+ * @param jsonData json data
+ * @throws DataValidationException when json data is invalid
+ * @throws DataNodeNotFoundException when parent node cannot be found by parent node xpath
+ * @throws AlreadyDefinedException when child data node with same xpath already exists
+ */
+ void saveData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
+ @NonNull String jsonData);
+
+ /**
* Retrieves datanode by XPath for given dataspace and anchor.
*
* @param dataspaceName dataspace name
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 6f7d6439b6..cc290bf29d 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
@@ -59,6 +59,13 @@ public class CpsDataServiceImpl implements CpsDataService {
}
@Override
+ public void saveData(final String dataspaceName, final String anchorName, final String parentNodeXpath,
+ final String jsonData) {
+ final DataNode dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ cpsDataPersistenceService.addChildDataNode(dataspaceName, anchorName, parentNodeXpath, dataNode);
+ }
+
+ @Override
public DataNode getDataNode(final String dataspaceName, final String anchorName, final String xpath,
final FetchDescendantsOption fetchDescendantsOption) {
return cpsDataPersistenceService.getDataNode(dataspaceName, anchorName, xpath, fetchDescendantsOption);
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 d561475273..29a2314a33 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
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Nordix Foundation
+ * Modifications Copyright (C) 2021 Pantheon.tech
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,6 +70,25 @@ class CpsDataServiceImplSpec extends Specification {
{ dataNode -> dataNode.xpath == '/test-tree' })
}
+ def 'Saving child data fragment under existing node.'() {
+ given: 'that the admin service will return an anchor'
+ def anchor = Anchor.builder().name(anchorName).schemaSetName(schemaSetName).build()
+ mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> anchor
+ and: 'the schema source set cache returns a schema source set'
+ def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
+ mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> mockYangTextSchemaSourceSet
+ and: 'the schema source sets returns the test-tree schema context'
+ def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
+ def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+ mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+ when: 'save data method is invoked with test-tree json data'
+ def jsonData = '{"branch": [{"name": "New"}]}'
+ objectUnderTest.saveData(dataspaceName, anchorName, '/test-tree',jsonData)
+ 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\']' })
+ }
+
@Unroll
def 'Get data node with option #fetchDescendantsOption.'() {
def xpath = '/xpath'