From c3ebcdbdf11ecd70778ee7efa63b6221579d1d51 Mon Sep 17 00:00:00 2001 From: ebo Date: Sat, 24 Aug 2019 11:37:59 +0000 Subject: UAT: fix validation of request headers Change-Id: I9725be21b421f2890cce2ef76bbe5c371ab5b46e Issue-ID: CCSDK-1639 Signed-off-by: ebo --- .../uat-blueprints/pnf_config/Tests/uat.yaml | 6 ++-- .../BlueprintsAcceptanceTest.kt | 20 ++++++------- .../ccsdk/cds/blueprintsprocessor/MoreMatchers.kt | 34 ++++++++++++++++++++++ .../ccsdk/cds/blueprintsprocessor/UatDefinition.kt | 11 ++----- 4 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/MoreMatchers.kt diff --git a/components/model-catalog/blueprint-model/uat-blueprints/pnf_config/Tests/uat.yaml b/components/model-catalog/blueprint-model/uat-blueprints/pnf_config/Tests/uat.yaml index 789659eb2..3a5903c49 100644 --- a/components/model-catalog/blueprint-model/uat-blueprints/pnf_config/Tests/uat.yaml +++ b/components/model-catalog/blueprint-model/uat-blueprints/pnf_config/Tests/uat.yaml @@ -96,7 +96,8 @@ external-services: - request: method: PUT path: &configUri [ restconf/config, &nodeIdentifier [network-topology:network-topology/topology/topology-netconf/node, *pnfId]] - content-type: application/json + headers: + Content-Type: application/json body: node: - node-id: *pnfId @@ -124,7 +125,8 @@ external-services: - request: method: PATCH path: [*configUri, *configletResourcePath] - content-type: application/yang.patch+json + headers: + Content-Type: application/yang.patch+json body: *assignPatch - request: method: DELETE diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintsAcceptanceTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintsAcceptanceTest.kt index adb6de101..dfa0a8563 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintsAcceptanceTest.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintsAcceptanceTest.kt @@ -131,10 +131,10 @@ class BlueprintsAcceptanceTest(private val blueprintName: String, private val fi uploadBlueprint(blueprintName) - // Configure mocked external services - val expectationPerClient = uat.externalServices.associateBy( + // Configure mocked external services and save their expected requests for further validation + val requestsPerClient = uat.externalServices.associateBy( { service -> createRestClientMock(service.selector, service.expectations) }, - { service -> service.expectations } + { service -> service.expectations.map { it.request } } ) // Run processes @@ -144,14 +144,14 @@ class BlueprintsAcceptanceTest(private val blueprintName: String, private val fi JsonNormalizer.getNormalizer(mapper, process.responseNormalizerSpec)) } - // Validate request payloads to external services - for ((mockClient, expectations) in expectationPerClient) { - expectations.forEach { expectation -> + // Validate requests to external services + for ((mockClient, requests) in requestsPerClient) { + requests.forEach { request -> verify(mockClient, atLeastOnce()).exchangeResource( - eq(expectation.request.method), - eq(expectation.request.path), - argThat { assertJsonEqual(expectation.request.body, this) }, - expectation.request.requestHeadersMatcher()) + eq(request.method), + eq(request.path), + argThat { assertJsonEqual(request.body, this) }, + argThat(RequiredMapEntriesMatcher(request.headers))) } // Don't mind the invocations to the overloaded exchangeResource(String, String, String) verify(mockClient, atLeast(0)).exchangeResource(any(), any(), any()) diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/MoreMatchers.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/MoreMatchers.kt new file mode 100644 index 000000000..71e07ab4c --- /dev/null +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/MoreMatchers.kt @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.ccsdk.cds.blueprintsprocessor + +import com.google.common.collect.Maps +import org.mockito.ArgumentMatcher + +class RequiredMapEntriesMatcher(private val requiredEntries: Map) : ArgumentMatcher> { + override fun matches(argument: Map?): Boolean { + val missingEntries = Maps.difference(requiredEntries, argument).entriesOnlyOnLeft() + return missingEntries.isEmpty() + } + + override fun toString(): String { + return requiredEntries.toString() + } +} diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/UatDefinition.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/UatDefinition.kt index ce2061168..abb1dfcd1 100644 --- a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/UatDefinition.kt +++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/UatDefinition.kt @@ -24,8 +24,6 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.node.MissingNode -import com.nhaarman.mockitokotlin2.any -import com.nhaarman.mockitokotlin2.eq import org.yaml.snakeyaml.Yaml import java.nio.file.Path @@ -35,13 +33,8 @@ data class ProcessDefinition(val name: String, val request: JsonNode, val expect data class RequestDefinition(val method: String, @JsonDeserialize(using = PathDeserializer::class) val path: String, - @JsonAlias("content-type") - val contentType: String? = null, - val body: JsonNode = MissingNode.getInstance()) { - fun requestHeadersMatcher(): Map { - return if (contentType != null) eq(mapOf("Content-Type" to contentType)) else any() - } -} + val headers: Map = emptyMap(), + val body: JsonNode = MissingNode.getInstance()) data class ResponseDefinition(val status: Int = 200, val body: JsonNode = MissingNode.getInstance()) { companion object { -- cgit 1.2.3-korg