summaryrefslogtreecommitdiffstats
path: root/src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy')
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/DmiServiceImplSpec.groovy58
1 files changed, 37 insertions, 21 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 93bc641e..9325d59b 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
@@ -22,6 +22,7 @@ package org.onap.cps.ncmp.dmi.service
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.ObjectWriter
import org.onap.cps.ncmp.dmi.TestUtils
import org.onap.cps.ncmp.dmi.config.DmiPluginConfig
import org.onap.cps.ncmp.dmi.exception.CmHandleRegistrationException
@@ -29,7 +30,7 @@ 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.model.ModuleReference
import org.onap.cps.ncmp.dmi.model.YangResource
import org.onap.cps.ncmp.dmi.model.YangResources
import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient
@@ -43,10 +44,10 @@ class DmiServiceImplSpec extends Specification {
def mockNcmpRestClient = Mock(NcmpRestClient)
def mockDmiPluginProperties = Mock(DmiPluginConfig.DmiPluginProperties)
- def objectMapper = new ObjectMapper()
+ def spyObjectMapper = Spy(ObjectMapper)
def mockObjectMapper = Mock(ObjectMapper)
def mockSdncOperations = Mock(SdncOperations)
- def objectUnderTest = new DmiServiceImpl(mockDmiPluginProperties, mockNcmpRestClient, mockSdncOperations, objectMapper)
+ def objectUnderTest = new DmiServiceImpl(mockDmiPluginProperties, mockNcmpRestClient, mockSdncOperations, spyObjectMapper)
def 'Call get modules for cm-handle on dmi Service.'() {
given: 'cm handle id'
@@ -175,31 +176,48 @@ class DmiServiceImplSpec extends Specification {
def 'Get module resources when sdnc returns #scenario response.'() {
given: 'get module schema is invoked and returns a response from sdnc'
- mockSdncOperations.getModuleResource(_ as String, _ as String) >> new ResponseEntity<String>('some-response-body', httpResponse)
+ mockSdncOperations.getModuleResource(_ as String, _ as String) >> new ResponseEntity<String>('some-response-body', httpStatus)
when: 'get module resources is invoked with the given cm handle and a module list'
objectUnderTest.getModuleResources('some-cmHandle', [new ModuleReference()] as LinkedList<ModuleReference>)
- then: 'ModuleResourceNotFoundException is thrown'
- thrown(exception)
+ then: '#expectedException is thrown'
+ thrown(expectedException)
where: 'the following values are returned'
- scenario | httpResponse || exception
+ scenario | httpStatus || expectedException
'not found' | HttpStatus.NOT_FOUND || ModuleResourceNotFoundException
'a internal server' | HttpStatus.INTERNAL_SERVER_ERROR || DmiException
}
+ def 'Get module resources with JSON processing exception.'() {
+ given: 'a json processing exception during conversion'
+ def mockObjectWriter = Mock(ObjectWriter)
+ spyObjectMapper.writer() >> mockObjectWriter
+ mockObjectWriter.withRootName(_) >> mockObjectWriter
+ def jsonProcessingException = new JsonProcessingException('')
+ mockObjectWriter.writeValueAsString(_) >> { throw jsonProcessingException }
+ when: 'get module resources is invoked with the given cm handle and a module list'
+ objectUnderTest.getModuleResources('some-cmHandle', [new ModuleReference()] as LinkedList<ModuleReference>)
+ then: 'a DMI exception is thrown'
+ def thrownException = thrown(DmiException.class)
+ and: 'the exception has the expected message and details'
+ thrownException.message == 'Unable to process JSON.'
+ thrownException.details == 'JSON exception occurred when creating the module request.'
+ and: 'the cause is the original json processing exception'
+ thrownException.cause == jsonProcessingException
+ }
+
def 'Get resource data for pass through operational 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
+ def optionsParam = '(fields=x/y/z,depth=10,test=abc)'
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, optionsParam, 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,
- fieldsParam, depthParam, null)
+ optionsParam, null)
then: 'response have expected json'
response == 'response json'
}
@@ -209,14 +227,13 @@ class DmiServiceImplSpec extends Specification {
def cmHandle = 'testCmHandle'
def resourceId = 'testResourceId'
def acceptHeaderParam = 'testAcceptParam'
- def fieldsParam = 'testFields'
- def depthParam = 10
+ def optionsParam = '(fields=x/y/z,depth=10,test=abc)'
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, optionsParam, acceptHeaderParam, _ as String) >> new ResponseEntity<>(HttpStatus.NOT_FOUND)
when: 'get resource data from cm handles service method invoked'
objectUnderTest.getResourceDataOperationalForCmHandle(cmHandle,
resourceId, acceptHeaderParam,
- fieldsParam, depthParam, null)
+ optionsParam, null)
then: 'resource data not found'
thrown(ResourceDataNotFound.class)
}
@@ -226,16 +243,15 @@ class DmiServiceImplSpec extends Specification {
def cmHandle = 'testCmHandle'
def resourceId = 'testResourceId'
def acceptHeaderParam = 'testAcceptParam'
- def fieldsParam = 'testFields'
- def depthParam = 10
+ def optionsParam = '(fields=x/y/z,depth=10,test=abc)'
def contentQuery = 'content=config'
and: 'sdnc operation returns OK response'
- mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, fieldsParam,
- depthParam, acceptHeaderParam, contentQuery) >> new ResponseEntity<>('response json', HttpStatus.OK)
+ mockSdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceId, optionsParam,
+ 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,
- fieldsParam, depthParam, null)
+ optionsParam, null)
then: 'response have expected json'
response == 'response json'
}
@@ -278,4 +294,4 @@ class DmiServiceImplSpec extends Specification {
then: 'a dmi exception is thrown'
thrown(DmiException.class)
}
-} \ No newline at end of file
+}