diff options
author | Dan Timoney <dtimoney@att.com> | 2020-09-22 19:05:47 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-09-22 19:05:47 +0000 |
commit | e515a85125e5487ecd3f7127b6af0b192d4a0993 (patch) | |
tree | 1fe08a7d54c28419a44845634037d77f8c434a4b /ms/blueprintsprocessor/modules/commons/rest-lib | |
parent | 85d8f7f7701570fb745c3d6360d500f97bdf1b25 (diff) | |
parent | 1072867dfac0df993cbd3e44bcc11a5cac7465fd (diff) |
Merge "Enabling Code Formatter"
Diffstat (limited to 'ms/blueprintsprocessor/modules/commons/rest-lib')
11 files changed, 241 insertions, 206 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt index 23125430a..6e9e4b554 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt @@ -47,6 +47,7 @@ fun BluePrintDependencyService.restClientService(jsonNode: JsonNode): BlueprintW class RestLibConstants { companion object { + const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service" const val PROPERTY_REST_CLIENT_PREFIX = "blueprintsprocessor.restclient." const val PROPERTY_TYPE = "type" diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt index 4c18f81ab..a227cf24e 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt @@ -19,12 +19,14 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest open class RestClientProperties { + lateinit var type: String lateinit var url: String var additionalHeaders: Map<String, String>? = null } open class SSLRestClientProperties : RestClientProperties() { + lateinit var keyStoreInstance: String // JKS, PKCS12 lateinit var sslTrust: String lateinit var sslTrustPassword: String @@ -46,15 +48,18 @@ open class SSLTokenAuthRestClientProperties : SSLRestClientProperties() { } open class BasicAuthRestClientProperties : RestClientProperties() { + lateinit var password: String lateinit var username: String } open class TokenAuthRestClientProperties : RestClientProperties() { + var token: String? = null } open class PolicyManagerRestClientProperties : RestClientProperties() { + lateinit var env: String lateinit var clientAuth: String lateinit var authorisation: String diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt index 5d68e5d43..ca1046dde 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/RestClientPropertiesDSL.kt @@ -112,6 +112,7 @@ open class RestClientPropertiesAssignmentBuilder : PropertiesAssignmentBuilder() } open class BasicAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() { + open fun password(password: String) { password(password.asJsonPrimitive()) } @@ -130,6 +131,7 @@ open class BasicAuthRestClientPropertiesAssignmentBuilder : RestClientProperties } open class TokenAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() { + open fun token(token: String) { token(token.asJsonPrimitive()) } @@ -140,6 +142,7 @@ open class TokenAuthRestClientPropertiesAssignmentBuilder : RestClientProperties } open class SslAuthRestClientPropertiesAssignmentBuilder : RestClientPropertiesAssignmentBuilder() { + open fun keyStoreInstance(keyStoreInstance: String) { keyStoreInstance(keyStoreInstance.asJsonPrimitive()) } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/filters/RestServerLoggingWebFilter.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/filters/RestServerLoggingWebFilter.kt index 5b6691eff..4b5c2c4e8 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/filters/RestServerLoggingWebFilter.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/filters/RestServerLoggingWebFilter.kt @@ -25,6 +25,7 @@ import reactor.core.publisher.Mono import reactor.util.context.Context open class RestServerLoggingWebFilter : WebFilter { + override fun filter(serverWebExchange: ServerWebExchange, webFilterChain: WebFilterChain): Mono<Void> { val loggingService = RestLoggerService() diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt index bfc0a5cd4..be9b849f6 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt @@ -26,7 +26,7 @@ import java.util.Base64 class BasicAuthRestClientService( private val restClientProperties: - BasicAuthRestClientProperties + BasicAuthRestClientProperties ) : BlueprintWebClientService { @@ -49,21 +49,21 @@ class BasicAuthRestClientService( } override fun convertToBasicHeaders(headers: Map<String, String>): - Array<BasicHeader> { - val customHeaders: MutableMap<String, String> = headers.toMutableMap() - // inject additionalHeaders - customHeaders.putAll(verifyAdditionalHeaders(restClientProperties)) + Array<BasicHeader> { + val customHeaders: MutableMap<String, String> = headers.toMutableMap() + // inject additionalHeaders + customHeaders.putAll(verifyAdditionalHeaders(restClientProperties)) - if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { - val encodedCredentials = setBasicAuth( - restClientProperties.username, - restClientProperties.password - ) - customHeaders[HttpHeaders.AUTHORIZATION] = - "Basic $encodedCredentials" + if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { + val encodedCredentials = setBasicAuth( + restClientProperties.username, + restClientProperties.password + ) + customHeaders[HttpHeaders.AUTHORIZATION] = + "Basic $encodedCredentials" + } + return super.convertToBasicHeaders(customHeaders) } - return super.convertToBasicHeaders(customHeaders) - } private fun setBasicAuth(username: String, password: String): String { val credentialsString = "$username:$password" diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt index 8f528a2ef..a2c68ec68 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt @@ -90,7 +90,7 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic else -> { throw BluePrintProcessorException( "Rest adaptor($type) is" + - " not supported" + " not supported" ) } } @@ -128,91 +128,93 @@ open class BluePrintRestLibPropertyService(private var bluePrintPropertiesServic } private fun blueprintWebClientService(restClientProperties: RestClientProperties): - BlueprintWebClientService { - - when (restClientProperties) { - is SSLRestClientProperties -> { - return SSLRestClientService(restClientProperties) - } - is TokenAuthRestClientProperties -> { - return TokenAuthRestClientService(restClientProperties) - } - is BasicAuthRestClientProperties -> { - return BasicAuthRestClientService(restClientProperties) - } - else -> { - throw BluePrintProcessorException("couldn't get rest service for type:${restClientProperties.type} uri: ${restClientProperties.url}") + BlueprintWebClientService { + + when (restClientProperties) { + is SSLRestClientProperties -> { + return SSLRestClientService(restClientProperties) + } + is TokenAuthRestClientProperties -> { + return TokenAuthRestClientService(restClientProperties) + } + is BasicAuthRestClientProperties -> { + return BasicAuthRestClientService(restClientProperties) + } + else -> { + throw BluePrintProcessorException("couldn't get rest service for type:${restClientProperties.type} uri: ${restClientProperties.url}") + } } } - } private fun tokenRestClientProperties(prefix: String): - TokenAuthRestClientProperties { - return bluePrintPropertiesService.propertyBeanType( - prefix, TokenAuthRestClientProperties::class.java - ) - } + TokenAuthRestClientProperties { + return bluePrintPropertiesService.propertyBeanType( + prefix, TokenAuthRestClientProperties::class.java + ) + } private fun basicAuthRestClientProperties(prefix: String): - BasicAuthRestClientProperties { - return bluePrintPropertiesService.propertyBeanType( - prefix, BasicAuthRestClientProperties::class.java - ) - } + BasicAuthRestClientProperties { + return bluePrintPropertiesService.propertyBeanType( + prefix, BasicAuthRestClientProperties::class.java + ) + } private fun sslBasicAuthRestClientProperties(prefix: String): - SSLRestClientProperties { + SSLRestClientProperties { - val sslProps: SSLBasicAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, SSLBasicAuthRestClientProperties::class.java - ) - val basicProps: BasicAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, BasicAuthRestClientProperties::class.java - ) - sslProps.basicAuth = basicProps - return sslProps - } + val sslProps: SSLBasicAuthRestClientProperties = + bluePrintPropertiesService.propertyBeanType( + prefix, SSLBasicAuthRestClientProperties::class.java + ) + val basicProps: BasicAuthRestClientProperties = + bluePrintPropertiesService.propertyBeanType( + prefix, BasicAuthRestClientProperties::class.java + ) + sslProps.basicAuth = basicProps + return sslProps + } private fun sslTokenAuthRestClientProperties(prefix: String): - SSLRestClientProperties { + SSLRestClientProperties { - val sslProps: SSLTokenAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, - SSLTokenAuthRestClientProperties::class.java - ) - val basicProps: TokenAuthRestClientProperties = - bluePrintPropertiesService.propertyBeanType( - prefix, - TokenAuthRestClientProperties::class.java - ) - sslProps.tokenAuth = basicProps - return sslProps - } + val sslProps: SSLTokenAuthRestClientProperties = + bluePrintPropertiesService.propertyBeanType( + prefix, + SSLTokenAuthRestClientProperties::class.java + ) + val basicProps: TokenAuthRestClientProperties = + bluePrintPropertiesService.propertyBeanType( + prefix, + TokenAuthRestClientProperties::class.java + ) + sslProps.tokenAuth = basicProps + return sslProps + } private fun sslNoAuthRestClientProperties(prefix: String): - SSLRestClientProperties { - return bluePrintPropertiesService.propertyBeanType( - prefix, SSLRestClientProperties::class.java - ) - } + SSLRestClientProperties { + return bluePrintPropertiesService.propertyBeanType( + prefix, SSLRestClientProperties::class.java + ) + } private fun policyManagerRestClientProperties(prefix: String): - PolicyManagerRestClientProperties { - return bluePrintPropertiesService.propertyBeanType( - prefix, PolicyManagerRestClientProperties::class.java - ) - } + PolicyManagerRestClientProperties { + return bluePrintPropertiesService.propertyBeanType( + prefix, PolicyManagerRestClientProperties::class.java + ) + } interface PreInterceptor { + fun getInstance(jsonNode: JsonNode): BlueprintWebClientService? fun getInstance(selector: String): BlueprintWebClientService? } interface PostInterceptor { + fun getInstance(jsonNode: JsonNode, service: BlueprintWebClientService): BlueprintWebClientService fun getInstance(selector: String, service: BlueprintWebClientService): BlueprintWebClientService diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt index 11f6dc7e3..9beacfcea 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BlueprintWebClientService.kt @@ -165,14 +165,14 @@ interface BlueprintWebClientService { httpUriRequest: HttpUriRequest, responseType: Class<T> ): - WebClientResponse<T> { - val httpResponse = httpClient().execute(httpUriRequest) - val statusCode = httpResponse.statusLine.statusCode - httpResponse.entity.content.use { - val body = getResponse(it, responseType) - return WebClientResponse(statusCode, body) + WebClientResponse<T> { + val httpResponse = httpClient().execute(httpUriRequest) + val statusCode = httpResponse.statusLine.statusCode + httpResponse.entity.content.use { + val body = getResponse(it, responseType) + return WebClientResponse(statusCode, body) + } } - } suspend fun getNB(path: String): WebClientResponse<String> { return getNB(path, null, String::class.java) @@ -183,9 +183,9 @@ interface BlueprintWebClientService { } suspend fun <T> getNB(path: String, additionalHeaders: Array<BasicHeader>?, responseType: Class<T>): - WebClientResponse<T> = withContext(Dispatchers.IO) { - get(path, additionalHeaders!!, responseType) - } + WebClientResponse<T> = withContext(Dispatchers.IO) { + get(path, additionalHeaders!!, responseType) + } suspend fun postNB(path: String, request: Any): WebClientResponse<String> { return postNB(path, request, null, String::class.java) @@ -230,19 +230,19 @@ interface BlueprintWebClientService { } suspend fun <T> deleteNB(path: String, additionalHeaders: Array<BasicHeader>?): - WebClientResponse<String> { - return deleteNB(path, additionalHeaders, String::class.java) - } + WebClientResponse<String> { + return deleteNB(path, additionalHeaders, String::class.java) + } suspend fun <T> deleteNB(path: String, additionalHeaders: Array<BasicHeader>?, responseType: Class<T>): - WebClientResponse<T> = withContext(Dispatchers.IO) { - delete(path, additionalHeaders!!, responseType) - } + WebClientResponse<T> = withContext(Dispatchers.IO) { + delete(path, additionalHeaders!!, responseType) + } suspend fun <T> patchNB(path: String, request: Any, additionalHeaders: Array<BasicHeader>?, responseType: Class<T>): - WebClientResponse<T> = withContext(Dispatchers.IO) { - patch(path, request, additionalHeaders!!, responseType) - } + WebClientResponse<T> = withContext(Dispatchers.IO) { + patch(path, request, additionalHeaders!!, responseType) + } suspend fun exchangeNB(methodType: String, path: String, request: Any): WebClientResponse<String> { return exchangeNB( @@ -252,9 +252,9 @@ interface BlueprintWebClientService { } suspend fun exchangeNB(methodType: String, path: String, request: Any, additionalHeaders: Map<String, String>?): - WebClientResponse<String> { - return exchangeNB(methodType, path, request, additionalHeaders, String::class.java) - } + WebClientResponse<String> { + return exchangeNB(methodType, path, request, additionalHeaders, String::class.java) + } suspend fun <T> exchangeNB( methodType: String, @@ -294,16 +294,16 @@ interface BlueprintWebClientService { } private fun basicHeaders(headers: Map<String, String>?): - Array<BasicHeader> { - val basicHeaders = mutableListOf<BasicHeader>() - defaultHeaders().forEach { (name, value) -> - basicHeaders.add(BasicHeader(name, value)) - } - headers?.forEach { name, value -> - basicHeaders.add(BasicHeader(name, value)) + Array<BasicHeader> { + val basicHeaders = mutableListOf<BasicHeader>() + defaultHeaders().forEach { (name, value) -> + basicHeaders.add(BasicHeader(name, value)) + } + headers?.forEach { name, value -> + basicHeaders.add(BasicHeader(name, value)) + } + return basicHeaders.toTypedArray() } - return basicHeaders.toTypedArray() - } // Non Blocking Rest Implementation suspend fun httpClientNB(): CloseableHttpClient { @@ -323,8 +323,8 @@ interface BlueprintWebClientService { restClientProperties.additionalHeaders?.let { if (it.keys.map { k -> k.toLowerCase().trim() }.contains(HttpHeaders.AUTHORIZATION.toLowerCase())) { val errMsg = "Error in definition of endpoint ${restClientProperties.url}." + - " User-supplied \"additionalHeaders\" cannot contain AUTHORIZATION header with" + - " auth-type \"${RestLibConstants.TYPE_BASIC_AUTH}\"" + " User-supplied \"additionalHeaders\" cannot contain AUTHORIZATION header with" + + " auth-type \"${RestLibConstants.TYPE_BASIC_AUTH}\"" WebClientUtils.log.error(errMsg) throw BluePrintProcessorException(errMsg) } else { diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt index dc45e3545..611c0855d 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt @@ -54,9 +54,11 @@ import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext class RestLoggerService { + private val log = logger(RestLoggerService::class) companion object { + /** Used before invoking any REST outbound request, Inbound Invocation ID is used as request Id * for outbound Request, If invocation Id is missing then default Request Id will be generated. */ @@ -110,6 +112,7 @@ suspend fun <T> mdcWebCoroutineScope( block: suspend CoroutineScope.() -> T ) = coroutineScope { val reactorContext = this.coroutineContext[ReactorContext] + /** Populate MDC context only if present in Reactor Context */ val newContext = if (reactorContext != null && !reactorContext.context.isEmpty && @@ -138,8 +141,11 @@ fun <T> monoMdc( block: suspend CoroutineScope.() -> T? ): Mono<T> = Mono.create { sink -> - val reactorContext = (context[ReactorContext]?.context?.putAll(sink.currentContext()) - ?: sink.currentContext()).asCoroutineContext() + val reactorContext = ( + context[ReactorContext]?.context?.putAll(sink.currentContext()) + ?: sink.currentContext() + ).asCoroutineContext() + /** Populate MDC context only if present in Reactor Context */ val newContext = if (!reactorContext.context.isEmpty && reactorContext.context.hasKey(MDCContext) diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt index 57702f8ac..600eedf15 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/TokenAuthRestClientService.kt @@ -23,7 +23,7 @@ import org.springframework.http.MediaType class TokenAuthRestClientService( private val restClientProperties: - TokenAuthRestClientProperties + TokenAuthRestClientProperties ) : BlueprintWebClientService { @@ -36,15 +36,15 @@ class TokenAuthRestClientService( } override fun convertToBasicHeaders(headers: Map<String, String>): - Array<BasicHeader> { - val customHeaders: MutableMap<String, String> = headers.toMutableMap() - // inject additionalHeaders - customHeaders.putAll(verifyAdditionalHeaders(restClientProperties)) - if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { - customHeaders[HttpHeaders.AUTHORIZATION] = restClientProperties.token!! + Array<BasicHeader> { + val customHeaders: MutableMap<String, String> = headers.toMutableMap() + // inject additionalHeaders + customHeaders.putAll(verifyAdditionalHeaders(restClientProperties)) + if (!headers.containsKey(HttpHeaders.AUTHORIZATION)) { + customHeaders[HttpHeaders.AUTHORIZATION] = restClientProperties.token!! + } + return super.convertToBasicHeaders(customHeaders) } - return super.convertToBasicHeaders(customHeaders) - } override fun host(uri: String): String { return restClientProperties.url + uri diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt index 53047d4a8..f45d1cd69 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BluePrintRestLibPropertyServiceTest.kt @@ -42,35 +42,38 @@ import kotlin.test.assertNotNull @RunWith(SpringRunner::class) @ContextConfiguration( - classes = [BluePrintRestLibConfiguration::class, BluePrintPropertyConfiguration::class, - BluePrintPropertiesService::class] + classes = [ + BluePrintRestLibConfiguration::class, BluePrintPropertyConfiguration::class, + BluePrintPropertiesService::class + ] ) @TestPropertySource( properties = - ["blueprintsprocessor.restclient.sample.type=basic-auth", - "blueprintsprocessor.restclient.sample.url=http://localhost:8080", - "blueprintsprocessor.restclient.sample.userId=sampleuser", - "blueprintsprocessor.restclient.sslbasic.type=ssl-basic-auth", - "blueprintsprocessor.restclient.sslbasic.url=https://localhost:8443", - "blueprintsprocessor.restclient.sslbasic.username=admin", - "blueprintsprocessor.restclient.sslbasic.password=cds", - "blueprintsprocessor.restclient.sslbasic.keyStoreInstance=PKCS12", - "blueprintsprocessor.restclient.sslbasic.sslTrust=src/test/resources/keystore.p12", - "blueprintsprocessor.restclient.sslbasic.sslTrustPassword=changeit", - "blueprintsprocessor.restclient.ssltoken.type=ssl-token-auth", - "blueprintsprocessor.restclient.ssltoken.url=https://localhost:8443", - "blueprintsprocessor.restclient.ssltoken.token=72178473kjshdkjgvbsdkjv903274908", - "blueprintsprocessor.restclient.ssltoken.keyStoreInstance=PKCS12", - "blueprintsprocessor.restclient.ssltoken.sslTrust=src/test/resources/keystore.p12", - "blueprintsprocessor.restclient.ssltoken.sslTrustPassword=changeit", - "blueprintsprocessor.restclient.ssl.type=ssl-no-auth", - "blueprintsprocessor.restclient.ssl.url=https://localhost:8443", - "blueprintsprocessor.restclient.ssl.keyStoreInstance=PKCS12", - "blueprintsprocessor.restclient.ssl.sslTrust=src/test/resources/keystore.p12", - "blueprintsprocessor.restclient.ssl.sslTrustPassword=changeit", - "blueprintsprocessor.restclient.ssl.sslKey=src/test/resources/keystore.p12", - "blueprintsprocessor.restclient.ssl.sslKeyPassword=changeit" - ] + [ + "blueprintsprocessor.restclient.sample.type=basic-auth", + "blueprintsprocessor.restclient.sample.url=http://localhost:8080", + "blueprintsprocessor.restclient.sample.userId=sampleuser", + "blueprintsprocessor.restclient.sslbasic.type=ssl-basic-auth", + "blueprintsprocessor.restclient.sslbasic.url=https://localhost:8443", + "blueprintsprocessor.restclient.sslbasic.username=admin", + "blueprintsprocessor.restclient.sslbasic.password=cds", + "blueprintsprocessor.restclient.sslbasic.keyStoreInstance=PKCS12", + "blueprintsprocessor.restclient.sslbasic.sslTrust=src/test/resources/keystore.p12", + "blueprintsprocessor.restclient.sslbasic.sslTrustPassword=changeit", + "blueprintsprocessor.restclient.ssltoken.type=ssl-token-auth", + "blueprintsprocessor.restclient.ssltoken.url=https://localhost:8443", + "blueprintsprocessor.restclient.ssltoken.token=72178473kjshdkjgvbsdkjv903274908", + "blueprintsprocessor.restclient.ssltoken.keyStoreInstance=PKCS12", + "blueprintsprocessor.restclient.ssltoken.sslTrust=src/test/resources/keystore.p12", + "blueprintsprocessor.restclient.ssltoken.sslTrustPassword=changeit", + "blueprintsprocessor.restclient.ssl.type=ssl-no-auth", + "blueprintsprocessor.restclient.ssl.url=https://localhost:8443", + "blueprintsprocessor.restclient.ssl.keyStoreInstance=PKCS12", + "blueprintsprocessor.restclient.ssl.sslTrust=src/test/resources/keystore.p12", + "blueprintsprocessor.restclient.ssl.sslTrustPassword=changeit", + "blueprintsprocessor.restclient.ssl.sslKey=src/test/resources/keystore.p12", + "blueprintsprocessor.restclient.ssl.sslKeyPassword=changeit" + ] ) class BluePrintRestLibPropertyServiceTest { @@ -84,8 +87,9 @@ class BluePrintRestLibPropertyServiceTest { ) assertNotNull(properties, "failed to create property bean") assertNotNull( - properties.url, "failed to get url property in" + - " property bean" + properties.url, + "failed to get url property in" + + " property bean" ) } @@ -424,6 +428,7 @@ class BluePrintRestLibPropertyServiceTest { } companion object BluePrintRestLibPropertyServiceTest { + val defaultMapper = ObjectMapper() val expectedTokenAuthDefaultHeaders = mapOf<String, String>( "Content-Type" to "application/json", @@ -435,7 +440,8 @@ class BluePrintRestLibPropertyServiceTest { """, "additionalHeaders" : { "authorization": "Basic aGF2ZTphbmljZWRheQo=" - }""".trimIndent() + } + """.trimIndent() ) private fun sslTokenAuthEndpointWithHeadersField(headers: String = ""): String = @@ -462,7 +468,8 @@ class BluePrintRestLibPropertyServiceTest { "username" : "admin", "password" : "cds" }$headers - }""".trimIndent() + } + """.trimIndent() private fun sslNoAuthEndpointWithHeadersField(headers: String = ""): String = """{ "type" : "ssl-no-auth", @@ -472,7 +479,8 @@ class BluePrintRestLibPropertyServiceTest { "sslTrustPassword" : "changeit", "sslKey" : "src/test/resources/keystore.p12", "sslKeyPassword" : "changeit"$headers - }""".trimIndent() + } + """.trimIndent() // Don't forget to supply "," as the first char to make valid JSON private fun basicAuthEndpointWithHeadersField(headers: String = ""): String = @@ -481,37 +489,44 @@ class BluePrintRestLibPropertyServiceTest { "url": "http://127.0.0.1:8000", "username": "user", "password": "pass"$headers - }""".trimIndent() + } + """.trimIndent() private val emptyAdditionalHeaders = """, "additionalHeaders" : { - }""".trimIndent() + } + """.trimIndent() private val oneAdditionalParameter = """, "additionalHeaders" : { "key1": "value1" - }""".trimIndent() + } + """.trimIndent() private val threeAdditionalHeaders = """, "additionalHeaders" : { "key1": "value1", "key2": "value2", "key3": "value3" - }""".trimIndent() + } + """.trimIndent() private val contentTypeAdditionalHeader = """, "additionalHeaders" : { "${HttpHeaders.CONTENT_TYPE}": "${MediaType.APPLICATION_XML}" - }""".trimIndent() + } + """.trimIndent() private val additionalHeadersWithAuth = """, "additionalHeaders" : { "Authorization": "Basic aGF2ZTphbmljZWRheQo=" - }""".trimIndent() + } + """.trimIndent() private val additionalHeadersWithAuthLowercased = """, "additionalHeaders" : { "authorization": "Basic aGF2ZTphbmljZWRheQo=" - }""".trimIndent() + } + """.trimIndent() } } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt index ea202481e..74e3807f7 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestClientServiceTest.kt @@ -65,31 +65,33 @@ import kotlin.test.assertNotNull @EnableAutoConfiguration(exclude = [DataSourceAutoConfiguration::class]) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @ContextConfiguration( - classes = [BluePrintRestLibConfiguration::class, SampleController::class, + classes = [ + BluePrintRestLibConfiguration::class, SampleController::class, SecurityConfiguration::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class] + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class + ] ) @TestPropertySource( properties = - [ - "server.port=8443", - "server.ssl.enabled=true", - "server.ssl.key-store=classpath:keystore.p12", - "server.ssl.key-store-password=changeit", - "server.ssl.keyStoreType=PKCS12", - "server.ssl.keyAlias=tomcat", - "blueprintsprocessor.restclient.sample.type=basic-auth", - "blueprintsprocessor.restclient.sample.url=http://127.0.0.1:9081", - "blueprintsprocessor.restclient.sample.username=admin", - "blueprintsprocessor.restclient.sample.password=jans", - "blueprintsprocessor.restclient.test.type=ssl-basic-auth", - "blueprintsprocessor.restclient.test.url=https://localhost:8443", - "blueprintsprocessor.restclient.test.username=admin", - "blueprintsprocessor.restclient.test.password=jans", - "blueprintsprocessor.restclient.test.keyStoreInstance=PKCS12", - "blueprintsprocessor.restclient.test.sslTrust=src/test/resources/keystore.p12", - "blueprintsprocessor.restclient.test.sslTrustPassword=changeit" - ] + [ + "server.port=8443", + "server.ssl.enabled=true", + "server.ssl.key-store=classpath:keystore.p12", + "server.ssl.key-store-password=changeit", + "server.ssl.keyStoreType=PKCS12", + "server.ssl.keyAlias=tomcat", + "blueprintsprocessor.restclient.sample.type=basic-auth", + "blueprintsprocessor.restclient.sample.url=http://127.0.0.1:9081", + "blueprintsprocessor.restclient.sample.username=admin", + "blueprintsprocessor.restclient.sample.password=jans", + "blueprintsprocessor.restclient.test.type=ssl-basic-auth", + "blueprintsprocessor.restclient.test.url=https://localhost:8443", + "blueprintsprocessor.restclient.test.username=admin", + "blueprintsprocessor.restclient.test.password=jans", + "blueprintsprocessor.restclient.test.keyStoreInstance=PKCS12", + "blueprintsprocessor.restclient.test.sslTrust=src/test/resources/keystore.p12", + "blueprintsprocessor.restclient.test.sslTrustPassword=changeit" + ] ) class RestClientServiceTest { @@ -119,26 +121,26 @@ class RestClientServiceTest { @Test fun testGetQueryParam() { val restClientService = bluePrintRestLibPropertyService - .blueprintWebClientService("sample") + .blueprintWebClientService("sample") val response = restClientService.exchangeResource( - HttpMethod.GET.name, "/sample/query?id=3", "" + HttpMethod.GET.name, "/sample/query?id=3", "" ) assertEquals( - "query with id:3", response.body, - "failed to get query param response" + "query with id:3", response.body, + "failed to get query param response" ) } @Test fun testGetPathParamWithWhitespace() { val restClientService = bluePrintRestLibPropertyService - .blueprintWebClientService("sample") + .blueprintWebClientService("sample") val response = restClientService.exchangeResource( - HttpMethod.GET.name, "/sample/path/id 3/get", "" + HttpMethod.GET.name, "/sample/path/id 3/get", "" ) assertEquals( - "path param id:id 3", response.body, - "failed to get query param response" + "path param id:id 3", response.body, + "failed to get query param response" ) } @@ -171,11 +173,11 @@ class RestClientServiceTest { @Test fun testSimpleBasicAuth() { val json: String = "{\n" + - " \"type\" : \"basic-auth\",\n" + - " \"url\" : \"http://localhost:9081\",\n" + - " \"username\" : \"admin\",\n" + - " \"password\" : \"jans\"\n" + - "}" + " \"type\" : \"basic-auth\",\n" + + " \"url\" : \"http://localhost:9081\",\n" + + " \"username\" : \"admin\",\n" + + " \"password\" : \"jans\"\n" + + "}" val mapper = ObjectMapper() val actualObj: JsonNode = mapper.readTree(json) val restClientService = bluePrintRestLibPropertyService @@ -203,13 +205,13 @@ class RestClientServiceTest { headers["X-TransactionId"] = "9999" headers["X-FromAppId"] = "AAI" val post1 = "{\n" + - " \"customer\": {\n" + - " \"global-customer-id\": \"ONSDEMOBJHKCustomer\",\n" + - " \"subscriber-name\": \"ONSDEMOBJHKCustomer\",\n" + - " \"subscriber-type\": \"CUST\",\n" + - " \"resource-version\": \"1552985011163\"\n" + - " }\n" + - "}" + " \"customer\": {\n" + + " \"global-customer-id\": \"ONSDEMOBJHKCustomer\",\n" + + " \"subscriber-name\": \"ONSDEMOBJHKCustomer\",\n" + + " \"subscriber-type\": \"CUST\",\n" + + " \"resource-version\": \"1552985011163\"\n" + + " }\n" + + "}" lateinit var res1: Customer lateinit var res2: Customer lateinit var res3: String @@ -307,11 +309,11 @@ open class SampleController { @GetMapping("/query") fun getQuery(@RequestParam("id") id: String): String = - "query with id:$id" + "query with id:$id" @GetMapping("/path/{id}/get") fun getPathParam(@PathVariable("id") id: String): String = - "path param id:$id" + "path param id:$id" @PatchMapping("/name") fun patchName(): String = "Patch request successful" @@ -330,11 +332,11 @@ open class SampleController { return "" } return "{\n" + - " \"id\": \"ONSDEMOBJHKCustomer\",\n" + - " \"name\": \"ONSDEMOBJHKCustomer\",\n" + - " \"type\": \"CUST\",\n" + - " \"resource\": \"1552985011163\"\n" + - "}" + " \"id\": \"ONSDEMOBJHKCustomer\",\n" + + " \"name\": \"ONSDEMOBJHKCustomer\",\n" + + " \"type\": \"CUST\",\n" + + " \"resource\": \"1552985011163\"\n" + + "}" } @PostMapping("/aai/v14/business/customers") |