aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
authortragait <rahul.tyagi@est.tech>2021-08-20 15:45:58 +0100
committertragait <rahul.tyagi@est.tech>2021-08-26 12:50:30 +0100
commitc584bf2729bb6eb9229aad9dbacc65beaa5dbc2f (patch)
tree9a44c8563dc73db1a620de7053cb1eace58fefae /cps-ncmp-service/src/test
parent673c6d94830a1677e685cab82a76747a0808d347 (diff)
Post impl for passthrough running (Ncmp impl.)
Issue-ID: CPS-577 Signed-off-by: tragait <rahul.tyagi@est.tech> Change-Id: Ic8983349cf88fb123feb95ce01ec6fdf670469f4
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy132
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy16
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy29
3 files changed, 109 insertions, 68 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 45fa0af45..8a32ad592 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
@@ -51,6 +51,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
def cmHandle = 'some handle'
def noTimestamp = null
+ def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
def expectedDataspaceName = 'NFP-Operational'
def 'Query data nodes by cps path with #fetchDescendantsOption.'() {
@@ -159,14 +160,8 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
}
def 'Get resource data for pass-through operational from dmi.'() {
- given: 'xpath'
- def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
- and: 'data node'
- def dataNode = new DataNode()
- dataNode.leaves = ['dmi-service-name':'testDmiService']
- def childDataNode = new DataNode()
- childDataNode.leaves = ['name':'testName','value':'testValue']
- dataNode.childDataNodes = [childDataNode]
+ given: 'data node representing cmHandle and its properties'
+ def cmHandleDataNode = prepareCmHandleDataNode()
when: 'get resource data is called'
def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceId',
@@ -175,9 +170,9 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
5)
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
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
and: 'dmi operation is being called to get resource data'
- 1 * mockDmiOperations.getResouceDataOperationalFromDmi('testDmiService',
+ 1 * mockDmiOperations.getResourceDataOperationalFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -188,17 +183,13 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
and: 'dmi returns ok response'
response == 'result-json'
}
+
def 'Get resource data for pass-through operational from dmi threw parsing exception.'() {
- given: 'xpath'
- def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
- and: 'data node'
- def dataNode = new DataNode()
- dataNode.leaves = ['dmi-service-name':'testDmiService']
- def childDataNode = new DataNode()
- childDataNode.leaves = ['name':'testName','value':'testValue']
- dataNode.childDataNodes = [childDataNode]
+ given: 'data node representing cmHandle and its properties'
+ def cmHandleDataNode = prepareCmHandleDataNode()
+ and: 'cps data service returns valid cmHandle data node'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
- xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
and: 'objectMapper not able to parse object'
def mockObjectMapper = Mock(ObjectMapper)
objectUnderTest.objectMapper = mockObjectMapper
@@ -212,19 +203,15 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
then: 'exception is thrown'
thrown(NcmpException.class)
}
+
def 'Get resource data for pass-through operational from dmi return NOK response.'() {
- given: 'xpath'
- def xpath = "/dmi-registry/cm-handles[@id='testCmHandle']"
- and: 'data node'
- def dataNode = new DataNode()
- dataNode.leaves = ['dmi-service-name':'testDmiService']
- def childDataNode = new DataNode()
- childDataNode.leaves = ['name':'testName','value':'testValue']
- dataNode.childDataNodes = [childDataNode]
+ given: 'data node representing cmHandle and its properties'
+ def cmHandleDataNode = prepareCmHandleDataNode()
+ and: 'cps data service returns valid cmHandle data node'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
- xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
and: 'dmi returns NOK response'
- mockDmiOperations.getResouceDataOperationalFromDmi('testDmiService',
+ mockDmiOperations.getResourceDataOperationalFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -241,20 +228,15 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
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]
+ given: 'data node representing cmHandle and its properties'
+ def cmHandleDataNode = prepareCmHandleDataNode()
and: 'cpsDataService returns valid dataNode'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
- xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
and: 'dmi returns valid response and data'
- mockDmiOperations.getResouceDataPassThroughRunningFromDmi('testDmiService',
+ mockDmiOperations.getResourceDataPassThroughRunningFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -270,18 +252,13 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
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]
+ given: 'data node representing cmHandle and its properties'
+ def cmHandleDataNode = prepareCmHandleDataNode()
and: 'cpsDataService returns valid dataNode'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
- xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
and: 'objectMapper not able to parse object'
def mockObjectMapper = Mock(ObjectMapper)
objectUnderTest.objectMapper = mockObjectMapper
@@ -295,20 +272,15 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
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]
+ given: 'data node representing cmHandle and its properties'
+ def cmHandleDataNode = prepareCmHandleDataNode()
and: 'cpsDataService returns valid dataNode'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
- xpath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
and: 'dmi returns NOK response'
- mockDmiOperations.getResouceDataPassThroughRunningFromDmi('testDmiService',
+ mockDmiOperations.getResourceDataPassThroughRunningFromDmi('testDmiService',
'testCmHandle',
'testResourceId',
'testFieldQuery',
@@ -325,4 +297,48 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
then: 'exception is thrown'
thrown(NcmpException.class)
}
+
+ def 'Write resource data for pass-through running from dmi using POST.'() {
+ given: 'data node representing cmHandle and its properties'
+ def cmHandleDataNode = prepareCmHandleDataNode()
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
+ when: 'get resource data is called'
+ objectUnderTest.createResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId',
+ '{some-json}', 'application/json')
+ then: 'dmi called with correct data'
+ 1 * mockDmiOperations.createResourceDataPassThroughRunningFromDmi('testDmiService',
+ 'testCmHandle',
+ 'testResourceId',
+ '{"operation":"create","dataType":"application/json","data":"{some-json}","cmHandleProperties":{"testName":"testValue"}}')
+ >> { new ResponseEntity<>(HttpStatus.CREATED) }
+ }
+
+ def 'Write resource data for pass-through running from dmi using POST "not found" response (from DMI).'() {
+ given: 'data node representing cmHandle and its properties'
+ def cmHandleDataNode = prepareCmHandleDataNode()
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
+ and: 'dmi throws exception'
+ 1 * mockDmiOperations.createResourceDataPassThroughRunningFromDmi(_ as String, _ as String, _ as String, _ as String)
+ >> { new ResponseEntity<>(HttpStatus.NOT_FOUND) }
+ when: 'get resource data is called'
+ objectUnderTest.createResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId',
+ '{some-json}', 'application/json')
+ then: 'exception is thrown'
+ thrown(NcmpException.class)
+ }
+
+ private DataNode prepareCmHandleDataNode() {
+ def cmHandleDataNode = new DataNode()
+ cmHandleDataNode.leaves = ['dmi-service-name': 'testDmiService']
+ def cmHandlePropertyDataNode = new DataNode()
+ cmHandlePropertyDataNode.leaves = ['name': 'testName', 'value': 'testValue']
+ cmHandleDataNode.childDataNodes = [cmHandlePropertyDataNode]
+ cmHandleDataNode
+ }
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
index 98bbe8748..879c73c27 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
@@ -35,7 +35,7 @@ class DmiRestClientSpec extends Specification {
def objectUnderTest = new DmiRestClient(mockRestTemplate, mockDmiProperties)
def 'DMI PUT operation.'() {
- given: 'a get url'
+ given: 'a PUT url'
def getResourceDataUrl = 'http://some-uri/getResourceDataUrl'
and: 'dmi properties'
setupTestConfigurationData()
@@ -48,6 +48,20 @@ class DmiRestClientSpec extends Specification {
result == mockResponseEntity
}
+ def 'DMI POST operation.'() {
+ given: 'a POST url'
+ def getResourceDataUrl = 'http://some-uri/createResourceDataUrl'
+ and: 'dmi properties'
+ setupTestConfigurationData()
+ and: 'the rest template returns a valid response entity'
+ def mockResponseEntity = Mock(ResponseEntity)
+ mockRestTemplate.postForEntity(getResourceDataUrl, _ as HttpEntity, Void.class) >> mockResponseEntity
+ when: 'POST operation is invoked'
+ def result = objectUnderTest.postOperationWithJsonData(getResourceDataUrl, 'json-data', new HttpHeaders())
+ then: 'the output of the method is equal to the output from the test template'
+ result == mockResponseEntity
+ }
+
def setupTestConfigurationData() {
mockDmiProperties.authUsername >> 'some-username'
mockDmiProperties.authPassword >> 'some-password'
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 ceb35696a..c2a135e67 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
@@ -22,7 +22,6 @@ package org.onap.cps.ncmp.api.impl.operation
import org.onap.cps.ncmp.api.impl.client.DmiRestClient
import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
-import org.onap.cps.ncmp.api.impl.operation.DmiOperations
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
@@ -40,12 +39,12 @@ class DmiOperationsSpec extends Specification {
@Autowired
DmiOperations objectUnderTest = new DmiOperations(mockDmiRestClient)
- def 'call get resource data for pass-through:operational datastore from dmi.'() {
+ def 'call get resource data for pass-through:operational datastore from DMI.'() {
given: 'expected url'
- def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
+ def expectedUrl = 'testDmiBasePath/dmi/api/v1/ch/testCmhandle/data/ds' +
'/ncmp-datastore:passthrough-operational/testResourceId?fields=testFieldsQuery&depth=10'
- when: 'get resource data is called to dmi'
- objectUnderTest.getResouceDataOperationalFromDmi('testDmiBasePath',
+ when: 'get resource data is called to DMI'
+ objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath',
'testCmhandle',
'testResourceId',
'testFieldsQuery',
@@ -55,12 +54,12 @@ class DmiOperationsSpec extends Specification {
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.'() {
+ def 'call get resource data for pass-through:running datastore from DMI.'() {
given: 'expected url'
- def expectedUrl = 'testDmiBasePath/v1/ch/testCmhandle/data/ds' +
+ def expectedUrl = 'testDmiBasePath/dmi/api/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',
+ when: 'get resource data is called to DMI'
+ objectUnderTest.getResourceDataPassThroughRunningFromDmi('testDmiBasePath',
'testCmhandle',
'testResourceId',
'testFieldsQuery',
@@ -70,4 +69,16 @@ class DmiOperationsSpec extends Specification {
then: 'the put operation is executed with the correct URL'
1 * mockDmiRestClient.putOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
}
+ def 'call create resource data for pass-through:running datastore from DMI.'() {
+ given: 'expected url'
+ def expectedUrl = 'testDmiBasePath/dmi/api/v1/ch/testCmhandle/data/ds' +
+ '/ncmp-datastore:passthrough-running/testResourceId'
+ when: 'get resource data is called to DMI'
+ objectUnderTest.createResourceDataPassThroughRunningFromDmi('testDmiBasePath',
+ 'testCmhandle',
+ 'testResourceId',
+ 'testJsonbody')
+ then: 'the put operation is executed with the correct URL'
+ 1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders)
+ }
} \ No newline at end of file