aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/application
diff options
context:
space:
mode:
Diffstat (limited to 'ms/blueprintsprocessor/application')
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt11
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt83
2 files changed, 76 insertions, 18 deletions
diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt
index d5bf3f4c6..f2036fee9 100644
--- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatDefinition.kt
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.module.kotlin.convertValue
+import org.onap.ccsdk.cds.blueprintsprocessor.uat.utils.RequestType.EXCHANGE_RESOURCE
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.nodes.Tag
@@ -41,11 +42,17 @@ data class ProcessDefinition(
data class RequestDefinition(
val method: String,
@JsonDeserialize(using = PathDeserializer::class)
- val path: String,
+ val path: String = "",
val headers: Map<String, String> = emptyMap(),
- val body: JsonNode? = null
+ val body: JsonNode? = null,
+ val requestType: RequestType = EXCHANGE_RESOURCE
)
+enum class RequestType {
+ EXCHANGE_RESOURCE,
+ UPLOAD_BINARY_FILE
+}
+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
data class ResponseDefinition(
val status: Int = 200,
diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
index 45677fac1..357154cb1 100644
--- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
@@ -52,14 +52,18 @@ import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientSer
import org.onap.ccsdk.cds.blueprintsprocessor.uat.logging.LogColor.COLOR_MOCKITO
import org.onap.ccsdk.cds.blueprintsprocessor.uat.logging.LogColor.markerOf
import org.onap.ccsdk.cds.blueprintsprocessor.uat.logging.MockInvocationLogger
+import org.onap.ccsdk.cds.blueprintsprocessor.uat.utils.RequestType.EXCHANGE_RESOURCE
+import org.onap.ccsdk.cds.blueprintsprocessor.uat.utils.RequestType.UPLOAD_BINARY_FILE
import org.skyscreamer.jsonassert.JSONAssert
import org.skyscreamer.jsonassert.JSONCompareMode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.core.env.ConfigurableEnvironment
+import org.springframework.http.HttpMethod
import org.springframework.http.MediaType
import org.springframework.stereotype.Component
import org.springframework.util.Base64Utils
+import java.nio.file.Path
import java.util.concurrent.ConcurrentHashMap
/**
@@ -151,12 +155,19 @@ open class UatExecutor(
for ((mockClient, expectations) in expectationsPerClient) {
expectations.forEach { expectation ->
val request = expectation.request
- verify(mockClient, evalVerificationMode(expectation.times)).exchangeResource(
- eq(request.method),
- eq(request.path),
- any(),
- argThat(RequiredMapEntriesMatcher(request.headers))
- )
+ if (request.requestType == EXCHANGE_RESOURCE) {
+ verify(mockClient, evalVerificationMode(expectation.times)).exchangeResource(
+ eq(request.method),
+ eq(request.path),
+ any(),
+ argThat(RequiredMapEntriesMatcher(request.headers))
+ )
+ } else if (request.requestType == UPLOAD_BINARY_FILE) {
+ verify(mockClient, evalVerificationMode(expectation.times)).uploadBinaryFile(
+ eq(request.path),
+ any()
+ )
+ }
}
// Don't mind the invocations to the overloaded exchangeResource(String, String, String)
verify(mockClient, atLeast(0)).exchangeResource(any(), any(), any())
@@ -198,16 +209,32 @@ open class UatExecutor(
restClient.exchangeResource(method, path, request, emptyMap())
}
for (expectation in restExpectations) {
- var stubbing = whenever(
- restClient.exchangeResource(
- eq(expectation.request.method),
- eq(expectation.request.path),
- argThat(JsonMatcher(expectation.request.body.toString())),
- any()
+ if (expectation.request.requestType == EXCHANGE_RESOURCE) {
+ var stubbing = whenever(
+ restClient.exchangeResource(
+ eq(expectation.request.method),
+ eq(expectation.request.path),
+ argThat(JsonMatcher(expectation.request.body.toString())),
+ any()
+ )
)
- )
- for (response in expectation.responses) {
- stubbing = stubbing.thenReturn(WebClientResponse(response.status, response.body.toString()))
+ for (response in expectation.responses) {
+ stubbing = stubbing.thenReturn(WebClientResponse(response.status, response.body.toString()))
+ }
+ }
+ }
+
+ for (expectation in restExpectations) {
+ if (expectation.request.requestType == UPLOAD_BINARY_FILE) {
+ var stubbing = whenever(
+ restClient.uploadBinaryFile(
+ eq(expectation.request.path),
+ any()
+ )
+ )
+ for (response in expectation.responses) {
+ stubbing = stubbing.thenReturn(WebClientResponse(response.status, response.body.toString()))
+ }
}
}
return restClient
@@ -361,7 +388,7 @@ open class UatExecutor(
headers: Map<String, String>
): WebClientResponse<String> {
val requestDefinition =
- RequestDefinition(methodType, path, headers, toJson(request))
+ RequestDefinition(methodType, path, headers, toJson(request), EXCHANGE_RESOURCE)
val realAnswer = realService.exchangeResource(methodType, path, request, headers)
val responseBody = when {
// TODO: confirm if we need to normalize the response here
@@ -379,6 +406,30 @@ open class UatExecutor(
return realAnswer
}
+ override fun uploadBinaryFile(path: String, filePath: Path):
+ WebClientResponse<String> {
+ val method = HttpMethod.POST.name
+ val headers = DEFAULT_HEADERS
+ val request = ""
+ val requestDefinition =
+ RequestDefinition(method, path, headers, toJson(request), UPLOAD_BINARY_FILE)
+ val realAnswer = realService.uploadBinaryFile(path, filePath)
+ val responseBody = when {
+ // TODO: confirm if we need to normalize the response here
+ realAnswer.status == HttpStatus.SC_OK -> toJson(realAnswer.body)
+ else -> null
+ }
+ val responseDefinition =
+ ResponseDefinition(realAnswer.status, responseBody)
+ expectations.add(
+ ExpectationDefinition(
+ requestDefinition,
+ responseDefinition
+ )
+ )
+ return realAnswer
+ }
+
override suspend fun <T> retry(times: Int, initialDelay: Long, delay: Long, block: suspend (Int) -> T): T {
return super.retry(times, initialDelay, delay, block)
}