spring-cloud / spring-cloud-contract

Support for Consumer Driven Contracts in Spring
https://cloud.spring.io/spring-cloud-contract
Apache License 2.0
714 stars 437 forks source link

wiremock.server.port is not defined if port is not explicitly set or if it is set to 8080 #1920

Closed josephearl closed 11 months ago

josephearl commented 1 year ago

Describe the bug

In my test I have something like:

@AutoConfigureWireMock
@SpringBootTest(properties = {"some.url=http://localhost:${wiremock.server.port}"})

With this I get an error:

Could not resolve placeholder 'wiremock.server.port' in value "http://localhost:${wiremock.server.port}"

If I explicitly set a port in @AutoConfigureWireMock(port = 8765), even 0 to randomly allocate a port, then it works - except for if I explicitly set it to 8080 (the default), then it no longer works

This used to work with Spring Boot 2.7 / Spring 5

I would expect it to set the property value to 8080 which is the WireMock default

Using version 4.0.3 of spring-cloud-contract-wiremock

mohamed-asfour commented 7 months ago

Hello, it seems that this fix lead to undesired behaviour by defaulting the server port always to 8080 after setting it once to a random port. This block replaces the wiremock.server.port property even if it has been already set else { Map<String, Object> source = getWireMockSource(environment); source.put("wiremock.server.port", 8080); if (log.isDebugEnabled()) { log.debug("Registered WireMock server port property to the default <8080> value"); } } could you please be kind and have a look on this issue?

Thanks in Advance

marcingrzejszczak commented 7 months ago

Argh sorry. Can you open a new issue please? I guess as a workaround you should go with the dynamic approach.