698ff1ac76b4a24d92314e325d90e9b354b32a5c
[cps.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
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  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.integration.functional.ncmp.provmns
22
23 import org.onap.cps.integration.base.CpsIntegrationSpecBase
24 import org.onap.cps.ncmp.impl.provmns.model.PatchItem
25 import org.onap.cps.ncmp.impl.provmns.model.ResourceOneOf
26 import org.springframework.http.MediaType
27
28 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
29 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
30 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch
31 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
32 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
33
34 @SuppressWarnings('SpellCheckingInspection')
35 class ProvMnSRestApiSpec extends CpsIntegrationSpecBase{
36
37     def 'Get Resource Data from provmns interface.'() {
38         given: 'a registered cm handle'
39             dmiDispatcher1.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2']
40             registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, '/A=1/B=2/C=3')
41         expect: 'not implemented response on GET endpoint'
42             mvc.perform(get("/ProvMnS/v1/A=1/B=2/C=3"))
43                     .andExpect(status().is2xxSuccessful())
44         cleanup: 'deregister CM handles'
45             deregisterCmHandle(DMI1_URL, 'ch-1')
46     }
47
48     def 'Put Resource Data from provmns interface.'() {
49         given: 'an example resource json body'
50             dmiDispatcher1.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2']
51             registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, '/A=1/B=2/C=3')
52             def jsonBody = jsonObjectMapper.asJsonString(new ResourceOneOf('test'))
53         expect: 'not implemented response on PUT endpoint'
54             mvc.perform(put("/ProvMnS/v1/A=1/B=2/C=3")
55                     .contentType(MediaType.APPLICATION_JSON)
56                     .content(jsonBody))
57                     .andExpect(status().isOk())
58         cleanup: 'deregister CM handles'
59             deregisterCmHandle(DMI1_URL, 'ch-1')
60     }
61
62     def 'Patch Resource Data from provmns interface.'() {
63         given: 'an example resource json body'
64             dmiDispatcher1.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2']
65             registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, '/A=1/B=2/C=3')
66             def jsonBody = jsonObjectMapper.asJsonString([new PatchItem(op: 'REMOVE', path: 'someUriLdnFirstPart')])
67         expect: 'not implemented response on PATCH endpoint'
68             mvc.perform(patch("/ProvMnS/v1/A=1/B=2/C=3")
69                     .contentType(new MediaType('application', 'json-patch+json'))
70                     .content(jsonBody))
71                     .andExpect(status().isOk())
72         cleanup: 'deregister CM handles'
73             deregisterCmHandle(DMI1_URL, 'ch-1')
74     }
75
76     def 'Delete Resource Data from provmns interface.'() {
77         given: 'a registered cm handle'
78             dmiDispatcher1.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2']
79             registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, '/A=1/B=2/C=3')
80         expect: 'ok response on DELETE endpoint'
81             mvc.perform(delete("/ProvMnS/v1/A=1/B=2/C=3")).andExpect(status().isOk())
82         cleanup: 'deregister CM handles'
83             deregisterCmHandle(DMI1_URL, 'ch-1')
84     }
85 }