From aea4b371e4c06a7d5b4191ab8a602e99abd1f140 Mon Sep 17 00:00:00 2001 From: tragait Date: Fri, 10 Sep 2021 10:45:31 +0100 Subject: revert cps:634 postpone this bug to jakarta This commit also have fix in application yaml for correct ncmp api path for registration url. Issue-ID: CPS-634 Issue-ID: CPS-617 Signed-off-by: tragait Change-Id: I465991492a01092e28b97583f84ed959c54ffaa6 --- docs/openapi/components.yml | 2 +- .../java/org/onap/cps/ncmp/dmi/service/DmiService.java | 2 +- .../org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java | 15 ++++++++++++--- .../onap/cps/ncmp/dmi/service/client/NcmpRestClient.java | 3 ++- .../cps/ncmp/dmi/service/client/SdncRestconfClient.java | 2 +- src/main/resources/application.yml | 2 +- .../ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy | 2 +- .../onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy | 2 +- .../cps/ncmp/dmi/service/client/NcmpRestClientSpec.groovy | 5 +++-- .../ncmp/dmi/service/client/SdncRestconfClientSpec.groovy | 4 ++-- src/test/resources/WriteDataForCmHandle.json | 4 +++- 11 files changed, 28 insertions(+), 15 deletions(-) diff --git a/docs/openapi/components.yml b/docs/openapi/components.yml index 3866b834..bac5f9c8 100644 --- a/docs/openapi/components.yml +++ b/docs/openapi/components.yml @@ -78,7 +78,7 @@ components: dataType: type: string data: - type: string + type: object cmHandleProperties: type: object additionalProperties: diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java index 7f79a04c..f1446084 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java @@ -106,5 +106,5 @@ public interface DmiService { * @return response from sdnc */ String writeResourceDataPassthroughForCmHandle(String cmHandle, String resourceIdentifier, String dataType, - String data); + Object data); } \ No newline at end of file diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java index e9ecc592..2512ce2f 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java @@ -211,14 +211,23 @@ public class DmiServiceImpl implements DmiService { @Override public String writeResourceDataPassthroughForCmHandle(final String cmHandle, final String resourceIdentifier, - final String dataType, final String data) { + final String dataType, final Object data) { + final String jsonData; + try { + jsonData = objectMapper.writeValueAsString(data); + } catch (final JsonProcessingException e) { + log.error("JSON exception occurred when processing pass through request data for the given cmHandle {}", + cmHandle); + throw new DmiException("Unable to process incoming JSON from the request body.", + "JSON exception occurred when writing data for the given cmHandle " + cmHandle, e); + } final ResponseEntity responseEntity = - sdncOperations.writeResourceDataPassthroughRunning(cmHandle, resourceIdentifier, dataType, data); + sdncOperations.writeResourceDataPassthroughRunning(cmHandle, resourceIdentifier, dataType, jsonData); if (responseEntity.getStatusCode() == HttpStatus.CREATED) { return responseEntity.getBody(); } else { throw new DmiException(cmHandle, - RESPONSE_CODE + responseEntity.getStatusCode() + MESSAGE + responseEntity.getBody()); + RESPONSE_CODE + responseEntity.getStatusCode() + MESSAGE + responseEntity.getBody()); } } diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java b/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java index 47651346..94783f3b 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/client/NcmpRestClient.java @@ -23,6 +23,7 @@ package org.onap.cps.ncmp.dmi.service.client; import org.onap.cps.ncmp.dmi.config.DmiConfiguration.CpsProperties; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; @@ -51,7 +52,7 @@ public class NcmpRestClient { httpHeaders.setBasicAuth(cpsProperties.getAuthUsername(), cpsProperties.getAuthPassword()); httpHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); final var httpEntity = new HttpEntity<>(jsonData, httpHeaders); - return restTemplate.postForEntity(ncmpRegistrationUrl, httpEntity, String.class); + return restTemplate.exchange(ncmpRegistrationUrl, HttpMethod.POST, httpEntity, String.class); } private String buildNcmpRegistrationUrl() { diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClient.java b/src/main/java/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClient.java index bbc39da5..b8e33dfc 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClient.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClient.java @@ -79,6 +79,6 @@ public class SdncRestconfClient { final var sdncRestconfUrl = sdncBaseUrl.concat(postResourceUrl); httpHeaders.setBasicAuth(sdncProperties.getAuthUsername(), sdncProperties.getAuthPassword()); final var httpEntity = new HttpEntity<>(jsonData, httpHeaders); - return restTemplate.postForEntity(sdncRestconfUrl, httpEntity, String.class); + return restTemplate.exchange(sdncRestconfUrl, HttpMethod.POST, httpEntity, String.class); } } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 10297e76..4383e794 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -54,7 +54,7 @@ management: cps-core: baseUrl: http://${CPS_CORE_HOST}:${CPS_CORE_PORT} - dmiRegistrationUrl : /cps-ncmp/api/ncmp-dmi/v1/ch + dmiRegistrationUrl : /ncmp/v1/ch auth: username: ${CPS_CORE_USERNAME} password: ${CPS_CORE_PASSWORD} diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy index c32608c0..e08870fd 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy @@ -212,7 +212,7 @@ class DmiRestControllerSpec extends Specification { def writeDataforCmHandlePassthroughRunning = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-running/some-resourceIdentifier" def jsonData = TestUtils.getResourceFileContent('WriteDataForCmHandle.json') and: 'dmi service is called' - mockDmiService.writeResourceDataPassthroughForCmHandle('some-cmHandle', 'some-resourceIdentifier', 'application/json', '{ some data }') >> '{some-json}' + mockDmiService.writeResourceDataPassthroughForCmHandle('some-cmHandle', 'some-resourceIdentifier', 'application/json', ['some-data': 'some-value']) >> '{some-json}' when: 'write cmHandle passthrough running post api is invoked with json data' def response = mvc.perform( post(writeDataforCmHandlePassthroughRunning).contentType(MediaType.APPLICATION_JSON) diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy index 7891450d..1d2cf7f3 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy @@ -266,7 +266,7 @@ class DmiServiceImplSpec extends Specification { mockObjectMapper.writeValueAsString(_) >> jsonString when: 'write resource data for pass through method is invoked' objectUnderTest.writeResourceDataPassthroughForCmHandle('some-cmHandle', - 'some-resourceIdentifier', 'some-dataType', 'some-json-data') + 'some-resourceIdentifier', 'some-dataType', new Object()) then: 'a dmi exception is thrown' thrown(DmiException.class) where: 'the following combinations are tested' diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/NcmpRestClientSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/NcmpRestClientSpec.groovy index f5c059c7..32df97b6 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/NcmpRestClientSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/NcmpRestClientSpec.groovy @@ -21,6 +21,7 @@ package org.onap.cps.ncmp.dmi.service.client import org.onap.cps.ncmp.dmi.config.DmiConfiguration +import org.springframework.http.HttpMethod import org.springframework.http.ResponseEntity import org.springframework.web.client.RestTemplate import spock.lang.Specification @@ -48,8 +49,8 @@ class NcmpRestClientSpec extends Specification { when: 'register cm-handle with ncmp is invoked' def result = objectUnderTest.registerCmHandlesWithNcmp(jsonData) then: 'the rest template is called with the correct uri and json in the body' - 1 * mockRestTemplate.postForEntity({ it.toString() == 'http://some-uri/some-url' }, - { it.body.contains(jsonData) }, String.class) >> mockResponseEntity + 1 * mockRestTemplate.exchange({ it.toString() == 'http://some-uri/some-url' }, + HttpMethod.POST, { it.body.contains(jsonData) }, String.class) >> mockResponseEntity and: 'the output of the method is equal to the output from the test template' result == mockResponseEntity } diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClientSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClientSpec.groovy index b550480d..2184c7e7 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClientSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClientSpec.groovy @@ -61,8 +61,8 @@ class SdncRestconfClientSpec extends Specification { when: 'get module resources is invoked' def result = objectUnderTest.postOperationWithJsonData(getModuleResourceUrl, jsonData, new HttpHeaders()) then: 'the rest template is called with the correct uri and json in the body' - 1 * mockRestTemplate.postForEntity({ it.toString() == 'http://some-uri/getModuleResourceUrl' }, - { it.body.contains(jsonData) }, String.class) >> mockResponseEntity + 1 * mockRestTemplate.exchange({ it.toString() == 'http://some-uri/getModuleResourceUrl' }, + HttpMethod.POST, { it.body.contains(jsonData) }, String.class) >> mockResponseEntity and: 'the output of the method is the same as the output from the test template' result == mockResponseEntity } diff --git a/src/test/resources/WriteDataForCmHandle.json b/src/test/resources/WriteDataForCmHandle.json index 178421fc..8eb19599 100644 --- a/src/test/resources/WriteDataForCmHandle.json +++ b/src/test/resources/WriteDataForCmHandle.json @@ -1,7 +1,9 @@ { "operation": "create", "dataType": "application/json", - "data": "{ some data }", + "data": { + "some-data": "some-value" + }, "cmHandleProperties": { "some-property": "some-property-value" } -- cgit 1.2.3-korg