https://linen.dev logo
#help
Title
# help
h

Harishkumar Kumar

01/11/2024, 7:02 PM
Hello Guys, quick question, I was trying to replace com.github.tomakehurstwiremock jre8 standalone2.35.1 with org.wiremockwiremock standalone3.3.1 however it does not work for spring boot 3 wiremock testing Is there anything deprecated when we moved to org.wiremock:wiremock-standalone?
t

Tom

01/12/2024, 2:37 PM
In most cases you should be able to just upgrade the dependency. When you say it doesn’t work, what do you mean specifically?
h

Harishkumar Kumar

01/12/2024, 2:52 PM
In my case the wiremock is integrated with cucumber and the mocks will start and shutdown for each use case, when. and my code is
Copy code
@CucumberContextConfiguration
@ContextConfiguration
@RunWith(Cucumber.class)
@CucumberOptions(
    plugin = {
      "pretty",
      "json:./build/reports/cucumber-reports/acceptance-test-results.json",
      "html:./build/reports/cucumber-reports/acceptance-test-results.html"
    },
    features = {"classpath:features"},
    extraGlue = "com.stepdefs")

// Spring server configuration
@AutoConfigureWebTestClient
@ActiveProfiles("actest")
@SpringBootTest(
    classes = NavigationApiApplication.class,
    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

// Wiremock config
// port = 0 sets a dynamic port:
// <https://cloud.spring.io/spring-cloud-contract/2.0.x/multi/multi__spring_cloud_contract_wiremock.html>
@AutoConfigureWireMock(
    port = 0,
    stubs = "file:src/test/resources/wiremock/mappings",
    files = "file:src/test/resources/wiremock")
public class LocalCucumberRunner {}
the above code uses dependencies like
Copy code
// Cucumber
testImplementation 'io.cucumber:cucumber-java:7.15.0'
testImplementation 'io.cucumber:cucumber-junit:7.15.0'
testImplementation 'io.cucumber:cucumber-spring:7.15.0'
testImplementation 'io.cucumber:cucumber-junit-platform-engine:7.15.0'
testImplementation group: 'io.cucumber', name: 'cucumber-html', version: '0.2.7'

// Wiremock
testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.35.1'
testImplementation("org.springframework.cloud:spring-cloud-contract-wiremock:4.0.3") {
    exclude module: 'wiremock-jre8-standalone'
}
It fails to load the spring context and fails when I replace with org.wiremock:wiremock-standalone 3.3.1
t

Tom

01/12/2024, 2:58 PM
You’ve got an old version of spring-cloud-contract-wiremock and you’ve still got the jre8 dependency in there
h

Harishkumar Kumar

01/12/2024, 3:05 PM
I tried with this combination
Copy code
testImplementation 'org.wiremock:wiremock-standalone:3.3.1'
testImplementation("org.springframework.cloud:spring-cloud-contract-wiremock:4.1.0") {
    exclude module: 'wiremock-jre8-standalone'
}
Hope this is latest
t

Tom

01/12/2024, 3:06 PM
The combination of dependencies you’ve shown should work as far as I know, but there are a lot of moving parts here so unfortunately I think it’s a case of digging into the specific errors being thrown and addressing them.
h

Harishkumar Kumar

01/12/2024, 3:10 PM
Suppressed: java.lang.IllegalStateException: ApplicationContext failure threshold (1) exceeded: skipping repeated attempt to load context for [WebMergedContextConfiguration@4c2ad035 testClass = com.discover.enterprise.web.nav.local.LocalCucumberRunner, locations = [], classes = [com.nav.SpringBootApplication], contextInitializerClasses = [], activeProfiles = ["actest"], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true", "server.port=0"], contextCustomizers = [org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@56b9402e, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@28a0fd6c, [ImportsContextCustomizer@4b7ab262 key = [org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration, org.springframework.cloud.contract.wiremock.WireMockRestTemplateConfiguration, org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration, org.springframework.cloud.contract.wiremock.WireMockConfiguration, org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientAutoConfiguration, org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration, org.springframework.boot.test.autoconfigure.web.reactive.WebTestClientAutoConfiguration]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@549621f3, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@293bb8a5, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@5cc69cfe, org.springframework.boot.test.context.SpringBootTestAnnotation@30fe89e9], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:145) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:130) at io.cucumber.spring.TestContextAdaptor.create(TestContextAdaptor.java:42) at io.cucumber.spring.SpringFactory.start(SpringFactory.java:121) at io.cucumber.core.runner.Runner.buildBackendWorlds(Runner.java:134) at io.cucumber.core.runner.Runner.runPickle(Runner.java:70) at io.cucumber.core.runtime.Runtime.lambda$executePickle$6(Runtime.java:107) at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:137) at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23) at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:137) at io.cucumber.core.runtime.Runtime.lambda$executePickle$7(Runtime.java:107) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:235) at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:123) at io.cucumber.core.runtime.Runtime.lambda$runFeatures$3(Runtime.java:89) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) at java.base/java.util.stream.SliceOps$1$1.accept(SliceOps.java:200) at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1602) at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129) at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) at io.cucumber.core.runtime.Runtime.runFeatures(Runtime.java:90) at io.cucumber.core.runtime.Runtime.lambda$run$0(Runtime.java:78) at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runFeatures$6(CucumberExecutionContext.java:148) at io.cucumber.core.runtime.CucumberExecutionContext.execute(CucumberExecutionContext.java:163) at io.cucumber.core.runtime.CucumberExecutionContext.runFeatures(CucumberExecutionContext.java:146)
the above exception is what I get
t

Tom

01/12/2024, 3:13 PM
Looks like you have a custom test runner in there so I think you’ll need to take a closer look at what that’s doing
h

Harishkumar Kumar

01/12/2024, 3:29 PM
I already pasted the code for custom runner
Copy code
@CucumberContextConfiguration
@ContextConfiguration
@RunWith(Cucumber.class)
@CucumberOptions(
    plugin = {
      "pretty",
      "json:./build/reports/cucumber-reports/acceptance-test-results.json",
      "html:./build/reports/cucumber-reports/acceptance-test-results.html"
    },
    features = {"classpath:features"},
    extraGlue = "com.stepdefs")

// Spring server configuration
@AutoConfigureWebTestClient
@ActiveProfiles("actest")
@SpringBootTest(
    classes = SpringBootApplication.class,
    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

// Wiremock config
// port = 0 sets a dynamic port:
// <https://cloud.spring.io/spring-cloud-contract/2.0.x/multi/multi__spring_cloud_contract_wiremock.html>
@AutoConfigureWireMock(
    port = 0,
    stubs = "file:src/test/resources/wiremock/mappings",
    files = "file:src/test/resources/wiremock")
public class LocalCucumberRunner {}
t

Tom

01/12/2024, 3:31 PM
Yes, but I can’t run your tests and set breakpoints to see what actual error is being thrown internally
6 Views