diff options
author | tragait <rahul.tyagi@est.tech> | 2021-08-06 17:01:31 +0100 |
---|---|---|
committer | tragait <rahul.tyagi@est.tech> | 2021-08-17 13:55:12 +0100 |
commit | e398be5923a47650b109512c795244cdc2b5eb10 (patch) | |
tree | 4d12aa2f7d18785825f4c5b1e9073a68505cf30b /src/test | |
parent | 3139ece993c68ce7e40d166acdd5d9572a3a8a1e (diff) |
implement passthough operational for dmi
Issue-ID: CPS-486
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: Icf48fa93ea1f0d8a27d2e7e1ab0cfd6096a765ec
Diffstat (limited to 'src/test')
4 files changed, 90 insertions, 5 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 03bffe4b..0c8ae3fc 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 @@ -36,7 +36,9 @@ 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 @WebMvcTest @AutoConfigureMockMvc(addFilters = false) @@ -152,4 +154,25 @@ class DmiRestControllerSpec extends Specification { then: 'a not found status is returned' response.status == HttpStatus.NOT_FOUND.value() } -} + + def 'Get resource data for cm handle.'() { + given: 'Get resource data url' + def getResourceDataForCmHandleUrl = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-operational" + + "/resourceIdentifier?fields=myfields&depth=5" + def json = '{"cmHandleProperties" : { "prop1" : "value1", "prop2" : "value2"}}' + when: 'get resource data GET api is invoked' + def response = mvc.perform( + put(getResourceDataForCmHandleUrl).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).content(json) + ).andReturn().response + then: 'response status is ok' + response.status == HttpStatus.OK.value() + and: 'dmi service called with get resource data for cm handle' + 1 * mockDmiService.getResourceDataOperationalForCmHandle('some-cmHandle', + 'resourceIdentifier', + 'application/json', + 'myfields', + 5, + ['prop1':'value1', 'prop2':'value2']) + } +}
\ No newline at end of file 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 1854b24d..da8ff6b8 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 @@ -27,6 +27,7 @@ import org.onap.cps.ncmp.dmi.exception.CmHandleRegistrationException 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.exception.ResourceDataNotFound import org.onap.cps.ncmp.dmi.model.ModuleReference import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient import org.onap.cps.ncmp.dmi.service.operation.SdncOperations @@ -136,8 +137,8 @@ class DmiServiceImplSpec extends Specification { 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) - then: 'the response contains the expected response body' - response.contains('["response-body1","response-body2"]') + and: 'the response equals to the expected response body' + response == '["response-body1","response-body2"]' } def 'Get module resources for a failed get module schema request.'() { @@ -148,4 +149,39 @@ class DmiServiceImplSpec extends Specification { then: 'ModuleResourceNotFoundException is thrown' thrown(ModuleResourceNotFoundException) } -} + + def 'Get resource data from cm handle.'() { + given: 'cm-handle, pass through parameter, resourceId, accept header, fields, depth' + def cmHandle = 'testCmHandle' + def resourceId = 'testResourceId' + def acceptHeaderParam = 'testAcceptParam' + def fieldsParam = 'testFields' + def depthParam = 10 + and: 'sdnc operation returns OK response' + mockSdncOperations.getResouceDataForOperational(cmHandle, resourceId, fieldsParam, depthParam, acceptHeaderParam ) >> new ResponseEntity<>('response json', HttpStatus.OK) + when: 'get resource data from cm handles service method invoked' + def response = objectUnderTest.getResourceDataOperationalForCmHandle(cmHandle, + resourceId, acceptHeaderParam, + fieldsParam, depthParam, null) + then: 'response have expected json' + response == 'response json' + } + + def 'Get resource data from cm handle with exception.'() { + given: 'cm-handle, pass through parameter, resourceId, accept header, fields, depth' + def cmHandle = 'testCmHandle' + def resourceId = 'testResourceId' + def acceptHeaderParam = 'testAcceptParam' + def fieldsParam = 'testFields' + def depthParam = 10 + and: 'sdnc operation returns "NOT_FOUND" response' + mockSdncOperations.getResouceDataForOperational(cmHandle, resourceId, fieldsParam, depthParam, acceptHeaderParam ) + >> new ResponseEntity<>(HttpStatus.NOT_FOUND) + when: 'get resource data from cm handles service method invoked' + objectUnderTest.getResourceDataOperationalForCmHandle(cmHandle, + resourceId, acceptHeaderParam, + fieldsParam, depthParam, null) + then: 'resource data not found' + thrown(ResourceDataNotFound.class) + } +}
\ 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 6d9445c1..e2621e47 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 @@ -22,6 +22,7 @@ package org.onap.cps.ncmp.dmi.service.client import org.onap.cps.ncmp.dmi.config.DmiConfiguration import org.springframework.http.HttpEntity +import org.springframework.http.HttpHeaders import org.springframework.http.ResponseEntity import org.springframework.web.client.RestTemplate import spock.lang.Specification @@ -64,6 +65,20 @@ class SdncRestconfClientSpec extends Specification { result == mockResponseEntity } + def 'SDNC GET operation with header.'() { + given: 'a get url' + def getResourceUrl = '/getResourceUrl' + and: 'sdnc properties' + setupTestConfigurationData() + and: 'the rest template returns a valid response entity' + def mockResponseEntity = Mock(ResponseEntity) + mockRestTemplate.getForEntity({ it.toString() == 'http://some-uri/getResourceUrl' }, String.class, _ as HttpEntity) >> mockResponseEntity + when: 'GET operation is invoked' + def result = objectUnderTest.getOperation(getResourceUrl, new HttpHeaders()) + then: 'the output of the method is equal to the output from the test template' + result == mockResponseEntity + } + def setupTestConfigurationData() { mockSdncProperties.baseUrl >> 'http://some-uri' mockSdncProperties.authUsername >> 'some-username' 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 9b07d68e..8a415c82 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 @@ -25,6 +25,7 @@ import org.onap.cps.ncmp.dmi.service.client.SdncRestconfClient import org.spockframework.spring.SpringBean import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.HttpHeaders import org.springframework.test.context.ContextConfiguration import spock.lang.Specification @@ -34,6 +35,7 @@ class SdncOperationsSpec extends Specification { @SpringBean SdncRestconfClient mockSdncRestClient = Mock() + @Autowired SdncOperations objectUnderTest @@ -56,4 +58,13 @@ class SdncOperationsSpec extends Specification { then: 'the SDNC Rest client is invoked with the correct URL and json data' 1 * mockSdncRestClient.postOperationWithJsonData(expectedUrl, 'some-json-data') } -} + + def 'Get resource data from node 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?fields=testFields&depth=10&content=all' + when: 'called get modules from node' + objectUnderTest.getResouceDataForOperational('node1', 'testResourceId', 'testFields', 10,'testAcceptParam') + then: 'the get operation is executed with the correct URL' + 1 * mockSdncRestClient.getOperation(expectedUrl, _ as HttpHeaders) + } +}
\ No newline at end of file |