dataType:
type: string
data:
- type: string
+ type: object
cmHandleProperties:
type: object
additionalProperties:
* @return response from sdnc
*/
String writeResourceDataPassthroughForCmHandle(String cmHandle, String resourceIdentifier, String dataType,
- String data);
+ Object data);
}
\ No newline at end of file
@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<String> 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());
}
}
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;
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() {
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
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}
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)
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'
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
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
}
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
}
{
"operation": "create",
"dataType": "application/json",
- "data": "{ some data }",
+ "data": {
+ "some-data": "some-value"
+ },
"cmHandleProperties": {
"some-property": "some-property-value"
}