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

RequestBody actual and expected not equal due to added value to the expected value #147

Open
3nterAUs3rname opened this issue Aug 8, 2024 · 2 comments
Labels

Comments

@3nterAUs3rname
Copy link

Hello,

I'm in need of some help with the following: Upon verifying the actual body content to be equal to the expected I run into the following issue:

image

So the only difference here is the [equalTo] value, making my test fail.

Below is part of my test setup where equalTo() is being used inside the withRequestBody().

@QuarkusIntegrationTest
@ConnectWireMock
public class MYTestIT {
private static final String ENTITY_SAMPLE =
        ( "Entity{entity=<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
            + "<SOAP-ENV:Header><requestingParty xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">12345678"
            + "</requestingParty></SOAP-ENV:Header><SOAP-ENV:Body SOAP-ENV:encodingStyle=\"UTF-8\"><note>\n"
            + "<to>Tove</to>\n"
            + "<from>Jani</from>\n"
            + "<heading>Reminder</heading>\n"
            + "<body>Don't forget me this weekend!</body>\n"
            + "</note></SOAP-ENV:Body></SOAP-ENV:Envelope>, variant=Variant[mediaType=application/xml;charset=UTF-8, language=null, encoding=null], annotations=[]}" );

@Test
    void requestBodyTest() {
        // Call expected to get triggered
        wireMock.register( post( urlEqualTo( "/my/url" ) ).willReturn( aResponse()
            .withStatus( Response.Status.OK.getStatusCode() )
            .withHeader( "Content-Type", MediaType.APPLICATION_XML )
            .withBody( "<somexml/>" ) ) );
        
        // Call to eventually trigger call above
        given()
            .auth().preemptive().basic( "john.doe", "password" )
            .post( "/api/v2/uploads" )
            .then()
            .statusCode( RestResponse.StatusCode.CREATED );
        
        // Asserting the requestbody of the triggered request to equal ENTITY_SAMPLE
        wireMock.verifyThat( postRequestedFor( urlEqualTo( "/my/url" ) ).withRequestBody( equalTo( ENITTY_SAMPLE ) ) );
        
        }
    }

I've tried multiple variants with contains(), matching(...), but often with the same result.

Looking forward to your response.

@3nterAUs3rname 3nterAUs3rname changed the title RequestBody actual and expected not equal due to added value to the expected avlue RequestBody actual and expected not equal due to added value to the expected value Aug 8, 2024
@diversit
Copy link

There seem to be other issues with the test.

  • the post does not seem to post a body so I do not understand how the result in the screen shot occur.
  • the status returned by the Wiremock response is 'OK' whereas the resulting status code is verified to be 'CREATED'.

Personally I have never used the 'verifyThat' of WireMock. I prefer verify the response given by the mock.
So after then().statusCode(..) I would verify the returned body (in this case: "").

Copy link

@quarkiverse/quarkiverse-wiremock This is being labeled as stale.

@github-actions github-actions bot added the Stale label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants