summaryrefslogtreecommitdiffstats
path: root/integration-test
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2024-09-19 17:23:58 +0100
committerToine Siebelink <toine.siebelink@est.tech>2024-09-25 08:18:46 +0000
commit2bcccff7e2891f708cedc08cdbf969025d63019e (patch)
treec0300990499012dd7b87d62d3f5c4cc78d068e41 /integration-test
parent39e4eef51e44b73569fe82e214afab04edc5bba0 (diff)
Policy Executor: handle errors
- configurable default answer - apply default answer upon non 2xx response - delayed default webclient read timeout - add custom timeout method with original read timeout in seconds - apply default answer upon timeout - add integration test with short timeout error scenario Issue-ID: CPS-2412 Change-Id: I62527a27e426c2f01fda2182ebd2513242c29ac1 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Diffstat (limited to 'integration-test')
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/base/PolicyDispatcher.groovy7
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/PolicyExecutorIntegrationSpec.groovy23
-rw-r--r--integration-test/src/test/resources/application.yml3
3 files changed, 25 insertions, 8 deletions
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/PolicyDispatcher.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/PolicyDispatcher.groovy
index 69792d7ed8..c93a5274e6 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/base/PolicyDispatcher.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/PolicyDispatcher.groovy
@@ -24,10 +24,12 @@ package org.onap.cps.integration.base
import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest
+import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper
+import java.util.concurrent.TimeUnit
/**
* This class simulates responses from the Policy Execution server in NCMP integration tests.
@@ -53,11 +55,14 @@ class PolicyDispatcher extends Dispatcher {
def targetIdentifier = body.get('requests').get(0).get('data').get('targetIdentifier')
def responseAsMap = [:]
responseAsMap.put('decisionId',1)
+ if (targetIdentifier == "mock slow response") {
+ TimeUnit.SECONDS.sleep(2) // One second more then configured readTimeoutInSeconds
+ }
if (allowAll || targetIdentifier == 'fdn1') {
responseAsMap.put('decision','allow')
responseAsMap.put('message','')
} else {
- responseAsMap.put('decision','deny')
+ responseAsMap.put('decision','deny from mock server (dispatcher)')
responseAsMap.put('message','I only like fdn1')
}
def responseAsString = objectMapper.writeValueAsString(responseAsMap)
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/PolicyExecutorIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/PolicyExecutorIntegrationSpec.groovy
index 99f245ae8c..1d4d19bee0 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/PolicyExecutorIntegrationSpec.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/ncmp/PolicyExecutorIntegrationSpec.groovy
@@ -20,6 +20,7 @@
package org.onap.cps.integration.functional.ncmp
+import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.integration.base.CpsIntegrationSpecBase
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
@@ -29,18 +30,22 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
class PolicyExecutorIntegrationSpec extends CpsIntegrationSpecBase {
+ def objectMapper = new ObjectMapper()
+
def setup() {
// Enable mocked policy executor logic
policyDispatcher.allowAll = false;
- //minimum setup for 2 cm handles with alternate ids
- dmiDispatcher1.moduleNamesPerCmHandleId = ['ch-1': [], 'ch-2': []]
+ //minimum setup for cm handles with alternate ids
+ dmiDispatcher1.moduleNamesPerCmHandleId = ['ch-1': [], 'ch-2': [], 'ch-3':[]]
registerCmHandle(DMI1_URL, 'ch-1', NO_MODULE_SET_TAG, 'fdn1')
registerCmHandle(DMI1_URL, 'ch-2', NO_MODULE_SET_TAG, 'fdn2')
+ registerCmHandle(DMI1_URL, 'ch-3', NO_MODULE_SET_TAG, 'mock slow response')
}
def cleanup() {
deregisterCmHandle(DMI1_URL, 'ch-1')
deregisterCmHandle(DMI1_URL, 'ch-2')
+ deregisterCmHandle(DMI1_URL, 'ch-3')
}
def 'Policy Executor create request with #scenario.'() {
@@ -53,11 +58,17 @@ class PolicyExecutorIntegrationSpec extends CpsIntegrationSpecBase {
.andReturn().response
then: 'the expected status code is returned'
response.getStatus() == execpectedStatusCode
+ and: 'when not allowed the response body contains the expected message'
+ if (expectedMessage!='allow') {
+ def bodyAsMap = objectMapper.readValue(response.getContentAsByteArray(), Map.class)
+ assert bodyAsMap.get('message').endsWith(expectedMessage)
+ }
where: 'following parameters are used'
- scenario | cmHandle | authorization || execpectedStatusCode
- 'accepted cm handle' | 'ch-1' | 'mock expects "ABC"' || 201
- 'un-accepted cm handle' | 'ch-2' | 'mock expects "ABC"' || 409
- 'invalid authorization' | 'ch-1' | 'something else' || 500
+ scenario | cmHandle | authorization || execpectedStatusCode || expectedMessage
+ 'accepted cm handle' | 'ch-1' | 'mock expects "ABC"' || 201 || 'allow'
+ 'un-accepted cm handle' | 'ch-2' | 'mock expects "ABC"' || 409 || 'deny from mock server (dispatcher)'
+ 'timeout' | 'ch-3' | 'mock expects "ABC"' || 409 || 'test default decision'
+ 'invalid authorization' | 'ch-1' | 'something else' || 500 || '401 Unauthorized from POST http://localhost:8790/policy-executor/api/v1/execute'
}
}
diff --git a/integration-test/src/test/resources/application.yml b/integration-test/src/test/resources/application.yml
index 760dad01af..793acc6395 100644
--- a/integration-test/src/test/resources/application.yml
+++ b/integration-test/src/test/resources/application.yml
@@ -215,6 +215,7 @@ ncmp:
policy-executor:
enabled: true
+ defaultDecision: "test default decision"
server:
address: http://localhost
port: 8790
@@ -224,7 +225,7 @@ ncmp:
maximumConnectionsTotal: 10
pendingAcquireMaxCount: 10
connectionTimeoutInSeconds: 30
- readTimeoutInSeconds: 30
+ readTimeoutInSeconds: 1
writeTimeoutInSeconds: 30
hazelcast: