2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Bell Canada
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.cps.ncmp.rest.controller
22 import com.fasterxml.jackson.databind.ObjectMapper
23 import org.onap.cps.TestUtils
24 import org.onap.cps.ncmp.api.NetworkCmProxyDataService
25 import org.spockframework.spring.SpringBean
26 import org.springframework.beans.factory.annotation.Autowired
27 import org.springframework.beans.factory.annotation.Value
28 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
29 import org.springframework.context.annotation.Import
30 import org.springframework.http.HttpStatus
31 import org.springframework.http.MediaType
32 import org.springframework.test.web.servlet.MockMvc
33 import spock.lang.Specification
34 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
36 @WebMvcTest(NetworkCmProxyInventoryController)
38 class NetworkCmProxyInventoryControllerSpec extends Specification {
44 NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
46 @Value('${rest.api.ncmp-inventory-base-path}/v1')
49 def 'Register CM Handle Event' () {
51 def jsonData = TestUtils.getResourceFileContent('dmi-registration.json')
52 when: 'post request is performed'
53 def response = mvc.perform(
54 post("$ncmpBasePathV1/ch")
55 .contentType(MediaType.APPLICATION_JSON)
57 ).andReturn().response
58 then: 'the cm handles are registered with the service'
59 1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(_)
60 and: 'response status is created'
61 response.status == HttpStatus.CREATED.value()