+ def exceptionThrown = thrown(NcmpException.class)
+ and: 'details contains the original response'
+ exceptionThrown.details.contains('NOK-json')
+ }
+
+ def 'Get resource data for pass-through running from dmi.'() {
+ given: 'a data node'
+ def dataNode = getDataNode(true)
+ and: 'cpsDataService returns valid data node'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ and: 'dmi returns valid response and data'
+ mockDmiDataOperations.getResourceDataFromDmi('testCmHandle',
+ 'testResourceId',
+ '(a=1,b=2)',
+ 'testAcceptParam',
+ PASSTHROUGH_RUNNING) >> new ResponseEntity<>('{result-json}', HttpStatus.OK)
+ when: 'get resource data is called'
+ def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceId',
+ 'testAcceptParam',
+ '(a=1,b=2)')
+ then: 'get resource data returns expected response'
+ response == '{result-json}'
+ }
+
+ def 'Get resource data for pass-through running from dmi return NOK response.'() {
+ 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 NOK response'
+ mockDmiDataOperations.getResourceDataFromDmi('testCmHandle',
+ 'testResourceId',
+ '(a=1,b=2)',
+ 'testAcceptParam',
+ PASSTHROUGH_RUNNING)
+ >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND)
+ when: 'get resource data is called'
+ objectUnderTest.getResourceDataPassThroughRunningForCmHandle('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')
+ }
+
+ def 'Getting Yang Resources.'() {
+ when: 'yang resources is called'
+ objectUnderTest.getYangResourcesModuleReferences('some cm handle')
+ then: 'CPS module services is invoked for the correct dataspace and cm handle'
+ 1 * mockCpsModuleService.getYangResourcesModuleReferences('NFP-Operational','some cm handle')
+ }
+
+ def 'Get cm handle identifiers for the given module names.'() {
+ when: 'execute a cm handle search for the given module names'
+ objectUnderTest.executeCmHandleHasAllModulesSearch(['some-module-name'])
+ then: 'get anchor identifiers is invoked with the expected parameters'
+ 1 * mockCpsAdminService.queryAnchorNames('NFP-Operational', ['some-module-name'])
+ }
+
+ def 'Update data node leaves.'() {
+ given: 'json data and xpath'
+ def jsonData = 'some json'
+ def xpath = '/xpath'
+ when: 'update node leaves is invoked'
+ objectUnderTest.updateNodeLeaves(cmHandle, xpath, jsonData)
+ then: 'the persistence service is called once with the correct parameters'
+ 1 * mockCpsDataService.updateNodeLeaves(expectedDataspaceName, cmHandle, xpath, jsonData, noTimestamp)
+ }
+
+ def 'Replace data node tree.'() {
+ given: 'json data and xpath'
+ def jsonData = 'some json'
+ def xpath = '/xpath'
+ when: 'replace node tree is invoked'
+ objectUnderTest.replaceNodeTree(cmHandle, xpath, jsonData)
+ then: 'the persistence service is called once with the correct parameters'
+ 1 * mockCpsDataService.replaceNodeTree(expectedDataspaceName, cmHandle, xpath, jsonData, noTimestamp)
+ }
+
+ def 'Update 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', UPDATE,
+ '{some-json}', 'application/json')
+ then: 'dmi called with correct data'
+ 1 * mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi('testCmHandle', 'testResourceId',
+ UPDATE, '{some-json}', 'application/json')
+ >> { new ResponseEntity<>(HttpStatus.OK) }
+ where:
+ scenario | includeCmHandleProperties || expectedJsonForCmhandleProperties
+ 'with' | true || '{"testName":"testValue"}'
+ 'without' | false || '{}'
+ }
+
+ def 'Verify error message from handleResponse is correct for #scenario operation.'() {
+ given: 'writeResourceDataPassThroughRunningFromDmi fails to return OK HttpStatus'
+ mockDmiDataOperations.writeResourceDataPassThroughRunningFromDmi(*_)
+ >> new ResponseEntity<>(HttpStatus.NOT_FOUND)
+ when: 'get resource data is called'
+ def response = objectUnderTest.writeResourceDataPassThroughRunningForCmHandle(
+ 'testCmHandle',
+ 'testResourceId',
+ givenOperation,
+ '{some-json}',
+ 'application/json')
+ then: 'an exception is thrown with the expected error message detailsd with correct operation'
+ def exceptionThrown = thrown(NcmpException.class)
+ exceptionThrown.getMessage().contains(expectedResponseMessage)
+ where:
+ scenario | givenOperation || expectedResponseMessage
+ 'CREATE' | CREATE || 'Not able to create resource data.'
+ 'READ' | READ || 'Not able to read resource data.'
+ 'UPDATE' | UPDATE || 'Not able to update resource data.'
+ }
+
+ def 'Query data nodes by cps path with #fetchDescendantsOption.'() {
+ given: 'a cps path'
+ def cpsPath = '/cps-path'
+ when: 'query data nodes is invoked'
+ objectUnderTest.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption)
+ then: 'the persistence query service is called once with the correct parameters'
+ 1 * mockCpsQueryService.queryDataNodes(expectedDataspaceName, cmHandle, cpsPath, fetchDescendantsOption)
+ where: 'all fetch descendants options are supported'
+ fetchDescendantsOption << FetchDescendantsOption.values()
+ }
+
+ def getDataNode(boolean includeCmHandleProperties) {
+ def dataNode = new DataNode()
+ dataNode.leaves = ['dmi-service-name': 'testDmiService']
+ if (includeCmHandleProperties) {
+ def cmHandlePropertyDataNode = new DataNode()
+ cmHandlePropertyDataNode.leaves = ['name': 'testName', 'value': 'testValue']
+ dataNode.childDataNodes = [cmHandlePropertyDataNode]
+ }
+ return dataNode