summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java11
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java23
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/api/impl/NetworkCmProxyDataServiceImplSpec.groovy26
3 files changed, 56 insertions, 4 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
index 158f20ef93..8176ea50fa 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2021 highstreet technologies GmbH
* 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.
@@ -57,6 +58,16 @@ public interface NetworkCmProxyDataService {
@NonNull FetchDescendantsOption fetchDescendantsOption);
/**
+ * Creates data node with descendants at root level or under existing node (if parent node xpath is provided).
+ *
+ * @param cmHandle The identifier for a network function, network element, subnetwork or any other cm
+ * object managed by Network CM Proxy
+ * @param parentNodeXpath xpath to parent node or '/' for root level
+ * @param jsonData data as JSON string
+ */
+ void createDataNode(@NonNull String cmHandle, @NonNull String parentNodeXpath, @NonNull String jsonData);
+
+ /**
* Updates data node for given cm handle using xpath to parent node.
*
* @param cmHandle The identifier for a network function, network element, subnetwork or any other cm object
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index 9e013145da..56f4cf8dce 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2021 highstreet technologies GmbH
* 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.
@@ -28,6 +29,7 @@ import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
@Service
public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
@@ -40,25 +42,38 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
@Autowired
private CpsQueryService cpsQueryService;
+ private String getDataspaceName() {
+ return NF_PROXY_DATASPACE_NAME;
+ }
+
@Override
public DataNode getDataNode(final String cmHandle, final String xpath,
final FetchDescendantsOption fetchDescendantsOption) {
- return cpsDataService.getDataNode(NF_PROXY_DATASPACE_NAME, cmHandle, xpath, fetchDescendantsOption);
+ return cpsDataService.getDataNode(getDataspaceName(), cmHandle, xpath, fetchDescendantsOption);
}
@Override
public Collection<DataNode> queryDataNodes(final String cmHandle, final String cpsPath,
final FetchDescendantsOption fetchDescendantsOption) {
- return cpsQueryService.queryDataNodes(NF_PROXY_DATASPACE_NAME, cmHandle, cpsPath, fetchDescendantsOption);
+ return cpsQueryService.queryDataNodes(getDataspaceName(), cmHandle, cpsPath, fetchDescendantsOption);
+ }
+
+ @Override
+ public void createDataNode(final String cmHandle, final String parentNodeXpath, final String jsonData) {
+ if (StringUtils.isEmpty(parentNodeXpath) || "/".equals(parentNodeXpath)) {
+ cpsDataService.saveData(getDataspaceName(), cmHandle, jsonData);
+ } else {
+ cpsDataService.saveData(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
+ }
}
@Override
public void updateNodeLeaves(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService.updateNodeLeaves(NF_PROXY_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData);
+ cpsDataService.updateNodeLeaves(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
}
@Override
public void replaceNodeTree(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService.replaceNodeTree(NF_PROXY_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData);
+ cpsDataService.replaceNodeTree(getDataspaceName(), cmHandle, parentNodeXpath, jsonData);
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
index 49028becd7..95493bf51e 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/api/impl/NetworkCmProxyDataServiceImplSpec.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.
@@ -24,6 +25,7 @@ import org.onap.cps.api.CpsQueryService
import org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServiceImpl
import org.onap.cps.spi.FetchDescendantsOption
import spock.lang.Specification
+import spock.lang.Unroll
class NetworkCmProxyDataServiceImplSpec extends Specification {
def objectUnderTest = new NetworkCmProxyDataServiceImpl()
@@ -49,6 +51,30 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
fetchDescendantsOption << FetchDescendantsOption.values()
}
+ @Unroll
+ def 'Create full data node: #scenario.'() {
+ given: 'a cm handle and root xpath'
+ def jsonData = 'some json'
+ when: 'createDataNode is invoked'
+ objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
+ then: 'the CPS service method is invoked once with the expected parameters'
+ 1 * mockcpsDataService.saveData(expectedDataspaceName, cmHandle, jsonData)
+ where: 'following parameters were used'
+ scenario | xpath
+ 'no xpath' | ''
+ 'root level xpath' | '/'
+ }
+
+ def 'Create child data node.'() {
+ given: 'a cm handle and parent node xpath'
+ def jsonData = 'some json'
+ def xpath = '/test-node'
+ when: 'createDataNode is invoked'
+ objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
+ then: 'the CPS service method is invoked once with the expected parameters'
+ 1 * mockcpsDataService.saveData(expectedDataspaceName, cmHandle, xpath, jsonData)
+ }
+
def 'Update data node leaves.'() {
given: 'a cm Handle and a cps path'
def xpath = '/xpath'