diff --git a/core/model/src/main/kotlin/au/com/dius/pact/core/model/HttpPart.kt b/core/model/src/main/kotlin/au/com/dius/pact/core/model/HttpPart.kt index e4aae602a..a6278b1f4 100644 --- a/core/model/src/main/kotlin/au/com/dius/pact/core/model/HttpPart.kt +++ b/core/model/src/main/kotlin/au/com/dius/pact/core/model/HttpPart.kt @@ -114,7 +114,7 @@ abstract class HttpPart: IHttpPart { contentType.isBinaryType() || contentType.isMultipart() -> try { OptionalBody.body(decoder.decode(body), contentType) } catch (ex: IllegalArgumentException) { - logger.warn(ex) { "Expected body for content type $contentType to be base64 encoded" } + logger.warn { "Expected body for content type $contentType to be base64 encoded: ${ex.message}" } OptionalBody.body(body.toByteArray(contentType.asCharset()), contentType) } else -> OptionalBody.body(body.toByteArray(contentType.asCharset()), contentType) diff --git a/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/MvcProviderVerifier.kt b/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/MvcProviderVerifier.kt index da36f97a5..98eda9007 100644 --- a/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/MvcProviderVerifier.kt +++ b/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/MvcProviderVerifier.kt @@ -13,7 +13,7 @@ import au.com.dius.pact.provider.VerificationResult import groovy.lang.Binding import groovy.lang.Closure import groovy.lang.GroovyShell -import io.github.oshai.kotlinlogging.KLogging +import io.github.oshai.kotlinlogging.KotlinLogging import org.apache.commons.lang3.StringUtils import org.hamcrest.Matchers.anything import org.springframework.http.HttpHeaders @@ -39,6 +39,8 @@ import javax.mail.internet.ContentDisposition import javax.mail.internet.MimeMultipart import javax.mail.util.ByteArrayDataSource +private val logger = KotlinLogging.logger {} + /** * Verifies the providers against the defined consumers using Spring MockMvc */ @@ -60,8 +62,9 @@ open class MvcProviderVerifier(private val debugRequestResponse: Boolean = false val expectedResponse = interaction.response val actualResponse = handleResponse(mvcResult.response) + // TODO: Add any plugin configuration here verifyRequestResponsePact(expectedResponse, actualResponse, interactionMessage, failures, - interaction.interactionId.orEmpty(), false) + interaction.interactionId.orEmpty(), false, emptyMap()) } catch (e: Exception) { failures[interactionMessage] = e reporters.forEach { @@ -98,7 +101,7 @@ open class MvcProviderVerifier(private val debugRequestResponse: Boolean = false } else { MockMvcRequestBuilders.request(HttpMethod.valueOf(request.method), requestUriString(request)) .headers(mapHeaders(request, true)) - .content(body.value) + .content(body.value ?: ByteArray(0)) } } else { MockMvcRequestBuilders.request(HttpMethod.valueOf(request.method), requestUriString(request)) @@ -188,13 +191,16 @@ open class MvcProviderVerifier(private val debugRequestResponse: Boolean = false val headers = mutableMapOf>() httpResponse.headerNames.forEach { headerName -> - headers[headerName] = listOf(httpResponse.getHeader(headerName)) + val header = httpResponse.getHeader(headerName) + if (header != null) { + headers[headerName] = listOf(header) + } } val contentType = if (httpResponse.contentType.isNullOrEmpty()) { ContentType.JSON } else { - ContentType.fromString(httpResponse.contentType.toString()) + ContentType.fromString(httpResponse.contentType!!.toString()) } val response = ProviderResponse(httpResponse.status, headers, contentType, @@ -204,6 +210,4 @@ open class MvcProviderVerifier(private val debugRequestResponse: Boolean = false return response } - - companion object : KLogging() } diff --git a/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/SpringEnvironmentResolver.kt b/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/SpringEnvironmentResolver.kt index bade42998..57788b8df 100644 --- a/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/SpringEnvironmentResolver.kt +++ b/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/SpringEnvironmentResolver.kt @@ -7,15 +7,21 @@ import org.springframework.core.env.Environment class SpringEnvironmentResolver(private val environment: Environment) : ValueResolver { override fun resolveValue(property: String?): String? { val tuple = SystemPropertyResolver.PropertyValueTuple(property).invoke() - return environment.getProperty(tuple.propertyName, tuple.defaultValue) + return if (tuple.propertyName != null) + environment.getProperty(tuple.propertyName!!, tuple.defaultValue.orEmpty()) + else null } override fun resolveValue(property: String?, default: String?): String? { - return environment.getProperty(property, default) + return if (property != null) + environment.getProperty(property, default.orEmpty()) + else null } override fun propertyDefined(property: String): Boolean { val tuple = SystemPropertyResolver.PropertyValueTuple(property).invoke() - return environment.containsProperty(tuple.propertyName) + return if (tuple.propertyName != null) + environment.containsProperty(tuple.propertyName!!) + else false } } diff --git a/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/WebFluxProviderVerifier.kt b/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/WebFluxProviderVerifier.kt index ae193e999..0dada1b59 100644 --- a/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/WebFluxProviderVerifier.kt +++ b/provider/spring/src/main/kotlin/au/com/dius/pact/provider/spring/WebFluxProviderVerifier.kt @@ -30,7 +30,7 @@ import javax.mail.internet.ContentDisposition import javax.mail.internet.MimeMultipart import javax.mail.util.ByteArrayDataSource -val logger = KotlinLogging.logger {} +private val logger = KotlinLogging.logger {} class WebFluxProviderVerifier : ProviderVerifier() {