e558ac45bfca9b42d9c6e3aaeb2b9c34bc5b4d35
[cps.git] / cps-ncmp-rest / src / test / groovy / org / onap / cps / ncmp / rest / controller / NetworkCmProxyInventoryControllerSpec.groovy
1 /*
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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.cps.ncmp.rest.controller
21
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
35
36 @WebMvcTest(NetworkCmProxyInventoryController)
37 @Import(ObjectMapper)
38 class NetworkCmProxyInventoryControllerSpec extends Specification {
39
40     @Autowired
41     MockMvc mvc
42
43     @SpringBean
44     NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
45
46     @Value('${rest.api.ncmp-inventory-base-path}/v1')
47     def ncmpBasePathV1
48
49     def 'Register CM Handle Event' () {
50         given: 'jsonData'
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)
56                 .content(jsonData)
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()
62     }
63
64 }
65