summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy/org/onap
diff options
context:
space:
mode:
authortragait <rahul.tyagi@est.tech>2021-08-19 15:17:56 +0100
committertragait <rahul.tyagi@est.tech>2021-08-20 15:31:31 +0100
commit888dcd495ecb63bf678e7234e9dc34e0743cb412 (patch)
tree65e1208beacc9a11eeb08985a1d4b28a90f3864c /cps-ncmp-service/src/test/groovy/org/onap
parentdc5ed75c841da857611713bceed8bf9988204d3d (diff)
Get resource data from pass through running (Ncmp impl.)
Issue-ID: CPS-580 Signed-off-by: tragait <rahul.tyagi@est.tech> Change-Id: I6dc37d9516078c87efc3f0c5bbd2b7b8a7155d48
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org/onap')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy96
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy17
2 files changed, 106 insertions, 7 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
index 65d96a4296..ac290af411 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
@@ -126,7 +126,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
childDataNode.leaves = ['name':'testName','value':'testValue']
dataNode.childDataNodes = [childDataNode]
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataOperationalFoCmHandle('testCmHandle',
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
@@ -134,8 +134,8 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
then: 'cps data service is being called once to get data node'
1 * mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
- and: 'dmi operation is being calle to get resource data'
- 1 * mockDmiOperations.getResouceDataFromDmi('testDmiService',
+ and: 'dmi operation is being called to get resource data'
+ 1 * mockDmiOperations.getResouceDataOperationalFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -161,7 +161,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
objectUnderTest.objectMapper = mockObjectMapper
mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException("testException") }
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataOperationalFoCmHandle('testCmHandle',
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
@@ -181,7 +181,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
and: 'dmi returns NOK response'
- mockDmiOperations.getResouceDataFromDmi('testDmiService',
+ mockDmiOperations.getResouceDataOperationalFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -190,7 +190,91 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
>> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
when: 'get resource data is called'
- def response = objectUnderTest.getResourceDataOperationalFoCmHandle('testCmHandle',
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ 'testFieldQuery',
+ 5)
+ then: 'exception is thrown'
+ thrown(NcmpException.class)
+ }
+ def 'Get resource data for pass-through running from dmi.'() {
+ given: 'xpath'
+ def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ and: 'data node representing cmhandle and its properties'
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name':'testDmiService']
+ def childDataNode = new DataNode()
+ childDataNode.leaves = ['name':'testName','value':'testValue']
+ dataNode.childDataNodes = [childDataNode]
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'dmi returns valid response and data'
+ mockDmiOperations.getResouceDataPassThroughRunningFromDmi('testDmiService',
+ 'testCmHandle',
+ 'testResourceId',
+ 'testFieldQuery',
+ 5,
+ 'testAcceptParam',
+ '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('{result-json}', HttpStatus.OK)
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ 'testFieldQuery',
+ 5)
+ then: 'get resource data returns expected response'
+ response == '{result-json}'
+ }
+ def 'Get resource data for pass-through running from dmi threw parsing exception.'() {
+ given: 'xpath'
+ def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ and: 'data node representing cmhandle and its properties'
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name':'testDmiService']
+ def childDataNode = new DataNode()
+ childDataNode.leaves = ['name':'testName','value':'testValue']
+ dataNode.childDataNodes = [childDataNode]
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'objectMapper not able to parse object'
+ def mockObjectMapper = Mock(ObjectMapper)
+ objectUnderTest.objectMapper = mockObjectMapper
+ mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException("testException") }
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ 'testFieldQuery',
+ 5)
+ then: 'exception is thrown'
+ thrown(NcmpException.class)
+ }
+ def 'Get resource data for pass-through running from dmi return NOK response.'() {
+ given: 'xpath'
+ def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+ and: 'data node representing cmhandle and its properties'
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name':'testDmiService']
+ def childDataNode = new DataNode()
+ childDataNode.leaves = ['name':'testName','value':'testValue']
+ dataNode.childDataNodes = [childDataNode]
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'dmi returns NOK response'
+ mockDmiOperations.getResouceDataPassThroughRunningFromDmi('testDmiService',
+ 'testCmHandle',
+ 'testResourceId',
+ 'testFieldQuery',
+ 5,
+ 'testAcceptParam',
+ '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}')
+ >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
index 75b5383d8a..ceb35696a9 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
@@ -45,7 +45,22 @@ class DmiOperationsSpec extends Specification {
def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
'/ncmp-datastore:passthrough-operational/testResourceId?fields=testFieldsQuery&depth=10'
when: 'get resource data is called to dmi'
- objectUnderTest.getResouceDataFromDmi('testDmiBasePath',
+ objectUnderTest.getResouceDataOperationalFromDmi('testDmiBasePath',
+ 'testCmhandle',
+ 'testResourceId',
+ 'testFieldsQuery',
+ 10,
+ 'testAcceptJson',
+ 'testJsonbody')
+ then: 'the put operation is executed with the correct URL'
+ 1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
+ }
+ def 'call get resource data for pass-through:running datastore from dmi.'() {
+ given: 'expected url'
+ def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
+ '/ncmp-datastore:passthrough-running/testResourceId?fields=testFieldsQuery&depth=10'
+ when: 'get resource data is called to dmi'
+ objectUnderTest.getResouceDataPassThroughRunningFromDmi('testDmiBasePath',
'testCmhandle',
'testResourceId',
'testFieldsQuery',