- @Value('${rest.api.ncmp-base-path}/v1')
- def ncmpBasePathV1
-
- def cmHandle = 'some handle'
- def xpath = 'some xpath'
-
- def 'Query data node by cps path for the given cm handle with #scenario.'() {
- given: 'service method returns a list containing a data node'
- def dataNode = new DataNodeBuilder().withXpath('/xpath').build()
- def cpsPath = 'some cps-path'
- mockNetworkCmProxyDataService.queryDataNodes(cmHandle, cpsPath, expectedCpsDataServiceOption) >> [dataNode]
- and: 'the query endpoint'
- def dataNodeEndpoint = "$ncmpBasePathV1/cm-handles/$cmHandle/nodes/query"
- when: 'query data nodes API is invoked'
- def response = mvc.perform(get(dataNodeEndpoint)
- .param('cps-path', cpsPath)
- .param('include-descendants', includeDescendantsOption))
- .andReturn().response
- then: 'the response contains the the datanode in json format'
- response.status == HttpStatus.OK.value()
- def expectedJsonContent = new Gson().toJson(dataNode)
- response.getContentAsString().contains(expectedJsonContent)
- where: 'the following options for include descendants are provided in the request'
- scenario | includeDescendantsOption || expectedCpsDataServiceOption
- 'no descendants by default' | '' || OMIT_DESCENDANTS
- 'no descendant explicitly' | 'false' || OMIT_DESCENDANTS
- 'descendants' | 'true' || INCLUDE_ALL_DESCENDANTS
- }
-
- def 'Create data node: #scenario.'() {
- given: 'json data'
- def jsonData = 'json data'
- when: 'post request is performed'
- def response = mvc.perform(
- post("$ncmpBasePathV1/cm-handles/$cmHandle/nodes")
- .contentType(MediaType.APPLICATION_JSON)
- .content(jsonData)
- .param('xpath', reqXpath)
- ).andReturn().response
- then: 'the service method is invoked once with expected parameters'
- 1 * mockNetworkCmProxyDataService.createDataNode(cmHandle, usedXpath, jsonData)
- and: 'response status indicates success'
- response.status == HttpStatus.CREATED.value()
- where: 'following parameters were used'
- scenario | reqXpath || usedXpath
- 'no xpath parameter' | '' || '/'
- 'root xpath' | '/' || '/'
- 'parent node xpath' | '/xpath' || '/xpath'
- }
-
- def 'Add list-node elements.'() {
- given: 'json data and parent node xpath'
- def jsonData = 'json data'
- def parentNodeXpath = 'parent node xpath'
- when: 'post request is performed'
- def response = mvc.perform(
- post("$ncmpBasePathV1/cm-handles/$cmHandle/list-node")
- .contentType(MediaType.APPLICATION_JSON)
- .content(jsonData)
- .param('xpath', parentNodeXpath)
- ).andReturn().response
- then: 'the service method is invoked once with expected parameters'
- 1 * mockNetworkCmProxyDataService.addListNodeElements(cmHandle, parentNodeXpath, jsonData)
- and: 'response status indicates success'
- response.status == HttpStatus.CREATED.value()
- }