package org.onap.cps.ncmp.rest.controller
-import org.onap.cps.TestUtils
-import org.onap.cps.spi.model.ModuleReference
+import org.mapstruct.factory.Mappers
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE
+import com.fasterxml.jackson.databind.ObjectMapper
+import org.onap.cps.TestUtils
+import org.onap.cps.spi.model.ModuleReference
+import org.onap.cps.utils.JsonObjectMapper
import org.onap.cps.ncmp.api.NetworkCmProxyDataService
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
@SpringBean
NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
+ @SpringBean
+ JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
+
+ @SpringBean
+ NcmpRestInputMapper ncmpRestInputMapper = Mappers.getMapper(NcmpRestInputMapper)
+
@Value('${rest.api.ncmp-base-path}/v1')
def ncmpBasePathV1
- def jsonString = '{"some-key":"some-value"}'
+ def requestBody = '{"some-key":"some-value"}'
def 'Get Resource Data from pass-through operational.' () {
given: 'resource data url'
def response = mvc.perform(
put(updateUrl)
.contentType(MediaType.APPLICATION_JSON_VALUE)
- .accept(MediaType.APPLICATION_JSON_VALUE).content(jsonString)
+ .accept(MediaType.APPLICATION_JSON_VALUE).content(requestBody)
).andReturn().response
then: 'ncmp service method to update resource is called'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', UPDATE, jsonString, 'application/json;charset=UTF-8')
+ 'parent/child', UPDATE, requestBody, 'application/json;charset=UTF-8')
and: 'the response status is OK'
response.status == HttpStatus.OK.value()
}
response.contentAsString == '{"cmHandles":[{"cmHandleId":"some-cmhandle-id1"},{"cmHandleId":"some-cmhandle-id2"}]}'
}
+ def 'Get Cm Handle details by Cm Handle id.' () {
+ given: 'an endpoint and a cm handle'
+ def cmHandleDetailsEndpoint = "$ncmpBasePathV1/ch/Some-Cm-Handle"
+ and: 'an existing ncmp service cm handle'
+ def cmHandleId = 'Some-Cm-Handle'
+ def dmiProperties = [ prop:'some DMI property' ]
+ def publicProperties = [ "public prop":'some public property' ]
+ def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleID: cmHandleId, dmiProperties: dmiProperties, publicProperties: publicProperties)
+ and: 'the service method is invoked with the cm handle id'
+ 1 * mockNetworkCmProxyDataService.getNcmpServiceCmHandle('Some-Cm-Handle') >> ncmpServiceCmHandle
+ when: 'the cm handle details api is invoked'
+ def response = mvc.perform(get(cmHandleDetailsEndpoint)).andReturn().response
+ then: 'the correct response is returned'
+ response.status == HttpStatus.OK.value()
+ and: 'the response returns public properties and the correct properties'
+ response.contentAsString.contains('publicCmHandleProperties')
+ response.contentAsString.contains('public prop')
+ response.contentAsString.contains('some public property')
+ and: 'the content does not contain dmi properties'
+ !response.contentAsString.contains("some DMI property")
+ }
+
def 'Call execute cm handle searches with unrecognized condition name.'() {
given: 'an endpoint and json data'
def searchesEndpoint = "$ncmpBasePathV1/ch/searches"
def response = mvc.perform(
patch(url)
.contentType(MediaType.APPLICATION_JSON)
- .accept(MediaType.APPLICATION_JSON).content(jsonString)
+ .accept(MediaType.APPLICATION_JSON).content(requestBody)
).andReturn().response
then: 'ncmp service method to update resource is called'
1 * mockNetworkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle('testCmHandle',
- 'parent/child', PATCH, jsonString, 'application/json;charset=UTF-8')
+ 'parent/child', PATCH, requestBody, 'application/json;charset=UTF-8')
and: 'the response status is OK'
response.status == HttpStatus.OK.value()
}