99f245ae8c8b4fb0e94aff7bc5f0ca1e0c3fe62f
[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.HttpHeaders
25 import org.springframework.http.MediaType
26
27 import static org.springframework.http.HttpMethod.POST
28 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request
29
30 class PolicyExecutorIntegrationSpec extends CpsIntegrationSpecBase {
31
32     def setup() {
33         // Enable mocked policy executor logic
34         policyDispatcher.allowAll = false;
35         //minimum setup for 2 cm handles with alternate ids
36         dmiDispatcher1.moduleNamesPerCmHandleId = ['ch-1': [], 'ch-2': []]
37         registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, 'fdn1')
38         registerCmHandle(DMI1_URL, 'ch-2', NO_MODULE_SET_TAG, 'fdn2')
39     }
40
41     def cleanup() {
42         deregisterCmHandle(DMI1_URL, 'ch-1')
43         deregisterCmHandle(DMI1_URL, 'ch-2')
44     }
45
46     def 'Policy Executor create request with #scenario.'() {
47         when: 'a pass-through write request is sent to NCMP'
48             def response = mvc.perform(request(POST, "/ncmp/v1/ch/$cmHandle/data/ds/ncmp-datastore:passthrough-running")
49                     .queryParam('resourceIdentifier', 'my-resource-id')
50                     .contentType(MediaType.APPLICATION_JSON)
51                     .content('{ "some-json": "data" }')
52                     .header(HttpHeaders.AUTHORIZATION, authorization))
53                     .andReturn().response
54         then: 'the expected status code is returned'
55             response.getStatus() == execpectedStatusCode
56         where: 'following parameters are used'
57             scenario                | cmHandle | authorization         || execpectedStatusCode
58             'accepted cm handle'    | 'ch-1'   | 'mock expects "ABC"'  || 201
59             'un-accepted cm handle' | 'ch-2'   | 'mock expects "ABC"'  || 409
60             'invalid authorization' | 'ch-1'   | 'something else'      || 500
61     }
62
63 }