summaryrefslogtreecommitdiffstats
path: root/src/test/groovy/org/onap
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-08-20 11:24:06 +0100
committerniamhcore <niamh.core@est.tech>2021-08-25 11:25:31 +0100
commit79e41e0794035ea8dd3ae3064f8d368b5345df95 (patch)
tree8d16f71d154195caee224407ff50cd6792610e20 /src/test/groovy/org/onap
parenteb26379d71b67c9e76f366665549c92d6f05b1eb (diff)
Write data for cm handle passthrough:running
Issue-ID: CPS-574 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: I15e2ad500d2bbf7a1d408b8a852287e55bddbecb
Diffstat (limited to 'src/test/groovy/org/onap')
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy29
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy43
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClientSpec.groovy2
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy11
4 files changed, 68 insertions, 17 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 b1528c71..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
@@ -26,7 +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
@@ -44,7 +45,6 @@ import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import spock.lang.Specification
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
@@ -121,7 +121,7 @@ class DmiRestControllerSpec extends Specification {
def 'Register given list of cm handles.'() {
given: 'register cm handle url and cm handles json'
def registerCmhandlesPost = "${basePathV1}/inventory/cmHandles"
- def cmHandleJson = '{"cmHandles":["node1", "node2"]}'
+ def cmHandleJson = '{"cmHandles":["node1", "node2"]}'
when: 'post register cm handles api is invoked'
def response = mvc.perform(
post(registerCmhandlesPost)
@@ -161,12 +161,12 @@ class DmiRestControllerSpec extends Specification {
moduleReference2.name = 'nc-notifications'
moduleReference2.revision = '2008-07-14'
def moduleReferences = [moduleReference1, moduleReference2]
- mockDmiService.getModuleResources('some-cm-handle', moduleReferences ) >> '{some-json}'
+ mockDmiService.getModuleResources('some-cm-handle', moduleReferences) >> '{some-json}'
when: 'get module resource api is invoked'
def response = mvc.perform(post(getModulesEndpoint)
.contentType(MediaType.APPLICATION_JSON)
.content(jsonData)).andReturn().response
- then:'a OK status is returned'
+ then: 'a OK status is returned'
response.status == HttpStatus.OK.value()
and: 'the expected response is returned'
response.getContentAsString() == '{some-json}'
@@ -204,7 +204,24 @@ class DmiRestControllerSpec extends Specification {
'application/json',
'myfields',
5,
- ['prop1':'value1', 'prop2':'value2'])
+ ['prop1': 'value1', 'prop2': 'value2'])
+ }
+
+ def 'Write data using passthrough running for a cm handle.'() {
+ 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')
+ and: 'dmi service is called'
+ 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)
+ .content(jsonData)
+ ).andReturn().response
+ then: 'response status is ok'
+ response.status == HttpStatus.OK.value()
+ and: 'the data in the request body is as expected'
+ response.getContentAsString() == '{some-json}'
}
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 31b60a7c..e3703020 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
@@ -68,7 +68,7 @@ class DmiServiceImplSpec extends Specification {
when: 'get modules for cm-handle is called'
def result = objectUnderTest.getModulesForCmHandle(cmHandle)
then: 'a dmi exception is thrown'
- thrown(DmiException)
+ thrown(DmiException)
}
def 'Call get modules for cm-handle and SDNC returns "bad request" status.'() {
@@ -149,8 +149,8 @@ class DmiServiceImplSpec extends Specification {
when: 'get module resources is invoked with the given cm handle and a module list'
def response = objectUnderTest.getModuleResources(cmHandle, moduleList)
then: 'then get modules resources called correctly'
- 1 * mockSdncOperations.getModuleResource(cmHandle,excpectedModulesJson1) >> new ResponseEntity<String>('response-body1', HttpStatus.OK)
- 1 * mockSdncOperations.getModuleResource(cmHandle,excpectedModulesJson2) >> new ResponseEntity<String>('response-body2', HttpStatus.OK)
+ 1 * mockSdncOperations.getModuleResource(cmHandle, excpectedModulesJson1) >> new ResponseEntity<String>('response-body1', HttpStatus.OK)
+ 1 * mockSdncOperations.getModuleResource(cmHandle, excpectedModulesJson2) >> new ResponseEntity<String>('response-body2', HttpStatus.OK)
and: 'the response equals to the expected response body'
response == '["response-body1","response-body2"]'
}
@@ -159,7 +159,7 @@ class DmiServiceImplSpec extends Specification {
given: 'get module schema is invoked and returns not found'
mockSdncOperations.getModuleResource(_ as String, _ as String) >> new ResponseEntity<String>('some-response-body', HttpStatus.BAD_REQUEST)
when: 'get module resources is invoked with the given cm handle and a module list'
- objectUnderTest.getModuleResources('some-cmHandle', [new ModuleReference()] as LinkedList<ModuleReference> )
+ objectUnderTest.getModuleResources('some-cmHandle', [new ModuleReference()] as LinkedList<ModuleReference>)
then: 'ModuleResourceNotFoundException is thrown'
thrown(ModuleResourceNotFoundException)
}
@@ -173,8 +173,7 @@ class DmiServiceImplSpec extends Specification {
def depthParam = 10
def contentQuery = 'content=all'
and: 'sdnc operation returns OK response'
- mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, fieldsParam,
- depthParam, acceptHeaderParam, contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
+ mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, fieldsParam, depthParam, acceptHeaderParam, contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
when: 'get resource data from cm handles service method invoked'
def response = objectUnderTest.getResourceDataOperationalForCmHandle(cmHandle,
resourceId, acceptHeaderParam,
@@ -191,8 +190,7 @@ class DmiServiceImplSpec extends Specification {
def fieldsParam = 'testFields'
def depthParam = 10
and: 'sdnc operation returns "NOT_FOUND" response'
- mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, fieldsParam,
- depthParam, acceptHeaderParam, _ as String) >> new ResponseEntity<>(HttpStatus.NOT_FOUND)
+ mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, fieldsParam, depthParam, acceptHeaderParam, _ as String) >> new ResponseEntity<>(HttpStatus.NOT_FOUND)
when: 'get resource data from cm handles service method invoked'
objectUnderTest.getResourceDataOperationalForCmHandle(cmHandle,
resourceId, acceptHeaderParam,
@@ -211,7 +209,7 @@ class DmiServiceImplSpec extends Specification {
def contentQuery = 'content=config'
and: 'sdnc operation returns OK response'
mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, fieldsParam,
- depthParam, acceptHeaderParam, contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
+ depthParam, acceptHeaderParam, contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
when: 'get resource data from cm handles service method invoked'
def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceId, acceptHeaderParam,
@@ -219,4 +217,31 @@ class DmiServiceImplSpec extends Specification {
then: 'response have expected json'
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 response = objectUnderTest.writeResourceDataPassthroughForCmHandle('some-cmHandle',
+ 'some-resourceIdentifier', 'some-dataType', '{some-data}')
+ then: 'response have expected json'
+ response == 'response json'
+ }
+
+ 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'
+ objectUnderTest.objectMapper = mockObjectMapper
+ mockObjectMapper.writeValueAsString(_) >> jsonString
+ 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
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 e2621e47..9a7ed180 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
@@ -57,7 +57,7 @@ class SdncRestconfClientSpec extends Specification {
and: 'the rest template returns a valid response entity'
def mockResponseEntity = Mock(ResponseEntity)
when: 'get module resources is invoked'
- def result = objectUnderTest.postOperationWithJsonData(getModuleResourceUrl, jsonData)
+ 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
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 3557bc1b..c9d7d1b8 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
@@ -56,7 +56,7 @@ class SdncOperationsSpec extends Specification {
when: 'get module resources is called with the expected parameters'
objectUnderTest.getModuleResource(nodeId, 'some-json-data')
then: 'the SDNC Rest client is invoked with the correct URL and json data'
- 1 * mockSdncRestClient.postOperationWithJsonData(expectedUrl, 'some-json-data')
+ 1 * mockSdncRestClient.postOperationWithJsonData(expectedUrl, 'some-json-data', _ as HttpHeaders)
}
def 'Get resource data from node to SDNC.'() {
@@ -68,4 +68,13 @@ class SdncOperationsSpec extends Specification {
then: 'the get operation is executed with the correct URL'
1 * mockSdncRestClient.getOperation(expectedUrl, _ as HttpHeaders)
}
+
+ def 'Write resource data to SDNC.'() {
+ given: 'excpected 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)
+ }
} \ No newline at end of file