summaryrefslogtreecommitdiffstats
path: root/src/test/groovy/org/onap/cps/ncmp/dmi/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/groovy/org/onap/cps/ncmp/dmi/service')
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy42
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/client/SdncRestconfClientSpec.groovy15
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy13
3 files changed, 66 insertions, 4 deletions
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