Merge "Formatted and fixed errors in DOC"
authorDan Timoney <dtimoney@att.com>
Mon, 26 Aug 2019 17:35:13 +0000 (17:35 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 26 Aug 2019 17:35:13 +0000 (17:35 +0000)
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 ad4173c..dfa0a85 100644 (file)
@@ -35,6 +35,7 @@ import org.junit.ClassRule
 import org.junit.Rule
 import org.junit.runner.RunWith
 import org.junit.runners.Parameterized
+import org.mockito.Answers
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestLibConstants
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
@@ -105,7 +106,7 @@ class BlueprintsAcceptanceTest(private val blueprintName: String, private val fi
     @JvmField
     val springMethodRule = SpringMethodRule()
 
-    @MockBean(name = RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+    @MockBean(name = RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY, answer = Answers.RETURNS_SMART_NULLS)
     lateinit var restClientFactory: BluePrintRestLibPropertyService
 
     @Autowired
@@ -130,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
@@ -143,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())
@@ -160,7 +161,8 @@ class BlueprintsAcceptanceTest(private val blueprintName: String, private val fi
 
     private fun createRestClientMock(selector: String, restExpectations: List<ExpectationDefinition>)
             : BlueprintWebClientService {
-        val restClient = mock<BlueprintWebClientService>(verboseLogging = true)
+        val restClient = mock<BlueprintWebClientService>(verboseLogging = true,
+                defaultAnswer = Answers.RETURNS_SMART_NULLS)
 
         // Delegates to overloaded exchangeResource(String, String, String, Map<String, String>)
         whenever(restClient.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 {