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

withRequestBody not working as expected #106

Closed
ghost opened this Issue Mar 6, 2014 · 4 comments

Comments

Projects
None yet
1 participant
@ghost

ghost commented Mar 6, 2014

I am attempting to use wiremock alongside dropwizard 0.6.2. I start my simple dropwizard service using a class rule and i start Wiremock using code (this is so i can transfer to cucumber testing when my junits are working).

I have attempted to confirm my request body using both the stubFor approach and the verify approach - the output appears to be gibberish. I know the call works because a i wrote a further dropwizard service that accepts the response successfully - i am wondering if there is a classpath conflict with dropwizard.

@Before
public void setUp() throws Exception {

    wireMockServer = new WireMockServer(wireMockConfig().port(7000));
    configureFor("localhost", 7000);
    wireMockServer.start();
    myWibble = new MyWibble();
    myWibble.setString1("str1");
    myWibble.setString2("str2");       
    json = mapper.writeValueAsString(myWibble);
}

@Test
public void postTest() throws Exception {

    stubFor(post(urlEqualTo("/your/resource"))
            .withHeader("Content-Type", equalTo(MediaType.APPLICATION_JSON))
            .withRequestBody(equalToJson(json, JSONCompareMode.LENIENT))
            .willReturn(aResponse().withStatus(200))
    );
    Client myClient = Client.create();
    WebResource resource = myClient.resource("http://localhost:7001");
    ClientResponse response = resource.path("my").path("resource").type(MediaType.APPLICATION_JSON).entity(myWibble).post(ClientResponse.class);
    assertThat(response.getStatus(), CoreMatchers.equalTo(200));
    verify(1,postRequestedFor(urlEqualTo("/your/resource"))
            .withHeader("Content-Type", equalTo(MediaType.APPLICATION_JSON)));
}

INFO [2014-03-06 21:04:42,109] com.github.tomakehurst.wiremock.common.Log4jNotifier: URL /your/resource is match, but body is not: ����������«V*.)ÊÌK7T²�± �t �F��#¥Z�±�R�#���

@ghost

This comment has been minimized.

ghost commented Mar 6, 2014

Sorry should have included the dropwizard code thats actually calling the mock !!

@POST
public Response postResponse( MyWibble myWibble ) { 
    WebResource resource = this.client.resource("http://localhost:7000");
    ClientResponse response = 
            resource.path("your").path("resource")
                    .entity(myWibble, MediaType.APPLICATION_JSON)
                    .post(ClientResponse.class);
    return Response.noContent().status(response.getStatus()).build();
}

@ghost ghost closed this Mar 6, 2014

@ghost ghost reopened this Mar 6, 2014

@ghost ghost closed this Mar 6, 2014

@ghost ghost reopened this Mar 6, 2014

@ghost

This comment has been minimized.

ghost commented Mar 7, 2014

this seems to be an issue with the Jersey Client - i wrote a simple test using the bog standard http client and that works - when i then run the same test using the jersey client i get my failure. I am wondering if there is a setting in the jersey client that needs to be set

@ghost

This comment has been minimized.

ghost commented Mar 7, 2014

Dropwizard turns on gzip by default and this is why verify wasn't working - for testing purposes we have turned it off and all is good.

@ghost ghost closed this Mar 7, 2014

@tomakehurst

This comment has been minimized.

Owner

tomakehurst commented Mar 7, 2014

Glad to hear you got it sorted :-)

I've had exactly the same problem with the Jersey client.

This issue was closed.

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