+ def mockCpsModuleService = Mock(CpsModuleService)
+ def mockCpsAdminService = Mock(CpsAdminService)
+ def spyObjectMapper = Spy(ObjectMapper)
+ def mockDmiDataOperations = Mock(DmiDataOperations)
+
+ def objectUnderTest = new NetworkCmProxyDataServiceImpl(mockDmiDataOperations, null,
+ mockCpsModuleService, mockCpsDataService, mockCpsAdminService, spyObjectMapper)
+
+ def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+
+
+ def 'Write resource data for pass-through running from dmi using POST #scenario cm handle properties.'() {
+ given: 'a data node'
+ def dataNode = getDataNode(includeCmHandleProperties)
+ and: 'cpsDataService returns valid datanode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ when: 'get resource data is called'
+ objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId', CREATE,
+ '{some-json}', 'application/json')
+ then: 'dmi called with correct data'
+ 1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
+ CREATE, '{some-json}', 'application/json')
+ >> { new ResponseEntity<>(HttpStatus.CREATED) }
+ where:
+ scenario | includeCmHandleProperties || expectedJsonForCmhandleProperties
+ 'with' | true || '{"testName":"testValue"}'
+ 'without' | false || '{}'
+ }
+
+ def 'Write resource data for pass-through running from dmi using POST "not found" response (from DMI).'() {
+ given: 'a data node'
+ def dataNode = getDataNode(true)
+ and: 'cpsDataService returns valid dataNode'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'dmi returns a response with 404 status code'
+ mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle',
+ 'testResourceId', CREATE,
+ '{some-json}', 'application/json')
+ >> { new ResponseEntity<>(HttpStatus.NOT_FOUND) }
+ when: 'write resource data is called'
+ objectUnderTest.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId', CREATE,
+ '{some-json}', 'application/json')
+ then: 'exception is thrown'
+ def exceptionThrown = thrown(NcmpException.class)
+ and: 'details contains (not found) error code: 404'
+ exceptionThrown.details.contains('404')
+ }
+
+
+ def 'Get resource data for pass-through operational from dmi.'() {
+ given: 'a data node'
+ def dataNode = getDataNode(true)
+ and: 'get data node is called'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'get resource data from dmi is called'
+ mockDmiDataOperations.getResourceDataFromDmi(
+ 'testCmHandle',
+ 'testResourceId',
+ '(a=1,b=2)',
+ 'testAcceptParam' ,
+ PASSTHROUGH_OPERATIONAL) >> new ResponseEntity<>('result-json', HttpStatus.OK)
+ when: 'get resource data operational for cm-handle is called'
+ def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ '(a=1,b=2)')
+ then: 'dmi returns a json response'
+ response == 'result-json'
+ }
+
+ def 'Get resource data for pass-through operational from dmi with Json Processing Exception.'() {
+ given: 'a data node'
+ def dataNode = getDataNode(true)
+ and: 'cps data service returns valid data node'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ cmHandleXPath, 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') }
+ and: 'dmi returns NOK response'
+ mockDmiDataOperations.getResourceDataFromDmi(*_)
+ >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
+ when: 'get resource data is called'
+ objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ '(a=1,b=2)')
+ then: 'exception is thrown with the expected details'
+ def exceptionThrown = thrown(NcmpException.class)
+ exceptionThrown.details == 'DMI status code: 404, DMI response body: NOK-json'
+ }
+
+ def 'Get resource data for pass-through operational from dmi return NOK response.'() {
+ given: 'a data node'
+ def dataNode = getDataNode(true)
+ and: 'cps data service returns valid data node'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'dmi returns NOK response'
+ mockDmiDataOperations.getResourceDataFromDmi('testCmHandle',
+ 'testResourceId',
+ '(a=1,b=2)',
+ 'testAcceptParam',
+ PASSTHROUGH_OPERATIONAL)
+ >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
+ when: 'get resource data is called'
+ objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ '(a=1,b=2)')
+ then: 'exception is thrown'
+ def exceptionThrown = thrown(NcmpException.class)
+ and: 'details contains the original response'
+ exceptionThrown.details.contains('NOK-json')