- 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
- request:
method: PATCH
path: [*configUri, *configletResourcePath]
- content-type: application/yang.patch+json
+ headers:
+ Content-Type: application/yang.patch+json
body: *assignPatch
- request:
method: DELETE
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
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())
--- /dev/null
+/*-
+ * ============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()
+ }
+}
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
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 {