2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Bell Canada
4 * Modifications Copyright (C) 2021-2022 Nordix Foundation
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.rest.controller
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.onap.cps.TestUtils
25 import org.onap.cps.ncmp.api.NetworkCmProxyDataService
26 import org.onap.cps.ncmp.api.models.CmHandle
27 import org.onap.cps.ncmp.api.models.DmiPluginRegistration
28 import org.spockframework.spring.SpringBean
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.beans.factory.annotation.Value
31 import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
32 import org.springframework.context.annotation.Import
33 import org.springframework.http.HttpStatus
34 import org.springframework.http.MediaType
35 import org.springframework.test.web.servlet.MockMvc
36 import spock.lang.Specification
37 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
39 @WebMvcTest(NetworkCmProxyInventoryController)
41 class NetworkCmProxyInventoryControllerSpec extends Specification {
47 NetworkCmProxyDataService mockNetworkCmProxyDataService = Mock()
49 @Value('${rest.api.ncmp-inventory-base-path}/v1')
52 def 'Register CM Handle Event' () {
54 def jsonData = TestUtils.getResourceFileContent('dmi-registration.json')
55 when: 'post request is performed'
56 def response = mvc.perform(
57 post("$ncmpBasePathV1/ch")
58 .contentType(MediaType.APPLICATION_JSON)
60 ).andReturn().response
61 then: 'the cm handles are registered with the service'
62 1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(_)
63 and: 'response status is created'
64 response.status == HttpStatus.CREATED.value()
67 def 'Dmi plugin registration with #scenario' () {
68 given: 'jsonData, cmHandle, & DmiPluginRegistration'
69 def jsonData = TestUtils.getResourceFileContent('dmi_registration_combined_valid.json' )
70 def cmHandle = new CmHandle(cmHandleID : 'example-name')
71 def expectedDmiPluginRegistration = new DmiPluginRegistration(
72 dmiPlugin: 'service1',
75 createdCmHandles: [cmHandle])
76 when: 'post request is performed & registration is called with correct DMI plugin information'
77 def response = mvc.perform(
78 post("$ncmpBasePathV1/ch")
79 .contentType(MediaType.APPLICATION_JSON)
81 ).andReturn().response
82 then: 'no NcmpException is thrown & updateDmiRegistrationAndSyncModule is called with correct parameters'
83 1 * mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule({
84 it.getDmiPlugin() == expectedDmiPluginRegistration.getDmiPlugin()
85 it.getDmiDataPlugin() == expectedDmiPluginRegistration.getDmiDataPlugin()
86 it.getDmiModelPlugin() == expectedDmiPluginRegistration.getDmiModelPlugin()
87 it.getCreatedCmHandles().get(0).getCmHandleID() == expectedDmiPluginRegistration.getCreatedCmHandles().get(0).getCmHandleID()