public void start() throws Exception { if (mockWebServer != null) throw new IllegalStateException(); mockWebServer = new MockWebServer(); mockWebServer.setDispatcher(this); mockWebServer.start(slackApi.port); }
public void run() throws IOException { MockWebServer server = new MockWebServer(); server.useHttps(sslContext.getSocketFactory(), false); server.setDispatcher(this); server.start(port); }
@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(); }
@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; }
@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; }
/** * A proxy method for MockWebServer dispatcher */ public void setDispatcher(Dispatcher dispatcher) { mockWebServer.setDispatcher(dispatcher); }
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); }
public MockWebServerWrapper(MockWebServer mockWebServer) { this.mockWebServer = mockWebServer; mockWebServer.setDispatcher(dispatcher()); }
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)); }
public LoginActivityTest() { server.setDispatcher(dispatcher); }
@NonNull private MockWebServer getMockWebServer(Dispatcher dispatcher) { MockWebServer mockWebServer = new MockWebServer(); mockWebServer.setDispatcher(dispatcher); return mockWebServer; }
protected MockWebServer getErrorMockWebServer() { mockWebServer.setDispatcher(new QueueDispatcher()); return mockWebServer; }
@After public void tearDown() throws Exception { mockWebServer.setDispatcher(dispatcher); mockWebServer.shutdown(); }
@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(""); }
@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(""); }
@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(); }
@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(""); }
@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(""); }
@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(""); }
@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(""); }