Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stubbing in @BeforeAll #2095

Open
ebcFlagman opened this issue Feb 1, 2024 · 5 comments
Open

Stubbing in @BeforeAll #2095

ebcFlagman opened this issue Feb 1, 2024 · 5 comments

Comments

@ebcFlagman
Copy link

ebcFlagman commented Feb 1, 2024

I'm currently upgrading to the latest spring-boot 3.x version and my tests fails now with the following exception:

wiremock.org.apache.hc.client5.http.HttpHostConnectException: Connect to http://localhost:8080 [localhost/127.0.0.1] failed: Connection refused

	at java.base/sun.nio.ch.Net.pollConnect(Native Method)
	at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
	at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:547)
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:602)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
	at java.base/java.net.Socket.connect(Socket.java:633)
	at wiremock.org.apache.hc.client5.http.socket.PlainConnectionSocketFactory$1.run(PlainConnectionSocketFactory.java:87)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at wiremock.org.apache.hc.client5.http.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:84)
	at wiremock.org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:148)
	at wiremock.org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:396)
	at wiremock.org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:158)
	at wiremock.org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:168)
	at wiremock.org.apache.hc.client5.http.impl.classic.ConnectExec.execute(ConnectExec.java:136)
	at wiremock.org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
	at wiremock.org.apache.hc.client5.http.impl.classic.ExecChainElement$1.proceed(ExecChainElement.java:57)
	at wiremock.org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ProtocolExec.java:175)
	at wiremock.org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
	at wiremock.org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:170)
	at wiremock.org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:75)
	at wiremock.org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:89)
	at com.github.tomakehurst.wiremock.client.HttpAdminClient.safelyExecuteRequest(HttpAdminClient.java:514)
	at com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:497)
	at com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:474)
	at com.github.tomakehurst.wiremock.client.HttpAdminClient.addStubMapping(HttpAdminClient.java:146)
	at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:418)
	at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:413)
	at com.github.tomakehurst.wiremock.client.WireMock.givenThat(WireMock.java:115)
	at com.github.tomakehurst.wiremock.client.WireMock.stubFor(WireMock.java:119)

My Test is annotated with

@AutoConfigureMockMvc
@AutoConfigureWireMock(port = 0)
@SpringBootTest(
    classes = ApplicationInitializer.class,
    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

In the @BeforeAll Method I stub the endpoints.

When I move the stubs into e.g. @BeforeEach everythink works fine.

Used dependency:
testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner:4.1.1'

When I use in addition the testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock:4.0.4' the tests run as before the upgrade.

@amidani-inovany
Copy link

I have the same issue, 4.0.x works fine 4.1.x generate this error, it's like the ramdom port ${wiremock.server.port} is the default one in the setup method (@BeforeAll)

@marcingrzejszczak
Copy link
Contributor

Please double check that you're using the latest version cause we did fix this problem

@ebcFlagman
Copy link
Author

I've update to the latest 4.1.2 version and got the error described in the description

@marcingrzejszczak
Copy link
Contributor

That's not good, we'll look into that ASAP.

@cbertoldi
Copy link

@marcingrzejszczak did you have a chance to look into this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants