Add delete operation for passthrough running within cps-ncmp.
Issue-ID: CPS-638
Change-Id: I360672adc1f0f5c8eb351391c94f2d4fa913d0b4
Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
       404:
         $ref: 'components.yaml#/components/responses/NotFound'
 
+  delete:
+    tags:
+      - network-cm-proxy
+    summary: Delete resource data
+    description: Delete resource data from pass-through running for a given cm handle
+    operationId: deleteResourceDataRunningForCmHandle
+    parameters:
+      - $ref: 'components.yaml#/components/parameters/cmHandleInPath'
+      - $ref: 'components.yaml#/components/parameters/resourceIdentifierInQuery'
+      - $ref: 'components.yaml#/components/parameters/contentParamInHeader'
+    requestBody:
+      required: true
+      content:
+        application/json:
+          schema:
+            type: string
+    responses:
+      204:
+        $ref: 'components.yaml#/components/responses/NoContent'
+      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'
+
+
 fetchModuleReferencesByCmHandle:
   get:
     description: fetch all module references (name and revision) for a given cm handle
 
 package org.onap.cps.ncmp.rest.controller;
 
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE;
+import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE;
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH;
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE;
 
     }
 
     /**
-     * Create resource data in datastore pass through running for given cm-handle.
+     * Create resource data in datastore pass-through running for given cm-handle.
      *
      * @param resourceIdentifier resource identifier
      * @param cmHandle cm handle identifier
     }
 
     /**
-     * Update resource data in datastore pass through running for given cm-handle.
+     * Update resource data in datastore pass-through running for given cm-handle.
      *
      * @param resourceIdentifier resource identifier
      * @param cmHandle cm handle identifier
         return new ResponseEntity<>(HttpStatus.OK);
     }
 
+
+    /**
+     *  Delete resource data in datastore pass-through running for a given cm-handle.
+     *
+     * @param resourceIdentifier resource identifier
+     * @param cmHandle cm handle identifier
+     * @param requestBody the request body
+     * @param contentType content type of the body
+     * @return response entity no content if request is successful
+     */
+    @Override
+    public ResponseEntity<Void> deleteResourceDataRunningForCmHandle(final String resourceIdentifier,
+                                                                     final String cmHandle,
+                                                                     final String requestBody,
+                                                                     final String contentType) {
+
+        networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
+            resourceIdentifier, DELETE, requestBody, contentType);
+        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+    }
+
     /**
      * Execute cm handle search.
      *
 
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH
 import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
 import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE
 import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE
+import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE
 
 import com.google.gson.Gson
 import org.onap.cps.ncmp.api.NetworkCmProxyDataService
             response.contentAsString.contains('"leaf":"value"')
     }
 
-    def 'Get Resource Data from passthrough operational.' () {
+    def 'Get Resource Data from pass-through operational.' () {
         given: 'resource data url'
             def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-operational" +
                     "?resourceIdentifier=parent/child&options=(a=1,b=2)"
             response.status == HttpStatus.OK.value()
     }
 
-    def 'Get Resource Data from passthrough running with #scenario value in resource identifier param.' () {
+    def 'Get Resource Data from pass-through running with #scenario value in resource identifier param.' () {
         given: 'resource data url'
             def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
                     "?resourceIdentifier=" + resourceIdentifier + "&options=(a=1,b=2)"
             '? needs to be encoded as %3F' | 'idWith%3F'
     }
 
-    def 'Update resource data from passthrough running.' () {
+    def 'Update resource data from pass-through running.' () {
         given: 'update resource data url'
             def updateUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
                 "?resourceIdentifier=parent/child"
             response.status == HttpStatus.OK.value()
     }
 
-    def 'Create Resource Data from passthrough running with #scenario.' () {
+    def 'Create Resource Data from pass-through running with #scenario.' () {
         given: 'resource data url'
             def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
                     "?resourceIdentifier=parent/child"
             response.contentAsString == '{"cmHandles":[]}'
     }
 
-    def 'Patch resource data in passthrough-running datastore.' () {
+    def 'Patch resource data in pass-through running datastore.' () {
         given: 'patch resource data url'
             def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
                     "?resourceIdentifier=parent/child"
         and: 'the response status is OK'
             response.status == HttpStatus.OK.value()
     }
+
+    def 'Delete resource data in pass-through running datastore.' () {
+        given: 'delete resource data url'
+            def url = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
+                     "?resourceIdentifier=parent/child"
+        when: 'delete data resource request is performed'
+            def response = mvc.perform(
+                delete(url).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)
+                .content('{"some-key" : "some-value"}')).andReturn().response
+        then: 'the ncmp service method to delete resource is called'
+            1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
+                'parent/child', DELETE, '{"some-key" : "some-value"}', 'application/json;charset=UTF-8')
+        and: 'the response is No Content'
+            response.status == HttpStatus.NO_CONTENT.value()
+    }
 }
 
 
         READ("read"),
         CREATE("create"),
         UPDATE("update"),
-        PATCH("patch");
+        PATCH("patch"),
+        DELETE("delete");
         private String value;
 
         OperationEnum(final String value) {
 
             1 * mockCpsDataService.saveListElements(expectedDataspaceName, cmHandle, xpath, jsonData, noTimestamp)
     }
 
-    def 'Write resource data for passthrough running from dmi using POST #scenario cm handle properties.'() {
+    def 'Write resource data for pass-through running from dmi using POST #scenario cm handle properties.'() {
         given: 'a data node'
             def dataNode = getDataNode(includeCmHandleProperties)
         and: 'cpsDataService returns valid datanode'
             'without' | false                     || '{}'
     }
 
-    def 'Write resource data for passthrough running from dmi using POST "not found" response (from DMI).'() {
+    def 'Write resource data for pass-through running from dmi using POST "not found" response (from DMI).'() {
         given: 'a data node'
             def dataNode = getDataNode(true)
         and: 'cpsDataService returns valid dataNode'
             fetchDescendantsOption << FetchDescendantsOption.values()
     }
 
-    def 'Get resource data for passthrough operational from dmi.'() {
+    def 'Get resource data for pass-through operational from dmi.'() {
         given: 'a data node'
             def dataNode = getDataNode(true)
         and: 'get data node is called'
             response == 'result-json'
     }
 
-    def 'Get resource data for passthrough operational from dmi with Json Processing Exception.'() {
+    def 'Get resource data for pass-through operational from dmi with Json Processing Exception.'() {
         given: 'a data node'
             def dataNode = getDataNode(true)
         and: 'cps data service returns valid data node'
             exceptionThrown.details == 'DMI status code: 404, DMI response body: NOK-json'
     }
 
-    def 'Get resource data for passthrough operational from dmi return NOK response.'() {
+    def 'Get resource data for pass-through operational from dmi return NOK response.'() {
         given: 'a data node'
             def dataNode = getDataNode(true)
         and: 'cps data service returns valid data node'
             exceptionThrown.details.contains('NOK-json')
     }
 
-    def 'Get resource data for passthrough running from dmi.'() {
+    def 'Get resource data for pass-through running from dmi.'() {
         given: 'a data node'
             def dataNode = getDataNode(true)
         and: 'cpsDataService returns valid data node'
             response == '{result-json}'
     }
 
-    def 'Get resource data for passthrough running from dmi return NOK response.'() {
+    def 'Get resource data for pass-through running from dmi return NOK response.'() {
         given: 'a data node'
             def dataNode = getDataNode(true)
         and: 'cpsDataService returns valid dataNode'
             1 * mockCpsDataService.replaceNodeTree(expectedDataspaceName, cmHandle, xpath, jsonData, noTimestamp)
     }
 
-    def 'Update resource data for passthrough running from dmi using POST #scenario cm handle properties.'() {
+    def 'Update resource data for pass-through running from dmi using POST #scenario cm handle properties.'() {
         given: 'a data node'
             def dataNode = getDataNode(includeCmHandleProperties)
         and: 'cpsDataService returns valid datanode'