summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-09-15 13:01:25 +0100
committerniamhcore <niamh.core@est.tech>2021-09-15 16:20:02 +0100
commitaccefb1c6f1fbb2ab904acbf7d5f4eb33ef51cee (patch)
treed5a4af9c248f110d433366f58cea0a3eefc8c7ed
parent0f6e827fca9dea842515f47748822844fc5568e5 (diff)
Update response code for passthrough-running create use-case
Issue-ID: CPS-659 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: I4ebc4f68604efe78efb951989c2fb021443c36c9
-rw-r--r--docs/openapi/openapi.yaml8
-rw-r--r--docs/openapi/openapi.yml4
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java4
-rw-r--r--src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java2
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy4
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy38
6 files changed, 35 insertions, 25 deletions
diff --git a/docs/openapi/openapi.yaml b/docs/openapi/openapi.yaml
index 082df223..58a23d90 100644
--- a/docs/openapi/openapi.yaml
+++ b/docs/openapi/openapi.yaml
@@ -313,12 +313,12 @@ paths:
$ref: '#/components/schemas/DataAccessWriteRequest'
required: true
responses:
- "200":
- description: OK
+ "201":
+ description: Created
content:
- application/json:
+ text/plain:
schema:
- type: object
+ type: string
"400":
description: Bad Request
content:
diff --git a/docs/openapi/openapi.yml b/docs/openapi/openapi.yml
index 516f7e3c..a9accdb9 100644
--- a/docs/openapi/openapi.yml
+++ b/docs/openapi/openapi.yml
@@ -192,8 +192,8 @@ paths:
schema:
$ref: 'components.yml#/components/schemas/DataAccessWriteRequest'
responses:
- '200':
- $ref: 'components.yml#/components/responses/Ok'
+ '201':
+ $ref: 'components.yml#/components/responses/Created'
'400':
$ref: 'components.yml#/components/responses/BadRequest'
'401':
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
index 4a18b067..37381fb1 100644
--- a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
+++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
@@ -84,14 +84,14 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
* @return (@ code ResponseEntity) response entity
*/
@Override
- public ResponseEntity<Object> writeDataByPassthroughRunningForCmHandle(
+ public ResponseEntity<String> writeDataByPassthroughRunningForCmHandle(
final DataAccessWriteRequest dataAccessWriteRequest,
final String cmHandle, final String resourceIdentifier) {
final String response = dmiService.writeResourceDataPassthroughForCmHandle(cmHandle,
resourceIdentifier,
MediaType.APPLICATION_JSON_VALUE,
dataAccessWriteRequest.getData());
- return new ResponseEntity<>(response, HttpStatus.OK);
+ return new ResponseEntity<>(response, HttpStatus.CREATED);
}
/**
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 2512ce2f..db115ce4 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
@@ -223,7 +223,7 @@ public class DmiServiceImpl implements DmiService {
}
final ResponseEntity<String> responseEntity =
sdncOperations.writeResourceDataPassthroughRunning(cmHandle, resourceIdentifier, dataType, jsonData);
- if (responseEntity.getStatusCode() == HttpStatus.CREATED) {
+ if (responseEntity.getStatusCode().is2xxSuccessful()) {
return responseEntity.getBody();
} else {
throw new DmiException(cmHandle,
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 e08870fd..a937c4e6 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
@@ -218,8 +218,8 @@ class DmiRestControllerSpec extends Specification {
post(writeDataforCmHandlePassthroughRunning).contentType(MediaType.APPLICATION_JSON)
.content(jsonData)
).andReturn().response
- then: 'response status is ok'
- response.status == HttpStatus.OK.value()
+ then: 'response status is 201 CREATED'
+ response.status == HttpStatus.CREATED.value()
and: 'the data in the request body is as expected'
response.getContentAsString() == '{some-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 1d2cf7f3..a99aa9aa 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
@@ -248,30 +248,40 @@ class DmiServiceImplSpec extends Specification {
response == 'response json'
}
- def 'Write resource data using for passthrough running for the given cm handle.'() {
- given: 'sdnc returns a created response'
- mockSdncOperations.writeResourceDataPassthroughRunning(_, _, _, _) >> new ResponseEntity<String>('response json', HttpStatus.CREATED)
- when: 'write resource data from cm handles service method invoked'
+ def 'Write resource data for passthrough running for the given cm handle with a #scenario from sdnc.'() {
+ given: 'sdnc returns a response'
+ mockSdncOperations.writeResourceDataPassthroughRunning(_, _, _, _) >> new ResponseEntity<String>('response json', httpResponse)
+ when: 'write resource data for cm handle method invoked'
def response = objectUnderTest.writeResourceDataPassthroughForCmHandle('some-cmHandle',
'some-resourceIdentifier', 'some-dataType', '{some-data}')
- then: 'response have expected json'
+ then: 'the response contains the expected json data from sdnc'
response == 'response json'
+ where: 'the following values are used'
+ scenario | httpResponse
+ '200 OK response' | HttpStatus.OK
+ '201 CREATED response' | HttpStatus.CREATED
+ }
+
+ def 'Write resource data for passthrough running with a 500 response from sdnc.'() {
+ given: 'sdnc returns a 500 response for the write operation'
+ mockSdncOperations.writeResourceDataPassthroughRunning(_, _, _, _) >> new ResponseEntity<String>('response json', HttpStatus.INTERNAL_SERVER_ERROR)
+ when: 'write resource data for pass through method is invoked'
+ objectUnderTest.writeResourceDataPassthroughForCmHandle('some-cmHandle',
+ 'some-resourceIdentifier', 'some-dataType', new Object())
+ then: 'a dmi exception is thrown'
+ thrown(DmiException.class)
}
- def 'Write resource data for passthrough running with a #scenario.'() {
- given: 'sdnc returns a response for the write operation'
- mockSdncOperations.writeResourceDataPassthroughRunning(_, _, _, _) >> new ResponseEntity<String>('response json', httpStatus)
- and: 'the data provided in the request body is written as a string'
+ def 'Write resource data for passthrough running with a json processing exception.'() {
+ given: 'sdnc returns a 200 response for the write operation'
+ mockSdncOperations.writeResourceDataPassthroughRunning(_, _, _, _) >> new ResponseEntity<String>('response json', HttpStatus.OK)
+ and: 'a json processing exception is thrown'
objectUnderTest.objectMapper = mockObjectMapper
- mockObjectMapper.writeValueAsString(_) >> jsonString
+ mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException('some-exception') }
when: 'write resource data for pass through method is invoked'
objectUnderTest.writeResourceDataPassthroughForCmHandle('some-cmHandle',
'some-resourceIdentifier', 'some-dataType', new Object())
then: 'a dmi exception is thrown'
thrown(DmiException.class)
- where: 'the following combinations are tested'
- scenario | httpStatus | jsonString
- '500 response from sdnc' | HttpStatus.INTERNAL_SERVER_ERROR | '{some-json-data}'
- 'json processing exception ' | HttpStatus.OK | { throw new JsonProcessingException('some error.') }
}
} \ No newline at end of file