You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Version: knotx-junit5:1.5.0
When a mock server is created with the @KnotxWiremock annotation, the mapping methods withBody() and withBodyFile() of ResponseDefinitionBuilder are ignored and the mock tries to load a response from a file instead.
To Reproduce
Steps to reproduce the behavior:
Create a mock server, using @KnotxWiremock, eg. @KnotxWiremock(port = 4000) protected WireMockServer mockServer;
Create a mapping, using withBody() or withBodyFile(), eg. stubForServer(mockServer, get("/get-data.json") .willReturn(aResponse() .withStatus(HttpStatus.SC_OK) .withHeader("Content-Type", "application/json;charset=UTF-8") .withBody("custom response")));
Create a test that calls the defined endpoint, eg. with RestAssured: given() .when() .header("Content-Type", "application/json;charset=UTF-8") .then() .body(equalTo("custom response"));
The test fails because a file "get-data.json" is missing.
java.lang.AssertionError: 1 expectation failed.
Response body doesn't match expectation.
Expected: "custom response"
Actual: <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 500 Server Error</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /get-data.json. Reason:
<pre> Server Error</pre></p><h3>Caused by:</h3><pre>java.lang.IllegalArgumentException: resource get-data.json not found.
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:216)
at com.google.common.io.Resources.getResource(Resources.java:195)
at io.knotx.junit5.util.FileReader.readText(FileReader.java:33)
at io.knotx.junit5.util.FileReader.readTextSafe(FileReader.java:45)
at io.knotx.junit5.wiremock.KnotxFileSource.transform(KnotxFileSource.java:78)
at com.github.tomakehurst.wiremock.http.StubResponseRenderer.applyTransformations(StubResponseRenderer.java:73)
at com.github.tomakehurst.wiremock.http.StubResponseRenderer.render(StubResponseRenderer.java:52)
at com.github.tomakehurst.wiremock.http.AbstractRequestHandler.handle(AbstractRequestHandler.java:47)
at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.service(WireMockHandlerDispatchingServlet.java:108)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.servlets.gzip.GzipHandler.handle(GzipHandler.java:479)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:258)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:748)
</pre>
<hr><i><small>Powered by Jetty://</small></i><hr/>
</body>
</html>
Expected behavior
The test should pass, regardless of existence of a file "get-data.json", as the mapping has defined body response.
As a workaround, the mock server can be created without @KnotxWiremock and then the test is going to pass. protected WireMockServer mockServer; //... mockServer = new WireMockServer(4000); mockServer.start();
Screenshots
Additional context
A running test with the workaround:
Describe the bug
Version: knotx-junit5:1.5.0
When a mock server is created with the @KnotxWiremock annotation, the mapping methods withBody() and withBodyFile() of ResponseDefinitionBuilder are ignored and the mock tries to load a response from a file instead.
To Reproduce
Steps to reproduce the behavior:
@KnotxWiremock(port = 4000) protected WireMockServer mockServer;
stubForServer(mockServer, get("/get-data.json") .willReturn(aResponse() .withStatus(HttpStatus.SC_OK) .withHeader("Content-Type", "application/json;charset=UTF-8") .withBody("custom response")));
given() .when() .header("Content-Type", "application/json;charset=UTF-8") .then() .body(equalTo("custom response"));
Expected behavior
The test should pass, regardless of existence of a file "get-data.json", as the mapping has defined body response.
As a workaround, the mock server can be created without @KnotxWiremock and then the test is going to pass.
protected WireMockServer mockServer; //... mockServer = new WireMockServer(4000); mockServer.start();
Screenshots
Additional context
A running test with the workaround:
The text was updated successfully, but these errors were encountered: