Wiremock: JavaDocs and docs explaining what server and client do? (How to interact with several WireMock servers?)

Created on 2 Apr 2014  路  10Comments  路  Source: tomakehurst/wiremock

Are there any JavaDocs available for WireMock (i.e. to tell you what exactly WireMockServer.stop() does, without having to look at the source code)?

Or documentation that explains how the server and client work together (i.e. what each one's tasks are)? Or docs containing hints to nuggets such as https://github.com/tomakehurst/wiremock/issues/18#issuecomment-14923087

I'm particularly interested if you can interact with several WireMockServers in the same unit test, e.g. a localhost and two remote ones...

Most helpful comment

There aren't any JavaDocs. I don't find they're a particularly good way to document DSLs.

They help a lot in IDEs.

All 10 comments

There aren't any JavaDocs. I don't find they're a particularly good way to document DSLs.

Agree the main docs ought to have a section on configuring the client in a bit more detail.

There are a couple of ways you can talk to multiple servers. If you're using JUnit and want to run everything in-JVM, then you can just use multiple rules e.g.

@Rule
public WireMockRule rule1 = new WireMockRule(wireMockConfig().port(8080));

@Rule
public WireMockRule rule2 = new WireMockRule(wireMockConfig().port(8081));

@Test
public void my_test() {
  rule1.stubFor(...);
  rule2.stubFor(...);
}

Alternatively, if you're running a remote WireMock server and just want to talk to it from your tests, then you can take the approach in the comment you linked to:

WireMock wireMock = new WireMock("my.remote.host", "8888");
wireMock.register(get(urlEqualTo("/thing"))....

Thanks, @tomakehurst, that's already really helpful! :)
But at the same time it showed me again that I really need a bit of docs that tells me what your different objects do and what the server's and client's responsibility is, respectively...

Uhm, actually, just out of curiosity: when (i.e. where in the code) is the client actually sending the new rule to the (local or remote) server for registration?

It's sent immediately and synchronously in the register method (or stubFor or givenThat). These methods delegate to an impl of the Admin interface, which currently always sends the command over HTTP, whether it's local or remote.

Hi tomakehurst

I found that wiremock standalone app always take request body in json format but my server reads the request body in Hashmap. Is there any work around for that?

Can I suggest you post the details of your setup on the mailing list with a description of the problem you're seeing?

There aren't any JavaDocs. I don't find they're a particularly good way to document DSLs.

They help a lot in IDEs.

The client code that @tomakehurst added above:

WireMock wireMock = new WireMock("my.remote.host", "8888");
wireMock.register(get(urlEqualTo("/thing"))....

...was real helpful. Would love to see that in the doc.

I'm about to give the docs a fairly major overhaul. Agree this needs to be in there, so I'll include it.

In new docs.

Was this page helpful?
0 / 5 - 0 ratings