com.undefinedlabs.scope.rules.ScopeMockWebServer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scope-rules-testing Show documentation
Show all versions of scope-rules-testing Show documentation
Scope is a APM for tests to give engineering teams unprecedented visibility into their CI process to quickly identify, troubleshoot and fix failed builds.
This artifact contains classes that supports Testing in the other Scope Rules modules.
package com.undefinedlabs.scope.rules;
import okhttp3.mockwebserver.Dispatcher;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import java.io.IOException;
public class ScopeMockWebServer {
private static MockWebServer MOCK_WEB_SERVER;
public static void start() {
try {
MOCK_WEB_SERVER = new MockWebServer();
MOCK_WEB_SERVER.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest recordedRequest) throws InterruptedException {
System.out.println("Captured request to MockWebServer. RequestURL: "+recordedRequest.getRequestUrl()+", Headers: " + recordedRequest.getHeaders());
return new MockResponse().setResponseCode(200);
}
});
MOCK_WEB_SERVER.start();
} catch(IOException e){
throw new RuntimeException(e);
}
}
public static String url(final String path) {
return MOCK_WEB_SERVER.url(path).toString();
}
public static void shutdown() {
try {
MOCK_WEB_SERVER.shutdown();
} catch(IOException e){
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy