[dmi-plugin] Fix getResourceDataForPassthroughOperational endpoint 23/128223/6
authorputhuparambil.aditya <aditya.puthuparambil@bell.ca>
Tue, 29 Mar 2022 10:22:31 +0000 (11:22 +0100)
committerputhuparambil.aditya <aditya.puthuparambil@bell.ca>
Mon, 4 Apr 2022 11:06:34 +0000 (12:06 +0100)
Get endpoint only accepts application/json.

Issue-ID: CPS-957
Change-Id: I7b9dd00f293f183dc76623c8e32699e8e90fd17c
Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca>
docs/api/swagger/openapi.yaml
openapi/components.yml
openapi/openapi.yml
src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java
src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java
src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java
src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy

index 59e1021..f41e513 100644 (file)
@@ -177,15 +177,6 @@ paths:
         schema:
           type: string
           example: my-schema:my-node
-      - name: accept
-        in: header
-        description: Accept parameter for response, if accept parameter is null, that
-          means client can accept any format.
-        schema:
-          type: string
-          enum:
-          - application/json
-          - application/yang-data+json
       - name: options
         in: query
         description: options parameter in query, it is mandatory to wrap key(s)=value(s)
@@ -268,15 +259,6 @@ paths:
         schema:
           type: string
           example: my-schema:my-node
-      - name: accept
-        in: header
-        description: Accept parameter for response, if accept parameter is null, that
-          means client can accept any format.
-        schema:
-          type: string
-          enum:
-          - application/json
-          - application/yang-data+json
       - name: options
         in: query
         description: options parameter in query, it is mandatory to wrap key(s)=value(s)
index bf91cd2..c317ba7 100644 (file)
@@ -1,3 +1,22 @@
+#  ============LICENSE_START=======================================================
+#  Copyright (C) 2021 Nordix Foundation
+#  Modifications Copyright (C) 2022 Bell Canada
+#  ================================================================================
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+#  SPDX-License-Identifier: Apache-2.0
+#  ============LICENSE_END=========================================================
+
 components:
   schemas:
     ErrorMessage:
@@ -158,14 +177,6 @@ components:
         type: string
         example: my-schema:my-node
 
-    acceptParamInHeader:
-      name: accept
-      in: header
-      description: Accept parameter for response, if accept parameter is null, that means client can accept any format.
-      schema:
-        type: string
-        enum: [ application/json, application/yang-data+json ]
-
     optionsParamInQuery:
       name: options
       in: query
index e977262..bae7639 100644 (file)
@@ -1,5 +1,6 @@
 #  ============LICENSE_START=======================================================
 #  Copyright (C) 2021 Nordix Foundation
+#  Modifications Copyright (C) 2022 Bell Canada
 #  ================================================================================
 #  Licensed under the Apache License, Version 2.0 (the "License");
 #  you may not use this file except in compliance with the License.
@@ -124,7 +125,6 @@ paths:
       parameters:
         - $ref: 'components.yml#/components/parameters/cmHandleInPath'
         - $ref: 'components.yml#/components/parameters/resourceIdentifierInQuery'
-        - $ref: 'components.yml#/components/parameters/acceptParamInHeader'
         - $ref: 'components.yml#/components/parameters/optionsParamInQuery'
       requestBody:
         description: Operational body
@@ -158,7 +158,6 @@ paths:
       parameters:
         - $ref: 'components.yml#/components/parameters/cmHandleInPath'
         - $ref: 'components.yml#/components/parameters/resourceIdentifierInQuery'
-        - $ref: 'components.yml#/components/parameters/acceptParamInHeader'
         - $ref: 'components.yml#/components/parameters/optionsParamInQuery'
       requestBody:
         content:
index ed7c75b..5544aeb 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Nordix Foundation
+ *  Modifications Copyright (C) 2022 Bell Canada
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -93,7 +94,6 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
      * @param resourceIdentifier    resource identifier to fetch data
      * @param cmHandle              cm handle identifier
      * @param dataAccessRequest     data Access Request
-     * @param acceptParamInHeader   accept header parameter
      * @param optionsParamInQuery   options query parameter
      * @return {@code ResponseEntity} response entity
      */
@@ -102,12 +102,10 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
                                                                    final String cmHandle,
                                                                    final @Valid DataAccessRequest
                                                                                 dataAccessRequest,
-                                                                   final String acceptParamInHeader,
                                                                    final @Valid String optionsParamInQuery) {
         if (isReadOperation(dataAccessRequest)) {
             final String resourceDataAsJson = dmiService.getResourceData(cmHandle,
                 resourceIdentifier,
-                acceptParamInHeader,
                 optionsParamInQuery,
                 DmiService.RESTCONF_CONTENT_PASSTHROUGH_OPERATIONAL_QUERY_PARAM);
             return ResponseEntity.ok(resourceDataAsJson);
@@ -120,13 +118,11 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
                                                                final String cmHandle,
                                                                final @Valid DataAccessRequest
                                                                        dataAccessRequest,
-                                                               final String acceptParamInHeader,
                                                                final @Valid String optionsParamInQuery) {
         final String sdncResponse;
         if (isReadOperation(dataAccessRequest)) {
             sdncResponse = dmiService.getResourceData(cmHandle,
                 resourceIdentifier,
-                acceptParamInHeader,
                 optionsParamInQuery,
                 DmiService.RESTCONF_CONTENT_PASSTHROUGH_RUNNING_QUERY_PARAM);
         } else {
index 0f3fcc0..e5b08d9 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Nordix Foundation
+ *  Modifications Copyright (C) 2022 Bell Canada
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -70,14 +71,12 @@ public interface DmiService {
      *
      * @param cmHandle                  cm handle identifier
      * @param resourceIdentifier        resource identifier
-     * @param acceptParamInHeader       accept header parameter
      * @param optionsParamInQuery       options query parameter
      * @param restconfContentQueryParam restconf content i.e. datastore to use
      * @return {@code Object} response from network function
      */
     String getResourceData(@NotNull String cmHandle,
         @NotNull String resourceIdentifier,
-        String acceptParamInHeader,
         String optionsParamInQuery,
         String restconfContentQueryParam);
 
index 38b044d..22d4744 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Nordix Foundation
- *  Modifications Copyright (C) 2021 Bell Canada
+ *  Modifications Copyright (C) 2021-2022 Bell Canada
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -150,13 +150,11 @@ public class DmiServiceImpl implements DmiService {
     @Override
     public String getResourceData(final String cmHandle,
         final String resourceIdentifier,
-        final String acceptParamInHeader,
         final String optionsParamInQuery,
         final String restconfContentQueryParam) {
         final ResponseEntity<String> responseEntity = sdncOperations.getResouceDataForOperationalAndRunning(cmHandle,
             resourceIdentifier,
             optionsParamInQuery,
-            acceptParamInHeader,
             restconfContentQueryParam);
         return prepareAndSendResponse(responseEntity, cmHandle);
     }
index c6e221e..7e2443e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021-2022 Nordix Foundation
- *  Modifications Copyright (C) 2021 Bell Canada
+ *  Modifications Copyright (C) 2021-2022 Bell Canada
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -127,23 +127,16 @@ public class SdncOperations {
      * @param nodeId                    network resource identifier
      * @param resourceId                resource identifier
      * @param optionsParamInQuery       fields query
-     * @param acceptParamInHeader       accept parameter
      * @param restConfContentQueryParam restConf content query param
      * @return {@code ResponseEntity} response entity
      */
     public ResponseEntity<String> getResouceDataForOperationalAndRunning(final String nodeId,
         final String resourceId,
         final String optionsParamInQuery,
-        final String acceptParamInHeader,
         final String restConfContentQueryParam) {
         final String getResourceDataUrl = prepareResourceDataUrl(nodeId,
-            resourceId,
-                buildQueryParamMap(optionsParamInQuery, restConfContentQueryParam));
-        final HttpHeaders httpHeaders = new HttpHeaders();
-        if (acceptParamInHeader != null && !acceptParamInHeader.isBlank()) {
-            httpHeaders.set(HttpHeaders.ACCEPT, acceptParamInHeader);
-        }
-        return sdncRestconfClient.getOperation(getResourceDataUrl, httpHeaders);
+            resourceId, buildQueryParamMap(optionsParamInQuery, restConfContentQueryParam));
+        return sdncRestconfClient.getOperation(getResourceDataUrl);
     }
 
     /**
index ac632bb..b42eb4d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Nordix Foundation
- *  Modifications Copyright (C) 2021 Bell Canada
+ *  Modifications Copyright (C) 2021-2022 Bell Canada
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -183,15 +183,13 @@ class DmiRestControllerSpec extends Specification {
             def json = '{"cmHandleProperties" : { "prop1" : "value1", "prop2" : "value2"}}'
         when: 'get resource data POST api is invoked'
             def response = mvc.perform(
-                    post(getResourceDataForCmHandleUrl).contentType(MediaType.APPLICATION_JSON)
-                            .accept(MediaType.APPLICATION_JSON).content(json)
+                    post(getResourceDataForCmHandleUrl).contentType(MediaType.APPLICATION_JSON).content(json)
             ).andReturn().response
         then: 'response status is ok'
             response.status == OK.value()
         and: 'dmi service called with get resource data'
             1 * mockDmiService.getResourceData('some-cmHandle',
                     'parent/child',
-                    'application/json',
                     '(fields=myfields,depth=5)',
                     'content=all')
     }
@@ -203,8 +201,7 @@ class DmiRestControllerSpec extends Specification {
             def jsonData = TestUtils.getResourceFileContent('createDataWithNormalChar.json')
         when: 'get resource data POST api is invoked'
             def response = mvc.perform(
-                post(getResourceDataForCmHandleUrl).contentType(MediaType.APPLICATION_JSON)
-                    .accept(MediaType.APPLICATION_JSON).content(jsonData)
+                post(getResourceDataForCmHandleUrl).contentType(MediaType.APPLICATION_JSON).content(jsonData)
             ).andReturn().response
         then: 'response status is bad request'
             response.status == BAD_REQUEST.value()
@@ -265,15 +262,13 @@ class DmiRestControllerSpec extends Specification {
             def json = '{"cmHandleProperties" : { "prop1" : "value1", "prop2" : "value2"}}'
         when: 'get resource data POST api is invoked'
             def response = mvc.perform(
-                    post(getResourceDataForCmHandleUrl).contentType(MediaType.APPLICATION_JSON)
-                            .accept(MediaType.APPLICATION_JSON).content(json)
+                    post(getResourceDataForCmHandleUrl).contentType(MediaType.APPLICATION_JSON).content(json)
             ).andReturn().response
         then: 'response status is ok'
             response.status == OK.value()
         and: 'dmi service called with get resource data for a cm handle'
             1 * mockDmiService.getResourceData('some-cmHandle',
                     resourceIdentifier,
-                    'application/json',
                     '(fields=myfields,depth=5)',
                     'content=config')
         where: 'tokens are used in the resource identifier parameter'
index edf1a80..e38d5c3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Nordix Foundation
- *  Modifications Copyright (C) 2021 Bell Canada
+ *  Modifications Copyright (C) 2021-2022 Bell Canada
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -198,15 +198,13 @@ class DmiServiceImplSpec extends Specification {
         given: 'cm-handle, passthrough parameter, resourceId, accept header, fields, depth'
             def cmHandle = 'testCmHandle'
             def resourceId = 'testResourceId'
-            def acceptHeaderParam = 'testAcceptParam'
             def optionsParam = '(fields=x/y/z,depth=10,test=abc)'
             def contentQuery = 'content=all'
         and: 'sdnc operation returns OK response'
-            mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, optionsParam, acceptHeaderParam, contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
+            mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, optionsParam, contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
         when: 'get resource data from cm handles service method invoked'
             def response = objectUnderTest.getResourceData(cmHandle,
-                resourceId, acceptHeaderParam,
-                optionsParam, contentQuery)
+                resourceId, optionsParam, contentQuery)
         then: 'response have expected json'
             response == 'response json'
     }
@@ -215,15 +213,13 @@ class DmiServiceImplSpec extends Specification {
         given: 'cm-handle, passthrough parameter, resourceId, accept header, fields, depth, query param'
             def cmHandle = 'testCmHandle'
             def resourceId = 'testResourceId'
-            def acceptHeaderParam = 'testAcceptParam'
             def optionsParam = '(fields=x/y/z,depth=10,test=abc)'
             def restConfQueryParam = 'content=config'
         and: 'sdnc operation returns "NOT_FOUND" response'
-            mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, optionsParam, acceptHeaderParam, _ as String) >> new ResponseEntity<>(HttpStatus.NOT_FOUND)
+            mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, optionsParam, _ as String) >> new ResponseEntity<>(HttpStatus.NOT_FOUND)
         when: 'get resource data from cm handles service method invoked'
             objectUnderTest.getResourceData(cmHandle,
-                resourceId, acceptHeaderParam,
-                optionsParam, restConfQueryParam)
+                resourceId, optionsParam, restConfQueryParam)
         then: 'resource data not found'
             thrown(ResourceDataNotFound.class)
     }
@@ -232,16 +228,14 @@ class DmiServiceImplSpec extends Specification {
         given: 'cm-handle, passthrough parameter, resourceId, accept header, fields, depth'
             def cmHandle = 'testCmHandle'
             def resourceId = 'testResourceId'
-            def acceptHeaderParam = 'testAcceptParam'
             def optionsParam = '(fields=x/y/z,depth=10,test=abc)'
             def contentQuery = 'content=config'
         and: 'sdnc operation returns OK response'
             mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, optionsParam,
-                acceptHeaderParam, contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
+                contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
         when: 'get resource data from cm handles service method invoked'
             def response = objectUnderTest.getResourceData(cmHandle,
-                resourceId, acceptHeaderParam,
-                optionsParam, contentQuery)
+                resourceId, optionsParam, contentQuery)
         then: 'response have expected json'
             response == 'response json'
     }
index c71f6d9..724d2d4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021-2022 Nordix Foundation
- *  Modifications Copyright (C) 2021 Bell Canada
+ *  Modifications Copyright (C) 2021-2022 Bell Canada
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -117,19 +117,14 @@ class SdncOperationsSpec extends Specification {
             1 * mockSdncRestClient.httpOperationWithJsonData(HttpMethod.POST, expectedUrl, 'some-json-data', _ as HttpHeaders)
     }
 
-    def 'Get resource data from node to SDNC. with#scenario accept header'() {
+    def 'Get resource data from node to SDNC.'() {
         given: 'expected url, topology-id, sdncOperation object'
             def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/testResourceId?a=1&b=2&content=testContent'
         when: 'called get modules from node'
             objectUnderTest.getResouceDataForOperationalAndRunning('node1', 'testResourceId',
-                '(a=1,b=2)', acceptParamInHeader, 'content=testContent')
-        then: 'the get operation is executed with the correct URL and Http headers'
-            1 * mockSdncRestClient.getOperation(expectedUrl, expectedHttpHeaders)
-        where:
-            scenario | acceptParamInHeader || expectedHttpHeaders
-            'test'   | 'test'              || new HttpHeaders([Accept:'test'])
-            'empty'  | ''                  || new HttpHeaders()
-            'null'   | null                || new HttpHeaders()
+                '(a=1,b=2)', 'content=testContent')
+        then: 'the get operation is executed with the correct URL'
+            1 * mockSdncRestClient.getOperation(expectedUrl)
     }
 
     def 'Write resource data with #scenario operation to SDNC.'() {