* Copyright (C) 2021 Pantheon.tech
* Modification Copyright (C) 2021 highstreet technologies GmbH
* Modification Copyright (C) 2021 Nordix Foundation
+ * Modification Copyright (C) 2021 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.springframework.test.web.servlet.MockMvc
import spock.lang.Specification
-@WebMvcTest
+@WebMvcTest(NetworkCmProxyController)
class NetworkCmProxyControllerSpec extends Specification {
@Autowired
@SpringBean
ObjectMapper objectMapper = new ObjectMapper()
- @Value('${rest.api.ncmp-base-path}')
- def basePath
-
- def deprecatedDataNodeBaseEndPoint
-
- def ncmpDmiEndpoint
-
- def setup() {
- deprecatedDataNodeBaseEndPoint = "$basePath/v1"
- ncmpDmiEndpoint = "$basePath/ncmp-dmi/v1"
- }
+ @Value('${rest.api.ncmp-base-path}/v1')
+ def ncmpBasePathV1
def cmHandle = 'some handle'
def xpath = 'some xpath'
def cpsPath = 'some cps-path'
mockNetworkCmProxyDataService.queryDataNodes(cmHandle, cpsPath, expectedCpsDataServiceOption) >> [dataNode]
and: 'the query endpoint'
- def dataNodeEndpoint = "$deprecatedDataNodeBaseEndPoint/cm-handles/$cmHandle/nodes/query"
+ 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)
def jsonData = 'json data'
when: 'post request is performed'
def response = mvc.perform(
- post("$deprecatedDataNodeBaseEndPoint/cm-handles/$cmHandle/nodes")
+ post("$ncmpBasePathV1/cm-handles/$cmHandle/nodes")
.contentType(MediaType.APPLICATION_JSON)
.content(jsonData)
.param('xpath', reqXpath)
def parentNodeXpath = 'parent node xpath'
when: 'post request is performed'
def response = mvc.perform(
- post("$deprecatedDataNodeBaseEndPoint/cm-handles/$cmHandle/list-node")
+ post("$ncmpBasePathV1/cm-handles/$cmHandle/list-node")
.contentType(MediaType.APPLICATION_JSON)
.content(jsonData)
.param('xpath', parentNodeXpath)
given: 'json data'
def jsonData = 'json data'
and: 'the query endpoint'
- def endpoint = "$deprecatedDataNodeBaseEndPoint/cm-handles/$cmHandle/nodes"
+ def endpoint = "$ncmpBasePathV1/cm-handles/$cmHandle/nodes"
when: 'patch request is performed'
def response = mvc.perform(
patch(endpoint)
given: 'json data'
def jsonData = 'json data'
and: 'the query endpoint'
- def endpoint = "$deprecatedDataNodeBaseEndPoint/cm-handles/$cmHandle/nodes"
+ def endpoint = "$ncmpBasePathV1/cm-handles/$cmHandle/nodes"
when: 'put request is performed'
def response = mvc.perform(
put(endpoint)
def dataNode = new DataNodeBuilder().withXpath(xpath).withLeaves(["leaf": "value"]).build()
mockNetworkCmProxyDataService.getDataNode(cmHandle, xpath, OMIT_DESCENDANTS) >> dataNode
and: 'the query endpoint'
- def endpoint = "$deprecatedDataNodeBaseEndPoint/cm-handles/$cmHandle/node"
+ def endpoint = "$ncmpBasePathV1/cm-handles/$cmHandle/node"
when: 'get request is performed through REST API'
def response = mvc.perform(get(endpoint).param('xpath', xpath)).andReturn().response
then: 'a success response is returned'
def jsonData = TestUtils.getResourceFileContent('dmi-registration.json')
when: 'post request is performed'
def response = mvc.perform(
- post("$ncmpDmiEndpoint/ch")
+ post("$ncmpBasePathV1/ch")
.contentType(MediaType.APPLICATION_JSON)
.content(jsonData)
).andReturn().response
def 'Get Resource Data from pass-through operational.' () {
given: 'resource data url'
- def getUrl = "$basePath/v1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-operational" +
+ def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-operational" +
"/testResourceIdentifier?fields=testFields&depth=5"
when: 'get data resource request is performed'
def response = mvc.perform(
def 'Get Resource Data from pass-through running.' () {
given: 'resource data url'
- def getUrl = "$basePath/v1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
+ def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
"/testResourceIdentifier?fields=testFields&depth=5"
and: 'ncmp service returns json object'
mockNetworkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
and: 'response contains valid object body'
response.getContentAsString() == '{valid-json}'
}
+
+ def 'Create Resource Data from pass-through running using POST.' () {
+ given: 'resource data url'
+ def getUrl = "$ncmpBasePathV1/ch/testCmHandle/data/ds/ncmp-datastore:passthrough-running" +
+ "/testResourceIdentifier"
+ when: 'get data resource request is performed'
+ def response = mvc.perform(
+ post(getUrl)
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE).content('{"some-json":"value"}')
+ ).andReturn().response
+ then: 'ncmp service method to create resource called'
+ 1 * mockNetworkCmProxyDataService.createResourceDataPassThroughRunningForCmHandle('testCmHandle',
+ 'testResourceIdentifier', ['some-json':'value'], 'application/json;charset=UTF-8')
+ and: 'resource is created'
+ response.status == HttpStatus.CREATED.value()
+ }
}