mockserver-client-node icon indicating copy to clipboard operation
mockserver-client-node copied to clipboard

Request sequence not found

Open florinmoc-git opened this issue 3 years ago • 1 comments

Describe the issue The expectations are not met. The request is returned instead of a comparison of the two paths.

What you are trying to do I have a test where I expect 'authenticate' to be called before 'orders' (I'm using JUnit 4). Here's the code:

mockServer.verify(
    request().withPath("/users/v2/authenticate"),
    request().withPath("/data/v1/orders")
);

MockServer version 5.13.2

To Reproduce Steps to reproduce the issue:

  1. How you are running MockServer (i.e maven plugin, docker, etc) In a JUnit 4 test:
@BeforeClass
public static void startMockServer() {
    ConfigurationProperties.initializationClass(ExpectationInitializer.class.getName());
    ConfigurationProperties.logLevel("WARN");
    mockServer = ClientAndServer.startClientAndServer(9001);
}
  1. Code you used to create expectations
@Override
public Expectation[] initializeExpectations() {
    return new Expectation[]{
            new Expectation(
                    request()
                            .withMethod("POST")
                            .withPath("/users/v2/authenticate")
            )
                    .thenRespond(
                    response()
                            .withStatusCode(200)
                            .withBody(json("{\n" +
                                    "  \"ImpersonationToken\": \"string\",\n" +
                                    "  \"KeepAliveTimeout\": \"string\",\n" +
                                    "  \"User\": {\n" +
                                    "    \"Language\": \"string\",\n" +
                                    "    \"Institution\": \"string\",\n" +
                                    "    \"Permissions\": {\n" +
                                    "      \"ImportSlides\": true,\n" +
                                    "      \"SaveAnnotations\": true,\n" +
                                    "      \"SaveOwnAnnotations\": true,\n" +
                                    "      \"ModifySystemConfiguration\": true,\n" +
                                    "      \"UseLisDataApi\": true,\n" +
                                    "      \"ExportImages\": true\n" +
                                    "    },\n" +
                                    "    \"Id\": \"00000000-0000-0000-0000-000000000000\",\n" +
                                    "    \"Login\": \"string\",\n" +
                                    "    \"Domain\": \"string\",\n" +
                                    "    \"FullName\": \"string\",\n" +
                                    "    \"RawName\": \"string\"\n" +
                                    "  },\n" +
                                    "  \"UrlAccessString\": \"string\"\n" +
                                    "}"))
            ),
            new Expectation(
                    request()
                            .withMethod("POST")
                            .withPath("/data/v1/orders")
            )
                    .thenRespond(
                    response()
                            .withStatusCode(200)
            )
    };
}
  1. What error you saw Intermittently I get this error:
junit.framework.AssertionFailedError: Request sequence not found, expected:<[ {
  "path" : "/users/v2/authenticate"
}, {
  "path" : "/data/v1/orders"
} ]> but was:<{
  "body" : {
    "contentType" : "application/json",
    "type" : "JSON",
    "json" : {
      "Login" : "ServerAccount",
      "Password" : "Password"
    },
    "rawBytes" : "eyJMb2dpbiI6IlNDSFNlcnZlckFjY591bnQiLCJQYXNzd29yZCI6IlNlY3RyYVBBQ1M0dSJ9"
  },
  "headers" : {
    "Authorization" : [ "Basic U0NIU9VydmVyQWNjb3VudDpTZWN0cmFQQUNTNHU=" ],
    "content-length" : [ "54" ],
    "Accept" : [ "application/json" ],
    "Connection" : [ "Keep-Alive" ],
    "User-Agent" : [ "Apache-HttpClient/4.5.4 (Java/11.0.14.1)" ],
    "Host" : [ "localhost:9001" ],
    "Accept-Encoding" : [ "gzip,deflate" ],
    "Content-Type" : [ "application/json" ]
  },
  "keepAlive" : true,
  "method" : "POST",
  "path" : "/users/v2/authenticate",
  "secure" : false
}>

Expected behaviour To show that the calls were made in the right order

MockServer Log

at org.mockserver.client.MockServerClient.verify(MockServerClient.java:864)
at org.mockserver.client.MockServerClient.verify(MockServerClient.java:822)

florinmoc-git avatar May 26 '22 09:05 florinmoc-git

How do you know that the code being test isn't sometimes not sending the second request? Also I don't understand the description:

The expectations are not met. The request is returned instead of a comparison of the two paths.

I guess the only issue you'ree concerned about is that you think MockServer is not verifying it has received both requests in the specified order when you feel it has?

jamesdbloom avatar Aug 20 '22 20:08 jamesdbloom