summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcps-ncmp-rest/docs/openapi/ncmproxy.yml25
-rwxr-xr-xcps-ncmp-rest/docs/openapi/openapi.yml3
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java28
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy25
-rw-r--r--cps-ncmp-service/pom.xml4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java28
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java47
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java88
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy96
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy17
10 files changed, 310 insertions, 51 deletions
diff --git a/cps-ncmp-rest/docs/openapi/ncmproxy.yml b/cps-ncmp-rest/docs/openapi/ncmproxy.yml
index ede0ec62f0..b2e14d714a 100755
--- a/cps-ncmp-rest/docs/openapi/ncmproxy.yml
+++ b/cps-ncmp-rest/docs/openapi/ncmproxy.yml
@@ -225,4 +225,29 @@ getResourceDataForPassthroughOperational:
403:
$ref: 'components.yaml#/components/responses/Forbidden'
404:
+ $ref: 'components.yaml#/components/responses/NotFound'
+
+resourceDataForPassthroughRunning:
+ get:
+ tags:
+ - network-cm-proxy
+ summary: Get resource data from pass-through running for cm handle
+ description: Get resource data from pass-through running for given cm handle
+ operationId: getResourceDataRunningForCmHandle
+ parameters:
+ - $ref: 'components.yaml#/components/parameters/cmHandleInPath'
+ - $ref: 'components.yaml#/components/parameters/resourceIdentifierInPath'
+ - $ref: 'components.yaml#/components/parameters/acceptParamInHeader'
+ - $ref: 'components.yaml#/components/parameters/fieldsParamInQuery'
+ - $ref: 'components.yaml#/components/parameters/depthParamInQuery'
+ responses:
+ 200:
+ $ref: 'components.yaml#/components/responses/Ok'
+ 400:
+ $ref: 'components.yaml#/components/responses/BadRequest'
+ 401:
+ $ref: 'components.yaml#/components/responses/Unauthorized'
+ 403:
+ $ref: 'components.yaml#/components/responses/Forbidden'
+ 404:
$ref: 'components.yaml#/components/responses/NotFound' \ No newline at end of file
diff --git a/cps-ncmp-rest/docs/openapi/openapi.yml b/cps-ncmp-rest/docs/openapi/openapi.yml
index 5b7c8d205b..0dfe3c83a7 100755
--- a/cps-ncmp-rest/docs/openapi/openapi.yml
+++ b/cps-ncmp-rest/docs/openapi/openapi.yml
@@ -43,4 +43,5 @@ paths:
/v1/ch/{cm-handle}/data/ds/ncmp-datastore:passthrough-operational/{resourceIdentifier}:
$ref: 'ncmproxy.yml#/getResourceDataForPassthroughOperational'
- \ No newline at end of file
+ /v1/ch/{cm-handle}/data/ds/ncmp-datastore:passthrough-running/{resourceIdentifier}:
+ $ref: 'ncmproxy.yml#/resourceDataForPassthroughRunning' \ No newline at end of file
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
index b35b245aab..587787e2df 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
@@ -153,7 +153,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
}
/**
- * Get resource data for for operational datastore.
+ * Get resource data from operational datastore.
*
* @param cmHandle cm handle identifier
* @param resourceIdentifier resource identifier
@@ -168,7 +168,31 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
final String accept,
final @Valid String fields,
final @Min(1) @Valid Integer depth) {
- final var responseObject = networkCmProxyDataService.getResourceDataOperationalFoCmHandle(cmHandle,
+ final Object responseObject = networkCmProxyDataService.getResourceDataOperationalForCmHandle(cmHandle,
+ resourceIdentifier,
+ accept,
+ fields,
+ depth);
+ return ResponseEntity.ok(responseObject);
+ }
+
+ /**
+ * Get resource data from pass-through running datastore.
+ *
+ * @param cmHandle cm handle identifier
+ * @param resourceIdentifier resource identifier
+ * @param accept accept header parameter
+ * @param fields fields query parameter
+ * @param depth depth query parameter
+ * @return {@code ResponseEntity} response from dmi plugin
+ */
+ @Override
+ public ResponseEntity<Object> getResourceDataRunningForCmHandle(final String cmHandle,
+ final String resourceIdentifier,
+ final String accept,
+ final @Valid String fields,
+ final @Min(1) @Valid Integer depth) {
+ final Object responseObject = networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceIdentifier,
accept,
fields,
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
index b2a060c278..a7fa309013 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
@@ -206,8 +206,8 @@ class NetworkCmProxyControllerSpec extends Specification {
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON_VALUE)
).andReturn().response
- then: 'the NCMP data service is called with getResourceDataOperationalFoCmHandle'
- 1 * mockNetworkCmProxyDataService.getResourceDataOperationalFoCmHandle('testCmHandle',
+ then: 'the NCMP data service is called with getResourceDataOperationalForCmHandle'
+ 1 * mockNetworkCmProxyDataService.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceIdentifier',
'application/json',
'testFields',
@@ -216,5 +216,26 @@ class NetworkCmProxyControllerSpec extends Specification {
response.status == HttpStatus.OK.value()
}
+ def 'Get Resource Data from pass-through running.' () {
+ given: 'resource data url'
+ def getUrl = "$basePath/v1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
+ "/testResourceIdentifier?fields=testFields&depth=5"
+ and: 'ncmp service returns json object'
+ mockNetworkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceIdentifier',
+ 'application/json',
+ 'testFields',
+ 5) >> '{valid-json}'
+ when: 'get data resource request is performed'
+ def response = mvc.perform(
+ get(getUrl)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON_VALUE)
+ ).andReturn().response
+ then: 'response status is Ok'
+ response.status == HttpStatus.OK.value()
+ and: 'response contains valid object body'
+ response.getContentAsString() == '{valid-json}'
+ }
}
diff --git a/cps-ncmp-service/pom.xml b/cps-ncmp-service/pom.xml
index f786b80562..fc01c3b1ca 100644
--- a/cps-ncmp-service/pom.xml
+++ b/cps-ncmp-service/pom.xml
@@ -66,5 +66,9 @@
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-validation</artifactId>
+ </dependency>
</dependencies>
</project>
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 82be7bf55c..3e715e5e75 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
@@ -23,6 +23,7 @@
package org.onap.cps.ncmp.api;
import java.util.Collection;
+import javax.validation.constraints.NotNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.spi.FetchDescendantsOption;
@@ -117,9 +118,26 @@ public interface NetworkCmProxyDataService {
* @param depth depth query
* @return {@code Object} resource data
*/
- Object getResourceDataOperationalFoCmHandle(@NonNull String cmHandle,
- @NonNull String resourceIdentifier,
- String accept,
- String fields,
- Integer depth);
+ Object getResourceDataOperationalForCmHandle(@NotNull String cmHandle,
+ @NotNull String resourceIdentifier,
+ String accept,
+ String fields,
+ Integer depth);
+
+ /**
+ * Get resource data for data store pass-through running
+ * using dmi.
+ *
+ * @param cmHandle cm handle
+ * @param resourceIdentifier resource identifier
+ * @param accept accept param
+ * @param fields fields query
+ * @param depth depth query
+ * @return {@code Object} resource data
+ */
+ Object getResourceDataPassThroughRunningForCmHandle(@NotNull String cmHandle,
+ @NotNull String resourceIdentifier,
+ String accept,
+ String fields,
+ Integer depth);
}
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 0b9cb5ad59..1ea95d3e65 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
@@ -29,6 +29,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import javax.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.api.CpsQueryService;
@@ -173,17 +174,17 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
@Override
- public Object getResourceDataOperationalFoCmHandle(final String cmHandle,
- final String resourceIdentifier,
- final String acceptParam,
- final String fieldsQueryParam,
- final Integer depthQueryParam) {
-
- final DataNode dataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
- final String dmiServiceName = String.valueOf(dataNode.getLeaves().get("dmi-service-name"));
+ public Object getResourceDataOperationalForCmHandle(final @NotNull String cmHandle,
+ final @NotNull String resourceIdentifier,
+ final String acceptParam,
+ final String fieldsQueryParam,
+ final Integer depthQueryParam) {
+
+ final var dataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
+ final var dmiServiceName = String.valueOf(dataNode.getLeaves().get("dmi-service-name"));
final Collection<DataNode> additionalPropsList = dataNode.getChildDataNodes();
- final String jsonBody = prepareOperationBody(GenericRequestBody.OperationEnum.READ, additionalPropsList);
- final ResponseEntity<Object> response = dmiOperations.getResouceDataFromDmi(dmiServiceName,
+ final var jsonBody = prepareOperationBody(GenericRequestBody.OperationEnum.READ, additionalPropsList);
+ final ResponseEntity<Object> response = dmiOperations.getResouceDataOperationalFromDmi(dmiServiceName,
cmHandle,
resourceIdentifier,
fieldsQueryParam,
@@ -193,6 +194,26 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return handleResponse(response);
}
+ @Override
+ public Object getResourceDataPassThroughRunningForCmHandle(final @NotNull String cmHandle,
+ final @NotNull String resourceIdentifier,
+ final String accept,
+ final String fields,
+ final Integer depth) {
+ final var cmHandleDataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
+ final var dmiServiceName = String.valueOf(cmHandleDataNode.getLeaves().get("dmi-service-name"));
+ final Collection<DataNode> additionalPropsList = cmHandleDataNode.getChildDataNodes();
+ final var dmiRequesBody = prepareOperationBody(GenericRequestBody.OperationEnum.READ, additionalPropsList);
+ final ResponseEntity<Object> response = dmiOperations.getResouceDataPassThroughRunningFromDmi(dmiServiceName,
+ cmHandle,
+ resourceIdentifier,
+ fields,
+ depth,
+ accept,
+ dmiRequesBody);
+ return handleResponse(response);
+ }
+
private DataNode fetchDataNodeFromDmiRegistryForCmHandle(final String cmHandle) {
final String xpathForDmiRegistryToFetchCmHandle = "/dmi-registry/cm-handles[@id='" + cmHandle + "']";
final var dataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME,
@@ -204,12 +225,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private String prepareOperationBody(final GenericRequestBody.OperationEnum operation,
final Collection<DataNode> additionalPropertyList) {
- final GenericRequestBody requestBody = new GenericRequestBody();
+ final var requestBody = new GenericRequestBody();
final Map<String, String> additionalPropertyMap = getAdditionalPropertiesMap(additionalPropertyList);
requestBody.setOperation(GenericRequestBody.OperationEnum.READ);
requestBody.setCmHandleProperties(additionalPropertyMap);
try {
- final String requestJson = objectMapper.writeValueAsString(requestBody);
+ final var requestJson = objectMapper.writeValueAsString(requestBody);
return requestJson;
} catch (final JsonProcessingException je) {
log.error("Parsing error occurred while converting Object to JSON.");
@@ -223,7 +244,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return null;
}
final Map<String, String> additionalPropertyMap = new LinkedHashMap<>();
- for (final DataNode node: additionalPropertyList) {
+ for (final var node: additionalPropertyList) {
additionalPropertyMap.put(String.valueOf(node.getLeaves().get("name")),
String.valueOf(node.getLeaves().get("value")));
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java
index c7554bc482..2b13d165f2 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java
@@ -20,6 +20,8 @@
package org.onap.cps.ncmp.api.impl.operation;
+import com.fasterxml.jackson.annotation.JsonValue;
+import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.onap.cps.ncmp.api.impl.client.DmiRestClient;
import org.springframework.http.HttpHeaders;
@@ -29,10 +31,27 @@ import org.springframework.stereotype.Component;
@Component
public class DmiOperations {
+ @Getter
+ public enum PassThroughEnum {
+ OPERATIONAL("/ncmp-datastore:passthrough-operational/"),
+ RUNNING("/ncmp-datastore:passthrough-running/");
+ private String value;
+
+ PassThroughEnum(final String value) {
+ this.value = value;
+ }
+
+ @Override
+ @JsonValue
+ public String toString() {
+ return String.valueOf(value);
+ }
+ }
+
private DmiRestClient dmiRestClient;
- private static final String GET_RESOURCE_DATA_FOR_PASSTHROUGH_OPERATIONAL =
- "/v1/ch/{cmHandle}/data/ds/ncmp-datastore:passthrough-operational/";
- private int indexCmHandleForGetOperational;
+ private static final String PARENT_CM_HANDLE_URI =
+ "/v1/ch/{cmHandle}/data/ds";
+ private final int indexCmHandleInUri;
/**
* Constructor for {@code DmiOperations}. This method also manipulates url properties.
@@ -41,12 +60,38 @@ public class DmiOperations {
*/
public DmiOperations(final DmiRestClient dmiRestClient) {
this.dmiRestClient = dmiRestClient;
- indexCmHandleForGetOperational = GET_RESOURCE_DATA_FOR_PASSTHROUGH_OPERATIONAL.indexOf("{cmHandle}");
+ indexCmHandleInUri = PARENT_CM_HANDLE_URI.indexOf("{cmHandle}");
+ }
+
+ /**
+ * This method fetches the resource data from operational data store for given cm handle
+ * identifier on given resource using dmi client.
+ *
+ * @param dmiBasePath dmi base path
+ * @param cmHandle network resource identifier
+ * @param resourceId resource identifier
+ * @param fieldsQuery fields query
+ * @param depthQuery depth query
+ * @param acceptParam accept parameter
+ * @param jsonBody json body for put operation
+ * @return {@code ResponseEntity} response entity
+ */
+ public ResponseEntity<Object> getResouceDataOperationalFromDmi(final String dmiBasePath,
+ final String cmHandle,
+ final String resourceId,
+ final String fieldsQuery,
+ final Integer depthQuery,
+ final String acceptParam,
+ final String jsonBody) {
+ final var builder = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId,
+ fieldsQuery, depthQuery, PassThroughEnum.OPERATIONAL);
+ final var httpHeaders = prepareHeader(acceptParam);
+ return dmiRestClient.putOperationWithJsonData(builder.toString(), jsonBody, httpHeaders);
}
/**
- * This method fetches the resource data for given cm handle identifier on given resource
- * using dmi client.
+ * This method fetches the resource data from pass-through running data store for given cm handle
+ * identifier on given resource using dmi client.
*
* @param dmiBasePath dmi base path
* @param cmHandle network resource identifier
@@ -57,15 +102,16 @@ public class DmiOperations {
* @param jsonBody json body for put operation
* @return {@code ResponseEntity} response entity
*/
- public ResponseEntity<Object> getResouceDataFromDmi(final String dmiBasePath,
- final String cmHandle,
- final String resourceId,
- final String fieldsQuery,
- final Integer depthQuery,
- final String acceptParam,
- final String jsonBody) {
- final StringBuilder builder = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId, fieldsQuery, depthQuery);
- final HttpHeaders httpHeaders = prepareHeader(acceptParam);
+ public ResponseEntity<Object> getResouceDataPassThroughRunningFromDmi(final String dmiBasePath,
+ final String cmHandle,
+ final String resourceId,
+ final String fieldsQuery,
+ final Integer depthQuery,
+ final String acceptParam,
+ final String jsonBody) {
+ final var builder = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId,
+ fieldsQuery, depthQuery, PassThroughEnum.RUNNING);
+ final var httpHeaders = prepareHeader(acceptParam);
return dmiRestClient.putOperationWithJsonData(builder.toString(), jsonBody, httpHeaders);
}
@@ -74,10 +120,10 @@ public class DmiOperations {
final String cmHandle,
final String resourceId,
final String fieldsQuery,
- final Integer depthQuery) {
- final StringBuilder builder = new StringBuilder(GET_RESOURCE_DATA_FOR_PASSTHROUGH_OPERATIONAL);
- builder.replace(indexCmHandleForGetOperational,
- indexCmHandleForGetOperational + "{cmHandle}".length(), cmHandle);
+ final Integer depthQuery,
+ final PassThroughEnum passThrough) {
+ final var builder = new StringBuilder(PARENT_CM_HANDLE_URI.replace("{cmHandle}", cmHandle));
+ builder.append(passThrough.getValue());
builder.insert(builder.length(), resourceId);
appendFieldsAndDepth(fieldsQuery, depthQuery, builder);
builder.insert(0, dmiBasePath);
@@ -85,7 +131,7 @@ public class DmiOperations {
}
private void appendFieldsAndDepth(final String fieldsQuery, final Integer depthQuery, final StringBuilder builder) {
- final boolean doesFieldExists = (fieldsQuery != null && !fieldsQuery.isEmpty());
+ final var doesFieldExists = (fieldsQuery != null && !fieldsQuery.isEmpty());
if (doesFieldExists) {
builder.append("?").append("fields=").append(fieldsQuery);
}
@@ -100,7 +146,7 @@ public class DmiOperations {
}
private HttpHeaders prepareHeader(final String acceptParam) {
- final HttpHeaders httpHeaders = new HttpHeaders();
+ final var httpHeaders = new HttpHeaders();
if (acceptParam != null && !acceptParam.isEmpty()) {
httpHeaders.set(HttpHeaders.ACCEPT, acceptParam);
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
index 6b32a2dc7a..f356ce66c1 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
@@ -141,7 +141,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
childDataNode.leaves = ['name':'testName','value':'testValue']
dataNode.childDataNodes = [childDataNode]
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataOperationalFoCmHandle('testCmHandle',
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
@@ -149,8 +149,8 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
then: 'cps data service is being called once to get data node'
1 * mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
- and: 'dmi operation is being calle to get resource data'
- 1 * mockDmiOperations.getResouceDataFromDmi('testDmiService',
+ and: 'dmi operation is being called to get resource data'
+ 1 * mockDmiOperations.getResouceDataOperationalFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -176,7 +176,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
objectUnderTest.objectMapper = mockObjectMapper
mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException("testException") }
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataOperationalFoCmHandle('testCmHandle',
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
@@ -196,7 +196,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
and: 'dmi returns NOK response'
- mockDmiOperations.getResouceDataFromDmi('testDmiService',
+ mockDmiOperations.getResouceDataOperationalFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -205,7 +205,91 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
>> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataOperationalFoCmHandle('testCmHandle',
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ 'testFieldQuery',
+ 5)
+ then: 'exception is thrown'
+ thrown(NcmpException.class)
+ }
+ def 'Get resource data for pass-through running from dmi.'() {
+ given: 'xpath'
+ def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ and: 'data node representing cmhandle and its properties'
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name':'testDmiService']
+ def childDataNode = new DataNode()
+ childDataNode.leaves = ['name':'testName','value':'testValue']
+ dataNode.childDataNodes = [childDataNode]
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'dmi returns valid response and data'
+ mockDmiOperations.getResouceDataPassThroughRunningFromDmi('testDmiService',
+ 'testCmHandle',
+ 'testResourceId',
+ 'testFieldQuery',
+ 5,
+ 'testAcceptParam',
+ '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('{result-json}', HttpStatus.OK)
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ 'testFieldQuery',
+ 5)
+ then: 'get resource data returns expected response'
+ response == '{result-json}'
+ }
+ def 'Get resource data for pass-through running from dmi threw parsing exception.'() {
+ given: 'xpath'
+ def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ and: 'data node representing cmhandle and its properties'
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name':'testDmiService']
+ def childDataNode = new DataNode()
+ childDataNode.leaves = ['name':'testName','value':'testValue']
+ dataNode.childDataNodes = [childDataNode]
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'objectMapper not able to parse object'
+ def mockObjectMapper = Mock(ObjectMapper)
+ objectUnderTest.objectMapper = mockObjectMapper
+ mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException("testException") }
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ 'testFieldQuery',
+ 5)
+ then: 'exception is thrown'
+ thrown(NcmpException.class)
+ }
+ def 'Get resource data for pass-through running from dmi return NOK response.'() {
+ given: 'xpath'
+ def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ and: 'data node representing cmhandle and its properties'
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name':'testDmiService']
+ def childDataNode = new DataNode()
+ childDataNode.leaves = ['name':'testName','value':'testValue']
+ dataNode.childDataNodes = [childDataNode]
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'dmi returns NOK response'
+ mockDmiOperations.getResouceDataPassThroughRunningFromDmi('testDmiService',
+ 'testCmHandle',
+ 'testResourceId',
+ 'testFieldQuery',
+ 5,
+ 'testAcceptParam',
+ '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
+ >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
index 75b5383d8a..ceb35696a9 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
@@ -45,7 +45,22 @@ class DmiOperationsSpec extends Specification {
def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
'/ncmp-datastore:passthrough-operational/testResourceId?fields=testFieldsQuery&depth=10'
when: 'get resource data is called to dmi'
- objectUnderTest.getResouceDataFromDmi('testDmiBasePath',
+ objectUnderTest.getResouceDataOperationalFromDmi('testDmiBasePath',
+ 'testCmhandle',
+ 'testResourceId',
+ 'testFieldsQuery',
+ 10,
+ 'testAcceptJson',
+ 'testJsonbody')
+ then: 'the put operation is executed with the correct URL'
+ 1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
+ }
+ def 'call get resource data for pass-through:running datastore from dmi.'() {
+ given: 'expected url'
+ def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
+ '/ncmp-datastore:passthrough-running/testResourceId?fields=testFieldsQuery&depth=10'
+ when: 'get resource data is called to dmi'
+ objectUnderTest.getResouceDataPassThroughRunningFromDmi('testDmiBasePath',
'testCmhandle',
'testResourceId',
'testFieldsQuery',