Wiremock issue when upgrading to java 17

1.3k Views Asked by At

We have our application using Spring Boot 2.7 with Java 8. It's a restful service that uses JAX-RS with Jersey for implementation. I am now trying to move to Java 17 and the Application is working as expected but we have some junit test cases that use wiremock and they are failing. I tried to upgrade the version of Wiremock but still had no success. We are currently using com.github.tomakehurst:wiremock-jre8:2.35.0. It's working completely fine with Java 8 but not with Java 17. I tried com.github.tomakehurst:wiremock-jre8:3.0.0, com.github.tomakehurst:wiremock:3.0.0 and all major versions from new packages like org.wiremock:wiremock:3.0.4.

I read there are issues due to javax/jakarta namespace change and using stand-alone package might help but in my case, I am getting errors with that as well. As I have not upgraded my spring boot version to 3 or above I am still using javax package.

After trying for many weeks I decided to upgrade to spring boot 3 and again after doing all the changes (Including changes related to jakarta namespace) everything started working and still wiremock dosn't. I again tried diffrent packages and versions of wiremock like 2.27.2, 3.0.4, 3.1.0, 3.2.0, 3.3.0 with both normal as well as stand alone packages.

This is how we are mocking.

public void stubDelete(String url, int status) {
        WireMock.stubFor(delete(urlEqualTo(url))
            .willReturn(aResponse()
                .withHeader("Content-Type", "application/json")
                .withStatus(status))
            );
    }

I get the following error.

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@3fc064cb testClass = com.test.IntegrationTest, locations = [], classes = [com.test.Application], contextInitializerClasses = [], activeProfiles = ["test"], propertySourceLocations = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true", "server.port=0"], contextCustomizers = [org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@23f5b5dc, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@5db6b9cd, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@4dc27487, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@f58853c, org.springframework.boot.test.context.SpringBootTestAnnotation@ce740854], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
.
.
.
Caused by: java.lang.ArithmeticException: long overflow

Can someone help me understand why we get this error and how to resolve it?

0

There are 0 best solutions below