X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ms%2Fblueprintsprocessor%2Fapplication%2Fsrc%2Fmain%2Fkotlin%2Forg%2Fonap%2Fccsdk%2Fcds%2Fblueprintsprocessor%2Fuat%2Futils%2FUatExecutor.kt;fp=ms%2Fblueprintsprocessor%2Fapplication%2Fsrc%2Fmain%2Fkotlin%2Forg%2Fonap%2Fccsdk%2Fcds%2Fblueprintsprocessor%2Fuat%2Futils%2FUatExecutor.kt;h=357154cb10929f7298aebe5f484e51113dc19502;hb=97c07491d6dfb1fca6e4aeebaf7318324c1d3eb4;hp=45677fac163907531e993aafefc2adbb475e2a11;hpb=4d906e5210c570678bba6db82d85b16ff2ebaaf8;p=ccsdk%2Fcds.git 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 ): WebClientResponse { 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 { + 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 retry(times: Int, initialDelay: Long, delay: Long, block: suspend (Int) -> T): T { return super.retry(times, initialDelay, delay, block) }