Skip to content
Advertisement

Integration tests with WireMock failing because no ALPN Processors are found

I’m writing some integration tests for a Spring Boot application written in Kotlin. To stub some HTTP requests, I’m using WireMock via spring-cloud-contract-wiremock as dependency.

Some anonymized sample code from an integration test:

@SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureWireMock
class MyIntegrationTest { 

    @Test
    fun `some test`() {
        mockEndpoint("url", 500, someResponseBodyInJson)

        mockMvc.perform(
            MockMvcRequestBuilders
                .post("url")
                .contentType(MediaType.APPLICATION_JSON.toString())
                .content(someRequestBodyInJson)
        )
            .andExpect(MockMvcResultMatchers.status().isInternalServerError)
    }

    private fun mockEndpoint(url: String, responseCode: Int, responseBody: String) {
        stubFor(
            WireMock.post(url).willReturn(
                WireMock.aResponse()
                    .withStatus(responseCode)
                    .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString())
                    .withBody(responseBody)
            )
        )
    }

}

While running these tests on my local machine, everything is working fine. On the CI/CD environment it’s failing though with the following error:

java.lang.IllegalStateException: No Server ALPNProcessors!
at wiremock.org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory.<init>(ALPNServerConnectionFactory.java:52)

I did some searching and figured out is has to do with Jetty missing some things on the class path. I added the following dependency testImplementation("org.eclipse.jetty:jetty-alpn-server:11.0.7"), but the tests are still failing. The alpn-boot extension should not be necessary as JDK 11 is being used.

Anyone able to help me solve this? Do I need another dependency or am I looking in the wrong direction?

Advertisement

Answer

Wiremock team addressed this in version 2.32, there’s a ticket here. You need to specify a correct version for wiremock-jre8-standalone to override an older version pulled by Spring:

# Gradle
testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.32.0'

#Maven
<dependency>
    <groupId>com.github.tomakehurst</groupId>
    <artifactId>wiremock-jre8-standalone</artifactId>
    <version>2.32.0</version>
    <scope>test</scope>
</dependency>
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement