diff options
author | tragait <rahul.tyagi@est.tech> | 2021-09-14 13:47:52 +0100 |
---|---|---|
committer | tragait <rahul.tyagi@est.tech> | 2021-09-21 14:38:30 +0100 |
commit | fa11e9cb799b9738d2295abd4690c142639b9250 (patch) | |
tree | 165fa9c085f2d87d53053af0e861e4bc12680583 /src/test/groovy/org | |
parent | accefb1c6f1fbb2ab904acbf7d5f4eb33ef51cee (diff) |
fix data from object to string
Also, make dmi service url configurable,
change name of dmi creds env var
Issue-ID: CPS-675
Issue-ID: CPS-634
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: I6fe794b3e65b6a3aae2a1698ea64a925238a18d3
Diffstat (limited to 'src/test/groovy/org')
3 files changed, 34 insertions, 30 deletions
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 a937c4e6..ac4fde3d 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 @@ -26,12 +26,8 @@ import org.onap.cps.ncmp.dmi.TestUtils import org.onap.cps.ncmp.dmi.exception.DmiException import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException -import org.onap.cps.ncmp.dmi.model.DataAccessReadRequest -import org.onap.cps.ncmp.dmi.model.DataAccessWriteRequest import org.onap.cps.ncmp.dmi.model.ModuleReference import org.onap.cps.ncmp.dmi.model.ModuleSchemaList -import org.onap.cps.ncmp.dmi.model.ModuleSchemaProperties -import org.onap.cps.ncmp.dmi.model.ModuleSchemas import org.onap.cps.ncmp.dmi.model.ModuleSet import org.onap.cps.ncmp.dmi.model.ModuleSetSchemas import org.onap.cps.ncmp.dmi.service.DmiService @@ -207,12 +203,14 @@ class DmiRestControllerSpec extends Specification { ['prop1': 'value1', 'prop2': 'value2']) } - def 'Write data using passthrough running for a cm handle.'() { + def 'Write data using passthrough running for a cm handle using #scenario.'() { given: 'write data for cmHandle url and jsonData' def writeDataforCmHandlePassthroughRunning = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-running/some-resourceIdentifier" - def jsonData = TestUtils.getResourceFileContent('WriteDataForCmHandle.json') + def jsonData = TestUtils.getResourceFileContent(requestBodyFile) and: 'dmi service is called' - mockDmiService.writeResourceDataPassthroughForCmHandle('some-cmHandle', 'some-resourceIdentifier', 'application/json', ['some-data': 'some-value']) >> '{some-json}' + mockDmiService.writeResourceDataPassthroughForCmHandle('some-cmHandle', + 'some-resourceIdentifier', 'application/json', + expectedRequestData) >> '{some-json}' when: 'write cmHandle passthrough running post api is invoked with json data' def response = mvc.perform( post(writeDataforCmHandlePassthroughRunning).contentType(MediaType.APPLICATION_JSON) @@ -222,6 +220,10 @@ class DmiRestControllerSpec extends Specification { response.status == HttpStatus.CREATED.value() and: 'the data in the request body is as expected' response.getContentAsString() == '{some-json}' + where: 'given request body and data' + scenario | requestBodyFile || expectedRequestData + 'data with normal chars' | 'dataWithNormalChar.json' || 'normal request body' + 'data with special chars' | 'dataWithSpecialChar.json'|| 'data with quote \" and new line \n' } def 'Get resource data for pass-through running from cm handle.'() { 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 a99aa9aa..c1700a2e 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 @@ -98,7 +98,7 @@ class DmiServiceImplSpec extends Specification { def givenCmHandlesList = ['node1', 'node2'] def expectedJson = '{"dmiPlugin":"test-dmi-service","createdCmHandles":[{"cmHandle":"node1"},{"cmHandle":"node2"}]}' and: 'mockDmiPluginProperties returns test-dmi-service' - mockDmiPluginProperties.getDmiServiceName() >> 'test-dmi-service' + mockDmiPluginProperties.getDmiServiceUrl() >> 'test-dmi-service' when: 'register cm handles service method with the given cm handles' objectUnderTest.registerCmHandles(givenCmHandlesList) then: 'register cm handle with ncmp called once and return "created" status' @@ -109,7 +109,7 @@ class DmiServiceImplSpec extends Specification { given: 'cm-handle list' def cmHandlesList = ['node1', 'node2'] and: 'dmi plugin service name is "test-dmi-service"' - mockDmiPluginProperties.getDmiServiceName() >> 'test-dmi-service' + mockDmiPluginProperties.getDmiServiceUrl() >> 'test-dmi-service' and: 'ncmp rest client returns #responseEntity' mockNcmpRestClient.registerCmHandlesWithNcmp(_ as String) >> responseEntity when: 'register cm handles service method called' @@ -170,7 +170,7 @@ class DmiServiceImplSpec extends Specification { def moduleReference = new ModuleReference(name: 'NAME',revision: 'REVISION') def moduleList = [moduleReference] when: 'get module resources is invoked with the given cm handle and a module list' - objectUnderTest.getModuleResources(cmHandle, moduleList) + objectUnderTest.getModuleResources(cmHandle, moduleList) then: 'get modules resources is called once with a response body that contains no data' 1 * mockSdncOperations.getModuleResource(cmHandle, _) >> new ResponseEntity<String>(responseBody, HttpStatus.OK) and: 'a module resource not found exception is thrown' @@ -249,7 +249,7 @@ class DmiServiceImplSpec extends Specification { } def 'Write resource data for passthrough running for the given cm handle with a #scenario from sdnc.'() { - given: 'sdnc returns a response' + given: 'sdnc returns a response with #scenario' mockSdncOperations.writeResourceDataPassthroughRunning(_, _, _, _) >> new ResponseEntity<String>('response json', httpResponse) when: 'write resource data for cm handle method invoked' def response = objectUnderTest.writeResourceDataPassthroughForCmHandle('some-cmHandle', @@ -262,25 +262,27 @@ class DmiServiceImplSpec extends Specification { '201 CREATED response' | HttpStatus.CREATED } + def 'Write resource data using for passthrough running for the given cm handle with #scenario.'() { + given: 'sdnc returns a created response' + mockSdncOperations.writeResourceDataPassthroughRunning('some-cmHandle', + 'some-resourceIdentifier', 'some-dataType', requestBody) >> new ResponseEntity<String>('response json', HttpStatus.CREATED) + when: 'write resource data from cm handles service method invoked' + def response = objectUnderTest.writeResourceDataPassthroughForCmHandle('some-cmHandle', + 'some-resourceIdentifier', 'some-dataType', requestBody) + then: 'response have expected json' + response == 'response json' + where: 'given request body' + scenario | requestBody + 'data contains normal char' | 'normal char string' + 'data contains quote and new line' | 'data with quote " and \n new line' + } + 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 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(_) >> { 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()) + 'some-resourceIdentifier', 'some-dataType', _ as String) then: 'a dmi exception is thrown' thrown(DmiException.class) } diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy index c9d7d1b8..14a62ebb 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy @@ -60,7 +60,7 @@ class SdncOperationsSpec extends Specification { } def 'Get resource data from node to SDNC.'() { - given: 'excpected url, topology-id, sdncOperation object' + given: 'expected url, topology-id, sdncOperation object' def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/testResourceId?fields=testFields&depth=10&content=testContent' when: 'called get modules from node' objectUnderTest.getResouceDataForOperationalAndRunning('node1', 'testResourceId', @@ -70,11 +70,11 @@ class SdncOperationsSpec extends Specification { } def 'Write resource data to SDNC.'() { - given: 'excpected url, topology-id, sdncOperation object' + given: 'expected url, topology-id, sdncOperation object' def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/testResourceId' when: 'write resource data for pass through running is called' - objectUnderTest.writeResourceDataPassthroughRunning('node1', 'testResourceId', 'application/json','testData') - then: 'the post operation is executed with the correct URL' - 1 * mockSdncRestClient.postOperationWithJsonData(expectedUrl, _ as String, _ as HttpHeaders) + objectUnderTest.writeResourceDataPassthroughRunning('node1','testResourceId','application/json','requestData') + then: 'the post operation is executed with the correct URL and data' + 1 * mockSdncRestClient.postOperationWithJsonData(expectedUrl, 'requestData', _ as HttpHeaders) } }
\ No newline at end of file |