spring-cloud / spring-cloud-contract

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

WireMock fails to initialize when client has server.context-path property set #99

Closed yacekmm closed 8 years ago

yacekmm commented 8 years ago

When the client side, that is starting stubs from contract has the server.context-path property specified in its application.yml config file, then the WireMock fails to start. The problem occurs on adding a stub definitions to WireMock by POST http://localhost:8080/__admin/mappings/new since the WireMock url does not take the context-path into account.

Steps to reproduce:

  1. add server.context-path in spring-cloud-contract\samples\standalone\dsl\http-client\src\main\resources\application.yml:

server.context-path: /my-path

  1. Run LoanApplicationServiceTests

The result is:

com.github.tomakehurst.wiremock.client.VerificationException: Expected status 201 for http://localhost:8080/__admin/mappings/new but was 404

due to ignoring the context-path.

Is there any way to setup the context path in wiremock to fix this issue?

lesongjia commented 8 years ago

I ran into this issue as well. I am using 1.0.1.RELEASE for wiremock and stubruner. Is that the current version that has the fix in?

marcingrzejszczak commented 8 years ago

Yeah that's the one. Please double check that the proper version is used. Also try using the release train once it's out to be sure that all the versions are ok. if you still see the issue please upload a sample so that I can check it out

lesongjia commented 8 years ago

I tried the sample in master branch and update the contextPath to "/server" in http-server and I update the url to have "/server" in http-client. Then, I ran the tests in http-client. I got the same problem. I uploaded the sample in a zip.

The version for the tests are 1.0.2.BUILD-SNAPSHOT. dsl-sample.zip

marcingrzejszczak commented 8 years ago

That's disappointing. There's a test that proves that it's working. The property https://github.com/spring-cloud/spring-cloud-contract/blob/master/tests/spring-cloud-contract-stub-runner-context-path/src/main/resources/application.yml and the test https://github.com/spring-cloud/spring-cloud-contract/blob/master/tests/spring-cloud-contract-stub-runner-context-path/src/test/java/com/example/loan/LoanApplicationServiceTests.java . Can you spot the difference? I'll be able to check it out tomorrow myself

lesongjia commented 8 years ago

Thanks for your quick response, @marcingrzejszczak

Correct me if I am wrong, seems like the test you show me are testing the contextPath on the client.

My case is I have a contextPath set in server. Then, I make a fatJar for client test. The client can not find the correct path due to the missing contextPath on stub runner.

For example, I have a contextPath set to server as "/server", then my endpoint for "/fraudcheck" in server will be "/server/fraudcheck". I will try to hit this endpoint in my client service, for instance something like "http://localhost:8080/server/fraudcheck".

I always get an error says no matching for "/server/fraudcheck" and the closet endpoint is "/fraudcheck".

Let me know anything is not clear or I misunderstand something. Thanks

marcingrzejszczak commented 8 years ago

Ah so you're saying that the stubs are created with an improper URL. In that case we need a new issue right? Can you file it please?

lesongjia commented 8 years ago

Sure, I misunderstand this case. I will create a new issue. Thanks