Get resource data from pass through running (Ncmp impl.) 91/123391/3
authortragait <rahul.tyagi@est.tech>
Thu, 19 Aug 2021 14:17:56 +0000 (15:17 +0100)
committertragait <rahul.tyagi@est.tech>
Fri, 20 Aug 2021 14:31:31 +0000 (15:31 +0100)
Issue-ID: CPS-580
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: I6dc37d9516078c87efc3f0c5bbd2b7b8a7155d48

cps-ncmp-rest/docs/openapi/ncmproxy.yml
cps-ncmp-rest/docs/openapi/openapi.yml
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
cps-ncmp-service/pom.xml
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy

index ede0ec6..b2e14d7 100755 (executable)
@@ -209,6 +209,31 @@ getResourceDataForPassthroughOperational:
     summary: Get resource data from pass-through operational for cm handle
     description: Get resource data from pass-through operational for given cm handle
     operationId: getResourceDataOperationalForCmHandle
+    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'
+
+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'
index 5b7c8d2..0dfe3c8 100755 (executable)
@@ -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
index b35b245..587787e 100755 (executable)
@@ -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,
index b2a060c..a7fa309 100644 (file)
@@ -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}'
+    }
 }
 
index f786b80..fc01c3b 100644 (file)
@@ -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>
index 82be7bf..3e715e5 100644 (file)
@@ -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);
 }
index 84dcc77..c2be9e9 100755 (executable)
@@ -29,6 +29,7 @@ import java.util.Collection;
 import java.util.LinkedHashMap;
 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;
@@ -149,17 +150,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,
@@ -169,6 +170,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,
@@ -180,12 +201,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.");
@@ -199,7 +220,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")));
         }
index c7554bc..2b13d16 100644 (file)
@@ -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);
         }
index 65d96a4..ac290af 100644 (file)
@@ -126,7 +126,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',
@@ -134,8 +134,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',
@@ -161,7 +161,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',
@@ -181,7 +181,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',
@@ -190,7 +190,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',
index 75b5383..ceb3569 100644 (file)
@@ -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',