From 341db21b2ac0a14a1ed2b8bf7930914dda054bfe Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Fri, 22 Nov 2019 18:06:08 -0500 Subject: Formatting Code base with ktlint No Business logic change, just the code format. Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3 To format run: mvn process-sources -P format Issue-ID: CCSDK-1947 Signed-off-by: Singal, Kapil (ks220y) Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331 --- .../cds/blueprintsprocessor/BlueprintGRPCServer.kt | 22 ++-- .../cds/blueprintsprocessor/BlueprintHttpServer.kt | 2 +- .../ccsdk/cds/blueprintsprocessor/SwaggerConfig.kt | 31 +++--- .../ccsdk/cds/blueprintsprocessor/WebConfig.kt | 34 +++--- .../actuator/indicator/BluePrintCustomIndicator.kt | 6 +- .../security/AuthenticationManager.kt | 7 +- .../security/BasicAuthServerInterceptor.kt | 30 +++-- .../security/SecurityConfiguration.kt | 8 +- .../security/SecurityContextRepository.kt | 16 +-- .../cds/blueprintsprocessor/uat/JsonNormalizer.kt | 8 +- .../cds/blueprintsprocessor/uat/MoreMatchers.kt | 34 ------ .../blueprintsprocessor/uat/PathDeserializer.kt | 2 +- .../uat/RequiredMapEntriesMatcher.kt | 34 ++++++ .../cds/blueprintsprocessor/uat/UatDefinition.kt | 38 ++++--- .../cds/blueprintsprocessor/uat/UatExecutor.kt | 124 ++++++++++++--------- .../cds/blueprintsprocessor/uat/UatServices.kt | 8 +- .../blueprintsprocessor/uat/logging/ColorMarker.kt | 2 +- .../blueprintsprocessor/uat/logging/LogColor.kt | 2 +- .../uat/logging/SmartColorDiscriminator.kt | 8 +- 19 files changed, 228 insertions(+), 188 deletions(-) delete mode 100644 ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/MoreMatchers.kt create mode 100644 ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/RequiredMapEntriesMatcher.kt (limited to 'ms/blueprintsprocessor/application/src/main') diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintGRPCServer.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintGRPCServer.kt index 2d39eaa1f..bfde39aa0 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintGRPCServer.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintGRPCServer.kt @@ -30,10 +30,12 @@ import org.springframework.stereotype.Component @ConditionalOnProperty(name = ["blueprintsprocessor.grpcEnable"], havingValue = "true") @Component -open class BlueprintGRPCServer(private val bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler, - private val bluePrintManagementGRPCHandler: BluePrintManagementGRPCHandler, - private val authInterceptor: BasicAuthServerInterceptor) - : ApplicationListener { +open class BlueprintGRPCServer( + private val bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler, + private val bluePrintManagementGRPCHandler: BluePrintManagementGRPCHandler, + private val authInterceptor: BasicAuthServerInterceptor +) : + ApplicationListener { private val log = logger(BlueprintGRPCServer::class) @@ -44,12 +46,12 @@ open class BlueprintGRPCServer(private val bluePrintProcessingGRPCHandler: BlueP try { log.info("Starting Blueprint Processor GRPC Starting..") val server = ServerBuilder - .forPort(grpcPort!!) - .intercept(GrpcServerLoggingInterceptor()) - .intercept(authInterceptor) - .addService(bluePrintProcessingGRPCHandler) - .addService(bluePrintManagementGRPCHandler) - .build() + .forPort(grpcPort!!) + .intercept(GrpcServerLoggingInterceptor()) + .intercept(authInterceptor) + .addService(bluePrintProcessingGRPCHandler) + .addService(bluePrintManagementGRPCHandler) + .build() server.start() log.info("Blueprint Processor GRPC server started and ready to serve on port({})...", server.port) diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintHttpServer.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintHttpServer.kt index 4251fb5cb..f152e307f 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintHttpServer.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/BlueprintHttpServer.kt @@ -30,4 +30,4 @@ open class BlueprintHttpServer : WebServerFactoryCustomizer { try { @@ -32,6 +32,5 @@ open class AuthenticationManager(private val authenticationProvider: Authenticat } catch (e: AuthenticationException) { return Mono.error(e) } - } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/BasicAuthServerInterceptor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/BasicAuthServerInterceptor.kt index a0a4ae297..ab9ee29df 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/BasicAuthServerInterceptor.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/BasicAuthServerInterceptor.kt @@ -15,7 +15,11 @@ */ package org.onap.ccsdk.cds.blueprintsprocessor.security -import io.grpc.* +import io.grpc.Metadata +import io.grpc.ServerCall +import io.grpc.ServerCallHandler +import io.grpc.ServerInterceptor +import io.grpc.Status import org.onap.ccsdk.cds.controllerblueprints.core.logger import org.springframework.security.authentication.BadCredentialsException import org.springframework.security.authentication.UsernamePasswordAuthenticationToken @@ -23,23 +27,24 @@ import org.springframework.security.core.AuthenticationException import org.springframework.security.core.context.SecurityContextHolder import org.springframework.stereotype.Component import java.nio.charset.StandardCharsets -import java.util.* +import java.util.Base64 @Component -class BasicAuthServerInterceptor(private val authenticationManager: AuthenticationManager) - : ServerInterceptor { +class BasicAuthServerInterceptor(private val authenticationManager: AuthenticationManager) : + ServerInterceptor { private val log = logger(BasicAuthServerInterceptor::class) override fun interceptCall( - call: ServerCall, - headers: Metadata, - next: ServerCallHandler): ServerCall.Listener { + call: ServerCall, + headers: Metadata, + next: ServerCallHandler + ): ServerCall.Listener { val authHeader = headers.get(Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER)) if (authHeader.isNullOrEmpty()) { throw Status.UNAUTHENTICATED.withDescription("Missing required authentication") - .asRuntimeException() + .asRuntimeException() } try { @@ -54,7 +59,6 @@ class BasicAuthServerInterceptor(private val authenticationManager: Authenticati log.info("Authentication success: {}", authResult) SecurityContextHolder.getContext().authentication = authResult - } catch (e: AuthenticationException) { SecurityContextHolder.clearContext() @@ -69,8 +73,10 @@ class BasicAuthServerInterceptor(private val authenticationManager: Authenticati private fun decodeBasicAuth(authHeader: String): Array { val basicAuth: String try { - basicAuth = String(Base64.getDecoder().decode(authHeader.substring(6).toByteArray(StandardCharsets.UTF_8)), - StandardCharsets.UTF_8) + basicAuth = String( + Base64.getDecoder().decode(authHeader.substring(6).toByteArray(StandardCharsets.UTF_8)), + StandardCharsets.UTF_8 + ) } catch (e: IllegalArgumentException) { throw BadCredentialsException("Failed to decode basic authentication token") } catch (e: IndexOutOfBoundsException) { @@ -84,4 +90,4 @@ class BasicAuthServerInterceptor(private val authenticationManager: Authenticati return arrayOf(basicAuth.substring(0, delim), basicAuth.substring(delim + 1)) } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/SecurityConfiguration.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/SecurityConfiguration.kt index 70b0df2d1..29ec27daa 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/SecurityConfiguration.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/SecurityConfiguration.kt @@ -38,8 +38,10 @@ open class SecurityConfiguration { @Bean open fun inMemoryUserService(): UserDetailsService { - val user = User(username, password, - listOf(SimpleGrantedAuthority("USER"))) + val user = User( + username, password, + listOf(SimpleGrantedAuthority("USER")) + ) return InMemoryUserDetailsManager(user) } @@ -54,4 +56,4 @@ open class SecurityConfiguration { provider.setUserDetailsService(inMemoryUserService()) return provider } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/SecurityContextRepository.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/SecurityContextRepository.kt index f1c362f57..d646c2ee5 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/SecurityContextRepository.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/security/SecurityContextRepository.kt @@ -25,11 +25,11 @@ import org.springframework.stereotype.Component import org.springframework.web.server.ServerWebExchange import reactor.core.publisher.Mono import java.nio.charset.StandardCharsets -import java.util.* +import java.util.Base64 @Component -class SecurityContextRepository(private val authenticationManager: AuthenticationManager) - : ServerSecurityContextRepository { +class SecurityContextRepository(private val authenticationManager: AuthenticationManager) : + ServerSecurityContextRepository { override fun save(swe: ServerWebExchange, sc: SecurityContext): Mono { throw UnsupportedOperationException("Not supported.") @@ -44,7 +44,7 @@ class SecurityContextRepository(private val authenticationManager: Authenticatio val password = tokens[1] val auth = UsernamePasswordAuthenticationToken(username, password) return this.authenticationManager!!.authenticate(auth) - .map { SecurityContextImpl(it) } + .map { SecurityContextImpl(it) } } else { return Mono.empty() } @@ -53,8 +53,10 @@ class SecurityContextRepository(private val authenticationManager: Authenticatio private fun decodeBasicAuth(authHeader: String): Array { val basicAuth: String try { - basicAuth = String(Base64.getDecoder().decode(authHeader.substring(6).toByteArray(StandardCharsets.UTF_8)), - StandardCharsets.UTF_8) + basicAuth = String( + Base64.getDecoder().decode(authHeader.substring(6).toByteArray(StandardCharsets.UTF_8)), + StandardCharsets.UTF_8 + ) } catch (e: IllegalArgumentException) { throw BadCredentialsException("Failed to decode basic authentication token") } catch (e: IndexOutOfBoundsException) { @@ -68,4 +70,4 @@ class SecurityContextRepository(private val authenticationManager: Authenticatio return arrayOf(basicAuth.substring(0, delim), basicAuth.substring(delim + 1)) } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/JsonNormalizer.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/JsonNormalizer.kt index 1a625c279..c5821bed1 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/JsonNormalizer.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/JsonNormalizer.kt @@ -52,10 +52,10 @@ internal class JsonNormalizer { private fun expandJstlSpec(jstlSpec: JsonNode): String { val extendedJstlSpec = updateObjectNodes(jstlSpec, "*", ".") return extendedJstlSpec.toString() - // Handle the "?" as a prefix to literal/non-quoted values - .replace("\"\\?([^\"]+)\"".toRegex(), "$1") - // Also, remove the quotes added by Jackson for key and value of the wildcard matcher - .replace("\"([.*])\"".toRegex(), "$1") + // Handle the "?" as a prefix to literal/non-quoted values + .replace("\"\\?([^\"]+)\"".toRegex(), "$1") + // Also, remove the quotes added by Jackson for key and value of the wildcard matcher + .replace("\"([.*])\"".toRegex(), "$1") } /** diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/MoreMatchers.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/MoreMatchers.kt deleted file mode 100644 index 163544fc9..000000000 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/MoreMatchers.kt +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============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.uat - -import com.google.common.collect.Maps -import org.mockito.ArgumentMatcher - -class RequiredMapEntriesMatcher(private val requiredEntries: Map) : ArgumentMatcher> { - override fun matches(argument: Map?): Boolean { - val missingEntries = Maps.difference(requiredEntries, argument).entriesOnlyOnLeft() - return missingEntries.isEmpty() - } - - override fun toString(): String { - return requiredEntries.toString() - } -} diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/PathDeserializer.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/PathDeserializer.kt index 6b1b0c676..710a65c6f 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/PathDeserializer.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/PathDeserializer.kt @@ -49,4 +49,4 @@ internal class PathDeserializer : StdDeserializer(String::class.java) { } return flatJoinTo(StringBuilder(), path).toString() } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/RequiredMapEntriesMatcher.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/RequiredMapEntriesMatcher.kt new file mode 100644 index 000000000..163544fc9 --- /dev/null +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/RequiredMapEntriesMatcher.kt @@ -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.uat + +import com.google.common.collect.Maps +import org.mockito.ArgumentMatcher + +class RequiredMapEntriesMatcher(private val requiredEntries: Map) : ArgumentMatcher> { + override fun matches(argument: Map?): Boolean { + val missingEntries = Maps.difference(requiredEntries, argument).entriesOnlyOnLeft() + return missingEntries.isEmpty() + } + + override fun toString(): String { + return requiredEntries.toString() + } +} diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatDefinition.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatDefinition.kt index 3046f1041..cc7ac69f0 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatDefinition.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatDefinition.kt @@ -30,34 +30,45 @@ import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.nodes.Tag @JsonInclude(JsonInclude.Include.NON_EMPTY) -data class ProcessDefinition(val name: String, val request: JsonNode, val expectedResponse: JsonNode? = null, - val responseNormalizerSpec: JsonNode? = null) +data class ProcessDefinition( + val name: String, + val request: JsonNode, + val expectedResponse: JsonNode? = null, + val responseNormalizerSpec: JsonNode? = null +) @JsonInclude(JsonInclude.Include.NON_EMPTY) -data class RequestDefinition(val method: String, - @JsonDeserialize(using = PathDeserializer::class) - val path: String, - val headers: Map = emptyMap(), - val body: JsonNode? = null) +data class RequestDefinition( + val method: String, + @JsonDeserialize(using = PathDeserializer::class) + val path: String, + val headers: Map = emptyMap(), + val body: JsonNode? = null +) @JsonInclude(JsonInclude.Include.NON_EMPTY) data class ResponseDefinition(val status: Int = 200, val body: JsonNode? = null) { + companion object { val DEFAULT_RESPONSE = ResponseDefinition() } } @JsonInclude(JsonInclude.Include.NON_EMPTY) -data class ExpectationDefinition(val request: RequestDefinition, - val response: ResponseDefinition = ResponseDefinition.DEFAULT_RESPONSE) +data class ExpectationDefinition( + val request: RequestDefinition, + val response: ResponseDefinition = ResponseDefinition.DEFAULT_RESPONSE +) @JsonInclude(JsonInclude.Include.NON_EMPTY) data class ServiceDefinition(val selector: String, val expectations: List) @JsonInclude(JsonInclude.Include.NON_EMPTY) -data class UatDefinition(val processes: List, - @JsonAlias("external-services") - val externalServices: List = emptyList()) { +data class UatDefinition( + val processes: List, + @JsonAlias("external-services") + val externalServices: List = emptyList() +) { fun dump(mapper: ObjectMapper, excludedProperties: List = emptyList()): String { val uatAsMap: Map = mapper.convertValue(this) @@ -86,7 +97,6 @@ data class UatDefinition(val processes: List, companion object { fun load(mapper: ObjectMapper, spec: String): UatDefinition = - mapper.convertValue(Yaml().load(spec), UatDefinition::class.java) - + mapper.convertValue(Yaml().load(spec), UatDefinition::class.java) } } diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatExecutor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatExecutor.kt index 4e97460d3..89ba1500b 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatExecutor.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatExecutor.kt @@ -70,9 +70,9 @@ import java.util.concurrent.ConcurrentHashMap */ @Component class UatExecutor( - private val environment: ConfigurableEnvironment, - private val restClientFactory: BluePrintRestLibPropertyService, - private val mapper: ObjectMapper + private val environment: ConfigurableEnvironment, + private val restClientFactory: BluePrintRestLibPropertyService, + private val mapper: ObjectMapper ) { companion object { @@ -103,8 +103,8 @@ class UatExecutor( fun execute(uat: UatDefinition, cbaBytes: ByteArray): UatDefinition { val defaultHeaders = listOf(BasicHeader(HttpHeaders.AUTHORIZATION, clientAuthToken())) val httpClient = HttpClientBuilder.create() - .setDefaultHeaders(defaultHeaders) - .build() + .setDefaultHeaders(defaultHeaders) + .build() // Only if externalServices are defined val mockInterceptor = MockPreInterceptor() // Always defined and used, whatever the case @@ -113,13 +113,13 @@ class UatExecutor( try { // Configure mocked external services and save their expected requests for further validation val requestsPerClient = uat.externalServices.associateBy( - { service -> - createRestClientMock(service.expectations).also { restClient -> - // side-effect: register restClient to override real instance - mockInterceptor.registerMock(service.selector, restClient) - } - }, - { service -> service.expectations.map { it.request } } + { service -> + createRestClientMock(service.expectations).also { restClient -> + // side-effect: register restClient to override real instance + mockInterceptor.registerMock(service.selector, restClient) + } + }, + { service -> service.expectations.map { it.request } } ) val newProcesses = httpClient.use { client -> @@ -129,8 +129,10 @@ class UatExecutor( uat.processes.map { process -> log.info("Executing process '${process.name}'") val responseNormalizer = JsonNormalizer.getNormalizer(mapper, process.responseNormalizerSpec) - val actualResponse = processBlueprint(client, process.request, - process.expectedResponse, responseNormalizer) + val actualResponse = processBlueprint( + client, process.request, + process.expectedResponse, responseNormalizer + ) ProcessDefinition(process.name, process.request, actualResponse, process.responseNormalizerSpec) } } @@ -139,10 +141,11 @@ class UatExecutor( for ((mockClient, requests) in requestsPerClient) { requests.forEach { request -> verify(mockClient, atLeastOnce()).exchangeResource( - eq(request.method), - eq(request.path), - argThat { assertJsonEquals(request.body, this) }, - argThat(RequiredMapEntriesMatcher(request.headers))) + eq(request.method), + eq(request.path), + argThat { assertJsonEquals(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()) @@ -150,7 +153,7 @@ class UatExecutor( } val newExternalServices = spyInterceptor.getSpies() - .map(SpyService::asServiceDefinition) + .map(SpyService::asServiceDefinition) return UatDefinition(newProcesses, newExternalServices) } finally { @@ -158,29 +161,32 @@ class UatExecutor( } } - private fun createRestClientMock(restExpectations: List) - : BlueprintWebClientService { + private fun createRestClientMock(restExpectations: List): + BlueprintWebClientService { val restClient = mock( - defaultAnswer = Answers.RETURNS_SMART_NULLS, - // our custom verboseLogging handler - invocationListeners = arrayOf(mockLoggingListener) + defaultAnswer = Answers.RETURNS_SMART_NULLS, + // our custom verboseLogging handler + invocationListeners = arrayOf(mockLoggingListener) ) // Delegates to overloaded exchangeResource(String, String, String, Map) whenever(restClient.exchangeResource(any(), any(), any())) - .thenAnswer { invocation -> - val method = invocation.arguments[0] as String - val path = invocation.arguments[1] as String - val request = invocation.arguments[2] as String - restClient.exchangeResource(method, path, request, emptyMap()) - } + .thenAnswer { invocation -> + val method = invocation.arguments[0] as String + val path = invocation.arguments[1] as String + val request = invocation.arguments[2] as String + restClient.exchangeResource(method, path, request, emptyMap()) + } for (expectation in restExpectations) { - whenever(restClient.exchangeResource( + whenever( + restClient.exchangeResource( eq(expectation.request.method), eq(expectation.request.path), any(), - any())) - .thenReturn(WebClientResponse(expectation.response.status, expectation.response.body.toString())) + any() + ) + ) + .thenReturn(WebClientResponse(expectation.response.status, expectation.response.body.toString())) } return restClient } @@ -188,9 +194,9 @@ class UatExecutor( @Throws(AssertionError::class) private fun uploadBlueprint(client: HttpClient, cbaBytes: ByteArray) { val multipartEntity = MultipartEntityBuilder.create() - .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) - .addBinaryBody("file", cbaBytes, ContentType.DEFAULT_BINARY, "cba.zip") - .build() + .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) + .addBinaryBody("file", cbaBytes, ContentType.DEFAULT_BINARY, "cba.zip") + .build() val request = HttpPost("$baseUrl/api/v1/blueprint-model/publish").apply { entity = multipartEntity } @@ -201,8 +207,12 @@ class UatExecutor( } @Throws(AssertionError::class) - private fun processBlueprint(client: HttpClient, requestBody: JsonNode, - expectedResponse: JsonNode?, responseNormalizer: (String) -> String): JsonNode { + private fun processBlueprint( + client: HttpClient, + requestBody: JsonNode, + expectedResponse: JsonNode?, + responseNormalizer: (String) -> String + ): JsonNode { val stringEntity = StringEntity(mapper.writeValueAsString(requestBody), ContentType.APPLICATION_JSON) val request = HttpPost("$baseUrl/api/v1/execution-service/process").apply { entity = stringEntity @@ -234,8 +244,8 @@ class UatExecutor( } private fun localServerPort(): Int = - (environment.getProperty("local.server.port") - ?: environment.getRequiredProperty("blueprint.httpPort")).toInt() + (environment.getProperty("local.server.port") + ?: environment.getRequiredProperty("blueprint.httpPort")).toInt() private fun clientAuthToken(): String { val username = environment.getRequiredProperty("security.user.name") @@ -255,7 +265,7 @@ class UatExecutor( } override fun getInstance(selector: String): BlueprintWebClientService? = - mocks[selector] + mocks[selector] fun registerMock(selector: String, client: BlueprintWebClientService) { mocks[selector] = client @@ -277,21 +287,27 @@ class UatExecutor( } fun getSpies(): List = - spies.values.toList() + spies.values.toList() } - private class SpyService(private val mapper: ObjectMapper, - val selector: String, - private val realService: BlueprintWebClientService) : - BlueprintWebClientService by realService { + private class SpyService( + private val mapper: ObjectMapper, + val selector: String, + private val realService: BlueprintWebClientService + ) : + BlueprintWebClientService by realService { private val expectations: MutableList = mutableListOf() override fun exchangeResource(methodType: String, path: String, request: String): WebClientResponse = - exchangeResource(methodType, path, request, DEFAULT_HEADERS) - - override fun exchangeResource(methodType: String, path: String, request: String, - headers: Map): WebClientResponse { + exchangeResource(methodType, path, request, DEFAULT_HEADERS) + + override fun exchangeResource( + methodType: String, + path: String, + request: String, + headers: Map + ): WebClientResponse { val requestDefinition = RequestDefinition(methodType, path, headers, toJson(request)) val realAnswer = realService.exchangeResource(methodType, path, request, headers) val responseBody = when { @@ -309,7 +325,7 @@ class UatExecutor( } fun asServiceDefinition() = - ServiceDefinition(selector, expectations) + ServiceDefinition(selector, expectations) private fun toJson(str: String): JsonNode? { return when { @@ -320,9 +336,9 @@ class UatExecutor( companion object { private val DEFAULT_HEADERS = mapOf( - HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, - HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE + HttpHeaders.CONTENT_TYPE to MediaType.APPLICATION_JSON_VALUE, + HttpHeaders.ACCEPT to MediaType.APPLICATION_JSON_VALUE ) } } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServices.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServices.kt index f133fd7c7..5b62f1296 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServices.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/UatServices.kt @@ -72,8 +72,10 @@ open class UatServices(private val uatExecutor: UatExecutor, private val mapper: @PostMapping("/spy", consumes = [MediaType.MULTIPART_FORM_DATA_VALUE], produces = ["text/vnd.yaml"]) @PreAuthorize("hasRole('USER')") @Suppress("BlockingMethodInNonBlockingContext") - open fun spy(@RequestPart("cba") cbaFile: FilePart, - @RequestPart("uat", required = false) uatFile: FilePart?): String = runBlocking { + open fun spy( + @RequestPart("cba") cbaFile: FilePart, + @RequestPart("uat", required = false) uatFile: FilePart? + ): String = runBlocking { val tempFile = createTempFile() setContextColor(COLOR_SERVICES) try { @@ -118,4 +120,4 @@ open class UatServices(private val uatExecutor: UatExecutor, private val mapper: // Fields that can be safely ignored from BPP response, and can be omitted on the UAT specification. private val FIELDS_TO_EXCLUDE = listOf("timestamp") } -} \ No newline at end of file +} diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt index 10139c839..9ae3ff805 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/ColorMarker.kt @@ -21,4 +21,4 @@ package org.onap.ccsdk.cds.blueprintsprocessor.uat.logging import org.slf4j.Marker -class ColorMarker internal constructor(private val dlg: Marker) : Marker by dlg \ No newline at end of file +class ColorMarker internal constructor(private val dlg: Marker) : Marker by dlg diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt index dce516933..f0cba2670 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/LogColor.kt @@ -41,5 +41,5 @@ object LogColor { } fun markerOf(color: String): ColorMarker = - ColorMarker(MarkerFactory.getMarker(color)) + ColorMarker(MarkerFactory.getMarker(color)) } diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/SmartColorDiscriminator.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/SmartColorDiscriminator.kt index d7b38d3fa..cad235450 100644 --- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/SmartColorDiscriminator.kt +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/logging/SmartColorDiscriminator.kt @@ -35,7 +35,7 @@ class SmartColorDiscriminator : AbstractDiscriminator() { } override fun getDiscriminatingValue(e: ILoggingEvent): String = - (e.marker as? ColorMarker)?.name - ?: e.mdcPropertyMap?.get(MDC_COLOR_KEY) - ?: defaultValue -} \ No newline at end of file + (e.marker as? ColorMarker)?.name + ?: e.mdcPropertyMap?.get(MDC_COLOR_KEY) + ?: defaultValue +} -- cgit 1.2.3-korg