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.onap.cps.ncmp.api.impl.NetworkCmProxyDataServiceImpl
26 import org.onap.cps.ncmp.api.models.CmHandle
27 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
28 import org.onap.cps.ncmp.api.models.PersistenceCmHandle
29 import org.spockframework.spring.SpringBean
30 import org.springframework.beans.factory.annotation.Autowired
31 import org.springframework.beans.factory.annotation.Value
32 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
33 import org.springframework.context.annotation.Import
34 import org.springframework.http.HttpStatus
35 import org.springframework.http.MediaType
36 import org.springframework.test.web.servlet.MockMvc
37 import spock.lang.Specification
38 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
40 @WebMvcTest(NetworkCmProxyInventoryController)
42 class NetworkCmProxyInventoryControllerSpec extends Specification {
48 NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
50 @Value('${rest.api.ncmp-inventory-base-path}/v1')
53 def 'Register CM Handle Event' () {
55 def jsonData = TestUtils.getResourceFileContent('dmi-registration.json')
56 when: 'post request is performed'
57 def response = mvc.perform(
58 post("$ncmpBasePathV1/ch")
59 .contentType(MediaType.APPLICATION_JSON)
61 ).andReturn().response
62 then: 'the cm handles are registered with the service'
63 1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(_)
64 and: 'response status is created'
65 response.status == HttpStatus.CREATED.value()
68 def 'Dmi plugin registration with #scenario' () {
69 given: 'jsonData, cmHandle, & DmiPluginRegistration'
70 def jsonData = TestUtils.getResourceFileContent('dmi_registration_combined_valid.json' )
71 def cmHandle = new CmHandle(cmHandleID : 'example-name')
72 def expectedDmiPluginRegistration = new DmiPluginRegistration(
73 dmiPlugin: 'service1',
76 createdCmHandles: [cmHandle])
77 when: 'post request is performed & registration is called with correct DMI plugin information'
78 def response = mvc.perform(
79 post("$ncmpBasePathV1/ch")
80 .contentType(MediaType.APPLICATION_JSON)
82 ).andReturn().response
83 then: 'no NcmpException is thrown & updateDmiRegistrationAndSyncModule is called with correct parameters'
84 1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule({
85 it.getDmiPlugin() == expectedDmiPluginRegistration.getDmiPlugin()
86 it.getDmiDataPlugin() == expectedDmiPluginRegistration.getDmiDataPlugin()
87 it.getDmiModelPlugin() == expectedDmiPluginRegistration.getDmiModelPlugin()
88 it.getCreatedCmHandles().get(0).getCmHandleID() == expectedDmiPluginRegistration.getCreatedCmHandles().get(0).getCmHandleID()