4e9b809eff55b1635c9ec4fd764efe849fcd2d3e
[cps.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 Nordix Foundation
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
22
23 import org.onap.cps.integration.base.CpsIntegrationSpecBase
24 import org.springframework.http.MediaType
25
26 import static org.springframework.http.HttpMethod.DELETE
27 import static org.springframework.http.HttpMethod.GET
28 import static org.springframework.http.HttpMethod.PATCH
29 import static org.springframework.http.HttpMethod.POST
30 import static org.springframework.http.HttpMethod.PUT
31 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request
32 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
33
34 class DmiUrlEncodingPassthroughSpec extends CpsIntegrationSpecBase {
35
36     def setup() {
37         dmiDispatcher1.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2']
38         registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG)
39     }
40
41     def cleanup() {
42         deregisterCmHandle(DMI1_URL, 'ch-1')
43     }
44
45     def 'DMI URL encoding for pass-through operational data operations with GET request'() {
46         when: 'sending a GET pass-through data request to NCMP'
47             mvc.perform(request(GET, '/ncmp/v1/ch/ch-1/data/ds/ncmp-datastore:passthrough-operational')
48                     .queryParam('resourceIdentifier', 'parent/child')
49                     .queryParam('options', '(a=1,b=2)'))
50                     .andExpect(status().is2xxSuccessful())
51         then: 'verify that DMI received the request with the correctly encoded URL'
52             assert dmiDispatcher1.dmiResourceDataUrl == '/dmi/v1/ch/ch-1/data/ds/ncmp-datastore%3Apassthrough-operational?resourceIdentifier=parent%2Fchild&options=%28a%3D1%2Cb%3D2%29'
53     }
54
55     def 'DMI URL encoding for pass-through running data operations with POST request'() {
56         when: 'sending a pass-through data request to NCMP with various HTTP methods'
57             mvc.perform(request(POST, '/ncmp/v1/ch/ch-1/data/ds/ncmp-datastore:passthrough-running')
58                     .queryParam('resourceIdentifier', 'parent/child')
59                     .contentType(MediaType.APPLICATION_JSON)
60                     .content('{ "some-json": "data" }'))
61                     .andExpect(status().is2xxSuccessful())
62         then: 'verify that DMI received the request with the correctly encoded URL'
63             assert dmiDispatcher1.dmiResourceDataUrl == '/dmi/v1/ch/ch-1/data/ds/ncmp-datastore%3Apassthrough-running?resourceIdentifier=parent%2Fchild'
64     }
65 }