WireMock stub creation fails: expects 201 but gets 200

482 views
Skip to first unread message

Jos Roseboom

unread,
Apr 29, 2015, 2:52:19 AM4/29/15
to wiremo...@googlegroups.com

Hi,

I am new to WireMock and trying to get my first unit test to work with it. Now, following the docs on wiremock.org, I wrote this

 
WireMockConfiguration config = wireMockConfig().port(9089).httpsPort(8443);
m_wireMockServer
= new WireMockServer(config);
m_wireMockServer
.start();
WireMock.configureFor("localhost", 9089);
givenThat
(get(urlEqualTo("/some/thing"))
 
.willReturn(aResponse()
 
.withHeader("Content-Type", "text/plain")
 
.withBody("Hello world!")));

I expect this to make any http request to /some/thing to be caught. It gives me the following exception on the giventhat call:

com.github.tomakehurst.wiremock.client.VerificationException: Expected status 201 for http://localhost:9089/__admin/mappings/new but was 200
at com
.github.tomakehurst.wiremock.client.HttpAdminClient.postJsonAssertOkAndReturnBody(HttpAdminClient.java:151)
at com
.github.tomakehurst.wiremock.client.HttpAdminClient.addStubMapping(HttpAdminClient.java:65)
at com
.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:130)
at com
.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:126)
at com
.github.tomakehurst.wiremock.client.WireMock.givenThat(WireMock.java:65)

What did I miss? What is wrong in the creation of the stub?

Regards,
Jos

Tom Akehurst

unread,
May 5, 2015, 4:04:13 PM5/5/15
to wiremo...@googlegroups.com
Weird, not seen that before.

Are on running the latest version?

Jos Roseboom

unread,
May 6, 2015, 4:04:06 AM5/6/15
to wiremo...@googlegroups.com
Hi,

Thanks for your response. I am running on version 1.55, which is the latest version.

Inspecting the code from the stacktrace via https://github.com/tomakehurst/wiremock/blob/master/src/main/java/com/github/tomakehurst/wiremock/client/HttpAdminClient.java I can see that postJsonAssertOkAndReturnBody (line 142) is called with the expected status 201/HTTP_CREATED from line 65. Status 200 is returned, so an Exception is thrown. What I do not understand is why the expected status is 201. Returning 200 does not seem an error to me. Why should this be 201?

Tom Akehurst

unread,
May 7, 2015, 2:54:58 PM5/7/15
to wiremo...@googlegroups.com, josro...@gmail.com
It should be a 201 because that's the only OK response the mappings/new endpoint will return. There's no code path that should result in a 200, so this is strange behaviour. Is there any chance you're accidentally talking to another web service (I know I've done this in the past!).
Reply all
Reply to author
Forward
0 new messages