本文整理了Java中okhttp3.mockwebserver.MockWebServer.setDispatcher()
方法的一些代码示例,展示了MockWebServer.setDispatcher()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockWebServer.setDispatcher()
方法的具体详情如下:
包路径:okhttp3.mockwebserver.MockWebServer
类名称:MockWebServer
方法名:setDispatcher
[英]Sets the dispatcher used to match incoming requests to mock responses. The default dispatcher simply serves a fixed sequence of responses from a #enqueue(MockResponse); custom dispatchers can vary the response based on timing or the content of the request.
[中]设置用于将传入请求与模拟响应匹配的调度程序。默认的调度程序只是为来自#排队(MockResponse)的固定响应序列提供服务;自定义调度器可以根据时间或请求内容更改响应。
代码示例来源:origin: square/okhttp
public void start() throws Exception {
if (mockWebServer != null) throw new IllegalStateException();
mockWebServer = new MockWebServer();
mockWebServer.setDispatcher(this);
mockWebServer.start(slackApi.port);
}
代码示例来源:origin: square/okhttp
public void run() throws IOException {
MockWebServer server = new MockWebServer();
server.useHttps(sslContext.getSocketFactory(), false);
server.setDispatcher(this);
server.start(port);
}
代码示例来源:origin: ctripcorp/apollo
@Override
protected void before() throws Throwable {
clear();
server = new MockWebServer();
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().startsWith("/notifications/v2")) {
String notifications = request.getRequestUrl().queryParameter("notifications");
return new MockResponse().setResponseCode(200).setBody(mockLongPollBody(notifications));
} else if (request.getPath().startsWith("/configs")) {
List<String> pathSegments = request.getRequestUrl().pathSegments();
// appId and cluster might be used in the future
String appId = pathSegments.get(1);
String cluster = pathSegments.get(2);
String namespace = pathSegments.get(3);
return new MockResponse().setResponseCode(200).setBody(loadConfigFor(namespace));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
server.start();
mockConfigServiceUrl("http://localhost:" + server.getPort());
super.before();
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setUp() throws Exception {
this.server = new MockWebServer();
this.server.setDispatcher(new TestDispatcher());
this.server.start();
this.port = this.server.getPort();
this.baseUrl = "http://localhost:" + this.port;
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setUp() throws Exception {
this.server = new MockWebServer();
this.server.setDispatcher(new TestDispatcher());
this.server.start();
this.port = this.server.getPort();
this.baseUrl = "http://localhost:" + this.port;
}
代码示例来源:origin: orhanobut/mockwebserverplus
/**
* A proxy method for MockWebServer dispatcher
*/
public void setDispatcher(Dispatcher dispatcher) {
mockWebServer.setDispatcher(dispatcher);
}
代码示例来源:origin: fabric8io/mockwebserver
public DefaultMockServer(Context context, MockWebServer server, Map<ServerRequest, Queue<ServerResponse>> responses, Dispatcher dispatcher, boolean useHttps) {
this.context = context;
this.useHttps = useHttps;
this.server = server;
this.responses = responses;
this.server.setDispatcher(dispatcher);
}
代码示例来源:origin: com.vmware.card-connectors/core-test
public MockWebServerWrapper(MockWebServer mockWebServer) {
this.mockWebServer = mockWebServer;
mockWebServer.setDispatcher(dispatcher());
}
代码示例来源:origin: fabric8io/mockwebserver
public DefaultMockServer(Context context, MockWebServer server, Map<ServerRequest, Queue<ServerResponse>> responses, boolean useHttps) {
this.context = context;
this.useHttps = useHttps;
this.server = server;
this.responses = responses;
this.server.setDispatcher(new MockDispatcher(responses));
}
代码示例来源:origin: schaal/ocreader
public LoginActivityTest() {
server.setDispatcher(dispatcher);
}
代码示例来源:origin: ragdroid/mockstar
@NonNull
private MockWebServer getMockWebServer(Dispatcher dispatcher) {
MockWebServer mockWebServer = new MockWebServer();
mockWebServer.setDispatcher(dispatcher);
return mockWebServer;
}
代码示例来源:origin: ragdroid/mockstar
protected MockWebServer getErrorMockWebServer() {
mockWebServer.setDispatcher(new QueueDispatcher());
return mockWebServer;
}
代码示例来源:origin: ragdroid/mockstar
@After
public void tearDown() throws Exception {
mockWebServer.setDispatcher(dispatcher);
mockWebServer.shutdown();
}
代码示例来源:origin: mapbox/mapbox-java
@Before
public void setUp() throws Exception {
final String json = loadJsonFixture(OPTIMIZATION_FIXTURE);
object = new JsonParser().parse(json).getAsJsonObject();
server = new MockWebServer();
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
return new MockResponse().setBody(json);
}
});
server.start();
mockUrl = server.url("");
}
代码示例来源:origin: mapbox/mapbox-java
@Before
public void setUp() throws Exception {
final String json = loadJsonFixture(OPTIMIZATION_FIXTURE);
object = new JsonParser().parse(json).getAsJsonObject();
server = new MockWebServer();
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
return new MockResponse().setBody(json);
}
});
server.start();
mockUrl = server.url("");
}
代码示例来源:origin: cloudant/java-cloudant
@BeforeEach
public void setupMockWebServer() throws Exception {
mockWebServer = mockWebServerExt.get();
// Set a dispatcher that always returns 200 OK
mockWebServer.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
return new MockResponse();
}
});
client = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer)
.build();
}
代码示例来源:origin: mapbox/mapbox-java
@Before
public void setUp() throws IOException {
server = new MockWebServer();
server.setDispatcher(new okhttp3.mockwebserver.Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
try {
String body = loadJsonFixture(DIRECTIONS_V5_FIXTURE);
return new MockResponse().setBody(body);
} catch (IOException ioException) {
throw new RuntimeException(ioException);
}
}
});
server.start();
mockUrl = server.url("");
}
代码示例来源:origin: mapbox/mapbox-java
@Before
public void setUp() throws IOException {
server = new MockWebServer();
server.setDispatcher(new okhttp3.mockwebserver.Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
try {
String body = loadJsonFixture("versions.json");
return new MockResponse().setBody(body);
} catch (IOException ioException) {
throw new RuntimeException(ioException);
}
}
});
server.start();
mockUrl = server.url("");
}
代码示例来源:origin: mapbox/mapbox-java
@Before
public void setUp() throws IOException {
mockWebServer = new MockWebServer();
mockWebServer.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
okio.Buffer buffer = new okio.Buffer();
try {
buffer.writeAll(Okio.source(new File("src/test/resources/test_response.mp3")));
} catch (IOException ioException) {
throw new RuntimeException(ioException);
}
return new MockResponse().setBody(buffer);
}
});
mockWebServer.start();
mockUrl = mockWebServer.url("");
}
代码示例来源:origin: mapbox/mapbox-java
@Before
public void setUp() throws IOException {
server = new MockWebServer();
server.setDispatcher(new okhttp3.mockwebserver.Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
String resource = OPTIMIZATION_FIXTURE;
try {
String body = loadJsonFixture(resource);
return new MockResponse().setBody(body);
} catch (IOException ioException) {
throw new RuntimeException(ioException);
}
}
});
server.start();
mockUrl = server.url("");
}
内容来源于网络,如有侵权,请联系作者删除!