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
9 * 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.integration.functional.ncmp
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.onap.cps.integration.base.CpsIntegrationSpecBase
25 import org.springframework.http.HttpHeaders
26 import org.springframework.http.MediaType
28 import static org.springframework.http.HttpMethod.POST
29 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.request
31 class PolicyExecutorIntegrationSpec extends CpsIntegrationSpecBase {
33 def objectMapper = new ObjectMapper()
36 // Enable mocked policy executor logic
37 policyDispatcher.allowAll = false;
38 //minimum setup for cm handles with alternate ids
39 dmiDispatcher1.moduleNamesPerCmHandleId = ['ch-1': [], 'ch-2': [], 'ch-3':[]]
40 registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, 'fdn1')
41 registerCmHandle(DMI1_URL, 'ch-2', NO_MODULE_SET_TAG, 'fdn2')
42 registerCmHandle(DMI1_URL, 'ch-3', NO_MODULE_SET_TAG, 'mock slow response')
46 deregisterSequenceOfCmHandles(DMI1_URL, 3, 1)
49 def 'Policy Executor create request with #scenario.'() {
50 when: 'a pass-through write request is sent to NCMP'
51 def response = mvc.perform(request(POST, "/ncmp/v1/ch/$cmHandle/data/ds/ncmp-datastore:passthrough-running")
52 .queryParam('resourceIdentifier', 'my-resource-id')
53 .contentType(MediaType.APPLICATION_JSON)
54 .content('{ "some-json": "data" }')
55 .header(HttpHeaders.AUTHORIZATION, authorization))
57 then: 'the expected status code is returned'
58 response.getStatus() == execpectedStatusCode
59 and: 'when not allowed the response body contains the expected message'
60 if (expectedMessage!='allow') {
61 def bodyAsMap = objectMapper.readValue(response.getContentAsByteArray(), Map.class)
62 assert bodyAsMap.get('message').endsWith(expectedMessage)
64 where: 'following parameters are used'
65 scenario | cmHandle | authorization || execpectedStatusCode || expectedMessage
66 'accepted cm handle' | 'ch-1' | 'mock expects "ABC"' || 201 || 'allow'
67 'un-accepted cm handle' | 'ch-2' | 'mock expects "ABC"' || 409 || 'deny from mock server (dispatcher)'
68 'timeout' | 'ch-3' | 'mock expects "ABC"' || 409 || 'test default decision'
69 'invalid authorization' | 'ch-1' | 'something else' || 409 || 'test default decision'