use of okhttp3.mockwebserver.MockWebServer in project scribejava by scribejava.
the class OkHttpHttpClientTest method shouldSendPostRequest.
@Test
public void shouldSendPostRequest() throws Exception {
final String expectedResponseBody = "response body";
final String expectedRequestBody = "request body";
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
// request with body
OAuthRequest request = new OAuthRequest(Verb.POST, baseUrl.toString());
request.setPayload(expectedRequestBody);
Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, response.getBody());
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("POST", recordedRequest.getMethod());
assertEquals(expectedRequestBody, recordedRequest.getBody().readUtf8());
// request with empty body
request = new OAuthRequest(Verb.POST, baseUrl.toString());
response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, response.getBody());
recordedRequest = server.takeRequest();
assertEquals("POST", recordedRequest.getMethod());
assertEquals("", recordedRequest.getBody().readUtf8());
server.shutdown();
}
use of okhttp3.mockwebserver.MockWebServer in project scribejava by scribejava.
the class OkHttpHttpClientTest method shouldSendGetRequest.
@Test
public void shouldSendGetRequest() throws Exception {
final String expectedResponseBody = "response body";
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(expectedResponseBody));
server.start();
final HttpUrl baseUrl = server.url("/testUrl");
final OAuthRequest request = new OAuthRequest(Verb.GET, baseUrl.toString());
final Response response = oAuthService.execute(request, null).get(30, TimeUnit.SECONDS);
assertEquals(expectedResponseBody, response.getBody());
final RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET", recordedRequest.getMethod());
server.shutdown();
}
use of okhttp3.mockwebserver.MockWebServer in project spring-framework by spring-projects.
the class AbstractMockWebServerTestCase method setUp.
@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;
}
use of okhttp3.mockwebserver.MockWebServer in project spring-framework by spring-projects.
the class WebClientIntegrationTests method setup.
@Before
public void setup() {
this.server = new MockWebServer();
String baseUrl = this.server.url("/").toString();
this.webClient = WebClient.create(baseUrl);
}
use of okhttp3.mockwebserver.MockWebServer in project okhttp by square.
the class Benchmark method startServer.
private MockWebServer startServer() throws IOException {
Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.WARNING);
MockWebServer server = new MockWebServer();
if (tls) {
SslClient sslClient = SslClient.localhost();
server.useHttps(sslClient.socketFactory, false);
server.setProtocols(protocols);
}
final MockResponse response = newResponse();
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) {
return response;
}
});
server.start();
return server;
}
Aggregations