- def mockCpsQueryService = Mock(CpsQueryService)
- def mockDmiOperations = Mock(DmiOperations)
- def objectUnderTest = new NetworkCmProxyDataServiceImpl(mockDmiOperations, mockCpsDataService, mockCpsQueryService, new ObjectMapper())
-
- def cmHandle = 'some handle'
-
- def expectedDataspaceName = 'NFP-Operational'
- def 'Query data nodes by cps path with #fetchDescendantsOption.'() {
- given: 'a cm Handle and a cps path'
- def cpsPath = '/cps-path'
- when: 'queryDataNodes is invoked'
- objectUnderTest.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption)
- then: 'the persistence 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 'Create full data node: #scenario.'() {
- given: 'a cm handle and root xpath'
- def jsonData = 'some json'
- when: 'createDataNode is invoked'
- objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
- then: 'the CPS service method is invoked once with the expected parameters'
- 1 * mockCpsDataService.saveData(expectedDataspaceName, cmHandle, jsonData)
- where: 'following parameters were used'
- scenario | xpath
- 'no xpath' | ''
- 'root level xpath' | '/'
- }
- def 'Create child data node.'() {
- given: 'a cm handle and parent node xpath'
- def jsonData = 'some json'
- def xpath = '/test-node'
- when: 'createDataNode is invoked'
- objectUnderTest.createDataNode(cmHandle, xpath, jsonData)
- then: 'the CPS service method is invoked once with the expected parameters'
- 1 * mockCpsDataService.saveData(expectedDataspaceName, cmHandle, xpath, jsonData)
- }
- def 'Add list-node elements.'() {
- given: 'a cm handle and parent node xpath'
- def jsonData = 'some json'
- def xpath = '/test-node'
- when: 'addListNodeElements is invoked'
- objectUnderTest.addListNodeElements(cmHandle, xpath, jsonData)
- then: 'the CPS service method is invoked once with the expected parameters'
- 1 * mockCpsDataService.saveListNodeData(expectedDataspaceName, cmHandle, xpath, jsonData)
+ def mockCpsModuleService = Mock(CpsModuleService)
+ def mockCpsAdminService = Mock(CpsAdminService)
+ def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
+ def mockDmiModelOperations = Mock(DmiModelOperations)
+ def mockDmiDataOperations = Mock(DmiDataOperations)
+
+ def objectUnderTest = new NetworkCmProxyDataServiceImpl(mockCpsDataService, spiedJsonObjectMapper, mockDmiDataOperations, mockDmiModelOperations,
+ mockCpsModuleService, mockCpsAdminService)
+
+ def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
+
+ def dataNode = new DataNode(leaves: ['dmi-service-name': 'testDmiService'])
+
+
+ def 'Write resource data for pass-through running from DMI using POST #scenario cm handle properties.'() {
+ given: '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) }