本文整理匯總了Java中com.squareup.okhttp.mockwebserver.MockWebServer.setDispatcher方法的典型用法代碼示例。如果您正苦於以下問題:Java MockWebServer.setDispatcher方法的具體用法?Java MockWebServer.setDispatcher怎麽用?Java MockWebServer.setDispatcher使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.okhttp.mockwebserver.MockWebServer
的用法示例。
在下文中一共展示了MockWebServer.setDispatcher方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getApiInterface
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
public ApiInterface getApiInterface(MockWebServer mockWebServer) throws IOException {
mockWebServer.start();
TestUtils testUtils = new TestUtils();
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().equals("/users/" + TestConst.TEST_OWNER + "/repos")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/repos.json"));
} else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/branches")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/branches.json"));
} else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/contributors")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/contributors.json"));
}
return new MockResponse().setResponseCode(404);
}
};
mockWebServer.setDispatcher(dispatcher);
HttpUrl baseUrl = mockWebServer.url("/");
return ApiModule.getApiInterface(baseUrl.toString());
}
示例2: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
super.setUp();
server = new MockWebServer();
server.start();
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws
InterruptedException {
if (request.getPath().equals("/account/info")) {
return new MockResponse().setResponseCode(200)
.setBody(jsonReader.readString("json/user.json"));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
HttpUrl baseUrl = server.url("/");
service = ServiceCreator.createTestService(baseUrl.toString(),
UserService.class);
}
示例3: startServer
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
private MockWebServer startServer() throws IOException {
Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.WARNING);
MockWebServer server = new MockWebServer();
if (tls) {
SSLContext sslContext = SslContextBuilder.localhost();
server.useHttps(sslContext.getSocketFactory(), false);
server.setNpnEnabled(true);
server.setNpnProtocols(protocols);
}
final MockResponse response = newResponse();
server.setDispatcher(new Dispatcher() {
@Override public MockResponse dispatch(RecordedRequest request) {
return response;
}
});
server.play();
return server;
}
示例4: run
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
public void run() throws IOException {
MockWebServer server = new MockWebServer();
server.useHttps(sslContext.getSocketFactory(), false);
server.setDispatcher(this);
InetAddress address = HttpUtil.getHostAddress();
server.start(address,port);
System.out.println(String.format("Started server for: http://%s:%d/", address.getHostAddress(), port));
}
示例5: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
super.setUp();
server = new MockWebServer();
server.start();
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().equals("/users/" + TestConst.TEST_OWNER + "/repos")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/repos.json"));
} else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/branches")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/branches.json"));
} else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/contributors")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/contributors.json"));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
HttpUrl baseUrl = server.url("/");
apiInterface = ApiModule.getApiInterface(baseUrl.toString());
}
示例6: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
server = new MockWebServer();
server.start();
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().equals("/users/" + TestConst.TEST_OWNER + "/repos")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/repos"));
} else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/branches")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/branches"));
} else if (request.getPath().equals("/repos/" + TestConst.TEST_OWNER + "/" + TestConst.TEST_REPO + "/contributors")) {
return new MockResponse().setResponseCode(200)
.setBody(testUtils.readString("json/contributors"));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
HttpUrl baseUrl = server.url("/");
Retrofit.Builder builder = new Retrofit.Builder().
baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create());
apiInterface = builder.build().create(ApiInterface.class);
}
示例7: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
mockWebServer = new MockWebServer();
mockWebServer.setDispatcher(new SoapDispatcher().getDispatcher());
mockWebServer.start();
soapAdapterFactory = new SoapAdapterFactory.Builder<>()
.setEndpoint(mockWebServer.getUrl("").toString())
.enableDebug();
}
示例8: provideSlowWsMock
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@Provides
@Named("slow")
public MockWebServer provideSlowWsMock() {
MockWebServer mockWebServer = new MockWebServer();
mockWebServer.setDispatcher(new QueueDispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
Uninterruptibles.sleepUninterruptibly(3L, TimeUnit.SECONDS);
return super.dispatch(request);
}
});
return mockWebServer;
}
示例9: setUp
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
super.setUp();
server = new MockWebServer();
server.start();
final Dispatcher dispatcher = new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws
InterruptedException {
String p = request.getPath();
MockResponse response = new MockResponse().setResponseCode(200);
if (p.matches("/board/all.*") ||
p.matches("/board/moderator/all.*")) {
return response.setBody(jsonReader.readString
("json/bulletins.json"));
} else if (p.equals("/board") ||
p.equals("/board/" + BULLETIN_ID)) {
return response.setBody(jsonReader.readString
("json/ok.json"));
} else if (p.equals("/board/" + BULLETIN_ID + "/recipient")) {
return response.setBody(jsonReader.readString
("json/bull_recipients.json"));
} else if (p.equals("/subdivision/" + SUBDIV_ID +
"/children")) {
return response.setBody(jsonReader.readString
("json/desc_subdivision.json"));
} else if (p.equals("/roles")) {
return response.setBody(jsonReader.readString("json/roles" +
".json"));
} else if (p.equals("/subdivision/" + SUBDIV_ID + "/group")) {
return response.setBody(jsonReader.readString
("json/groups.json"));
}
return new MockResponse().setResponseCode(404);
}
};
server.setDispatcher(dispatcher);
HttpUrl baseUrl = server.url("/");
service = ServiceCreator.createTestService(baseUrl.toString(),
BulletinService.class);
}
示例10: getApiTestInstance
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
public static AppliveryTestApi getApiTestInstance(){
MockWebServer server = new MockWebServer();
server.setDispatcher(getMockwebserverDispatcherInstance());
return initializeApiclient(server);
}
示例11: getApiServiceInstance
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
public static AppliveryApiService getApiServiceInstance(){
MockWebServer server = new MockWebServer();
server.setDispatcher(getMockwebserverDispatcherInstance());
return initializeApiServiceClient(server);
}
示例12: runMockServer
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
private void runMockServer() throws IOException {
server = new MockWebServer();
server.setDispatcher(dispatcher);
server.start(0);
}
示例13: run
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
public void run() throws IOException {
MockWebServer server = new MockWebServer();
server.useHttps(sslContext.getSocketFactory(), false);
server.setDispatcher(this);
server.play(port);
}
示例14: setup
import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
@BeforeClass
public static void setup() throws IOException {
server = new MockWebServer();
dispatcher = new CustomDispatcher();
server.setDispatcher(dispatcher);
}