UAT: fix validation of request headers 48/94248/2
authorebo <eliezio.oliveira@est.tech>
Sat, 24 Aug 2019 11:37:59 +0000 (11:37 +0000)
committerebo <eliezio.oliveira@est.tech>
Sat, 24 Aug 2019 11:37:59 +0000 (11:37 +0000)
Change-Id: I9725be21b421f2890cce2ef76bbe5c371ab5b46e
Issue-ID: CCSDK-1639
Signed-off-by: ebo <eliezio.oliveira@est.tech>
components/model-catalog/blueprint-model/uat-blueprints/pnf_config/Tests/uat.yaml
ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintsAcceptanceTest.kt
ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/MoreMatchers.kt [new file with mode: 0644]
ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/UatDefinition.kt

index 789659e..3a5903c 100644 (file)
@@ -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
index adb6de1..dfa0a85 100644 (file)
@@ -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 (file)
index 0000000..71e07ab
--- /dev/null
@@ -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<K, V>(private val requiredEntries: Map<K, V>) : ArgumentMatcher<Map<K, V>> {
+    override fun matches(argument: Map<K, V>?): Boolean {
+        val missingEntries = Maps.difference(requiredEntries, argument).entriesOnlyOnLeft()
+        return missingEntries.isEmpty()
+    }
+
+    override fun toString(): String {
+        return requiredEntries.toString()
+    }
+}
index ce20611..abb1dfc 100644 (file)
@@ -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<String, String> {
-        return if (contentType != null) eq(mapOf("Content-Type" to contentType)) else any()
-    }
-}
+                             val headers: Map<String, String> = emptyMap(),
+                             val body: JsonNode = MissingNode.getInstance())
 
 data class ResponseDefinition(val status: Int = 200, val body: JsonNode = MissingNode.getInstance()) {
     companion object {