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.groovy44
1 files changed, 38 insertions, 6 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 9d6bc358..1854b24d 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
@@ -25,7 +25,9 @@ import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.ncmp.dmi.config.DmiPluginConfig
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.model.ModuleReference
import org.onap.cps.ncmp.dmi.service.client.NcmpRestClient
import org.onap.cps.ncmp.dmi.service.operation.SdncOperations
import org.springframework.http.HttpStatus
@@ -40,7 +42,7 @@ class DmiServiceImplSpec extends Specification {
def objectMapper = new ObjectMapper()
def mockObjectMapper = Mock(ObjectMapper)
def mockSdncOperations = Mock(SdncOperations)
- def objectUnderTest = new DmiServiceImpl(mockDmiPluginProperties, mockNcmpRestClient, objectMapper, mockSdncOperations)
+ def objectUnderTest = new DmiServiceImpl(mockDmiPluginProperties, mockNcmpRestClient, mockSdncOperations, objectMapper)
def 'Call get modules for cm-handle on dmi Service.'() {
given: 'cm handle id'
@@ -62,7 +64,7 @@ class DmiServiceImplSpec extends Specification {
when: 'get modules for cm-handle is called'
objectUnderTest.getModulesForCmHandle(cmHandle)
then: 'dmi exception is thrown'
- thrown( DmiException )
+ thrown(DmiException)
}
def 'Call get modules for cm-handle and SDNC returns OK with empty body.'() {
@@ -73,7 +75,7 @@ class DmiServiceImplSpec extends Specification {
when: 'get modules for cm-handle is called'
objectUnderTest.getModulesForCmHandle(cmHandle)
then: 'ModulesNotFoundException is thrown'
- thrown( ModulesNotFoundException )
+ thrown(ModulesNotFoundException)
}
def 'Register cm handles with ncmp.'() {
@@ -100,9 +102,9 @@ class DmiServiceImplSpec extends Specification {
then: 'a registration exception is thrown'
thrown(CmHandleRegistrationException.class)
where: 'given #scenario'
- scenario | responseEntity
- 'ncmp rest client returns bad request' | new ResponseEntity<>(HttpStatus.BAD_REQUEST)
- 'ncmp rest client returns internal server error'| new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)
+ scenario | responseEntity
+ 'ncmp rest client returns bad request' | new ResponseEntity<>(HttpStatus.BAD_REQUEST)
+ 'ncmp rest client returns internal server error' | new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR)
}
def 'Register cm handles with ncmp with wrong data.'() {
@@ -116,4 +118,34 @@ class DmiServiceImplSpec extends Specification {
then: 'a dmi exception is thrown'
thrown(DmiException.class)
}
+
+ def 'Get module resources.'() {
+ given: 'cmHandle, expected jsons and module reference list'
+ def cmHandle = 'some-cmHandle'
+ def excpectedModulesJson1 = '{"ietf-netconf-monitoring:input":{"ietf-netconf-monitoring:identifier":"mRef1","ietf-netconf-monitoring:version":"mRefV1"}}'
+ def excpectedModulesJson2 = '{"ietf-netconf-monitoring:input":{"ietf-netconf-monitoring:identifier":"mRef2","ietf-netconf-monitoring:version":"mRefV2"}}'
+ def mRef1 = Mock(ModuleReference.class)
+ def mRef2 = Mock(ModuleReference.class)
+ mRef1.getName() >> 'mRef1'
+ mRef1.getRevision() >> 'mRefV1'
+ mRef2.getName() >> 'mRef2'
+ mRef2.getRevision() >> 'mRefV2'
+ def moduleList = [mRef1, mRef2] as LinkedList<ModuleReference>
+ when: 'get module resources is invoked with the given cm handle and a module list'
+ def response = objectUnderTest.getModuleResources(cmHandle, moduleList)
+ 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"]')
+ }
+
+ def 'Get module resources for a failed get module schema request.'() {
+ given: 'get module schema is invoked and returns not found'
+ mockSdncOperations.getModuleResource(_ as String, _ as String) >> new ResponseEntity<String>('some-response-body', HttpStatus.BAD_REQUEST)
+ 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(ModuleResourceNotFoundException)
+ }
}