當前位置: 首頁>>代碼示例>>Java>>正文


Java MockWebServer.setDispatcher方法代碼示例

本文整理匯總了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());
}
 
開發者ID:andrey7mel,項目名稱:android-step-by-step,代碼行數:27,代碼來源:IntegrationApiModule.java

示例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);
}
 
開發者ID:kpi-ua,項目名稱:ecampus-client-android,代碼行數:22,代碼來源:UserServiceTest.java

示例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;
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:22,代碼來源:Benchmark.java

示例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));
}
 
開發者ID:alexclin0188,項目名稱:httplite,代碼行數:9,代碼來源:SampleServer.java

示例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());
}
 
開發者ID:andrey7mel,項目名稱:android-step-by-step,代碼行數:29,代碼來源:ApiInterfaceTest.java

示例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);
}
 
開發者ID:andrey7mel,項目名稱:android-simple-architecture,代碼行數:33,代碼來源:ApiInterfaceTest.java

示例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();
}
 
開發者ID:moltak,項目名稱:Rx-Soap,代碼行數:11,代碼來源:MockServerTest.java

示例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;
}
 
開發者ID:avarabyeu,項目名稱:restendpoint,代碼行數:14,代碼來源:GuiceTestModule.java

示例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);
}
 
開發者ID:kpi-ua,項目名稱:ecampus-client-android,代碼行數:42,代碼來源:BulletinServiceTest.java

示例10: getApiTestInstance

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
public static AppliveryTestApi getApiTestInstance(){
  MockWebServer server = new MockWebServer();
  server.setDispatcher(getMockwebserverDispatcherInstance());
  return initializeApiclient(server);
}
 
開發者ID:applivery,項目名稱:applivery-android-sdk,代碼行數:6,代碼來源:MockAppliveryInstance.java

示例11: getApiServiceInstance

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
public static AppliveryApiService getApiServiceInstance(){
  MockWebServer server = new MockWebServer();
  server.setDispatcher(getMockwebserverDispatcherInstance());
  return initializeApiServiceClient(server);
}
 
開發者ID:applivery,項目名稱:applivery-android-sdk,代碼行數:6,代碼來源:MockAppliveryInstance.java

示例12: runMockServer

import com.squareup.okhttp.mockwebserver.MockWebServer; //導入方法依賴的package包/類
private void runMockServer() throws IOException {
  server = new MockWebServer();
  server.setDispatcher(dispatcher);
  server.start(0);
}
 
開發者ID:cfg4j,項目名稱:cfg4j,代碼行數:6,代碼來源:ConsulConfigurationSourceIntegrationTest.java

示例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);
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:7,代碼來源:SampleServer.java

示例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);
}
 
開發者ID:outbrain,項目名稱:ob1k,代碼行數:7,代碼來源:ClientBasicFlowsTest.java


注:本文中的com.squareup.okhttp.mockwebserver.MockWebServer.setDispatcher方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。