-
Notifications
You must be signed in to change notification settings - Fork 72
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
Use mock http servers from okhttp #1441
Use mock http servers from okhttp #1441
Conversation
riptide-failsafe/src/test/java/org/zalando/riptide/failsafe/MockWebServerUtil.java
Show resolved
Hide resolved
|
||
reference.set(URI.create("http://www.example.net/")); | ||
http.get().call(pass()).join(); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously invocation was to real pages http://www.example.net/ and http://www.example.org/, so part
driver.addExpectation(
onRequestTo("http://www.example.org/"),
giveEmptyResponse());
wasn't actually used
I've changed the test to use the same base URL but different paths (/path1
and /path2
). Another approach would involve continuing to use the pages http://www.example.net/ and http://www.example.org/ while completely removing the mock server from this test. However, it is not clear how to verify in this scenario that the URL has changed between invocations.
.withHeader("X-Content-Encoding", "gzip") // written by Jetty's GzipHandler | ||
.withBody(equalTo("{}"), "application/json"), | ||
giveResponse("", "text/plain")); | ||
server.enqueue(textMockResponse("")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot use Jetty's GzipHandler
anymore, so we cannot test header inserted by it (X-Content-Encoding
).
I'm checking header inserted by the plugin and that body was actually compressed (by decompressing it and checking the result)
Thank you for your contribution! |
👍 |
Description
com.github.restdriver.clientdriver.ClientDriver
as mock web server were migrated tookhttp3.mockwebserver.MockWebServer
instead.MockWebServerUtil
util class was introduced to simplify migration and add functionality missing in the newokhttp3.mockwebserver.MockWebServer
.MockWebServerUtil
class is duplicated across modules and can be reviewed only in one place. The same duplication approach was used for the existingMockSetup
class. In the future we can avoid copying and pasting them by introducing a new project module that will be used only with the test scope (see discussion Use mock http servers from okhttp #1441 (comment)).com.github.restdriver.clientdriver.ClientDriver
allows you to define response for a specific request and then useverify()
method to ensure that driver got this exact request. Forokhttp3.mockwebserver.MockWebServer
you usually define common response for all possible requests, then check the request you actually got (usingserver.takeRequest(...)
method). Multipleverify()
methods were added toMockWebServerUtil
class to simplify such check. See https://github.com/zalando/riptide/pull/1441/files#diff-c2b11cfb53a03add49f5f20b1efdbd3c238230a2ec547eed41218d6c8dbdfff6R95 for a simple example of old validation vs new validation.Motivation and Context
Fixes #1392.
Migration to the new mock test server is required because
com.github.restdriver.clientdriver.ClientDriver
doesn't support latest Jetty version and thus blocks migration to the Spring Boot 3 & Spring 6.Different alternatives were analysed and discussed in the task, see #1392 (comment) for more details.
Types of changes
Checklist: