Here are the examples of the java api com.google.mockwebserver.MockWebServer.play() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
17
Source : ExpatSaxParserTest.java
with Apache License 2.0
from lulululbj
with Apache License 2.0
from lulululbj
public void testExternalEnreplacedyDownload() throws IOException, SAXException {
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody("<bar></bar>"));
server.play();
clreplaced Handler extends DefaultHandler {
final List<String> elementNames = new ArrayList<String>();
@Override
public InputSource resolveEnreplacedy(String publicId, String systemId) throws IOException {
// The parser should have resolved the systemId.
replacedertEquals(server.getUrl("/systemBar").toString(), systemId);
return new InputSource(systemId);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) {
elementNames.add(localName);
}
@Override
public void endElement(String uri, String localName, String qName) {
elementNames.add("/" + localName);
}
}
// 'systemBar', the external enreplacedy, is relative to 'systemFoo':
Reader in = new StringReader("<?xml version=\"1.0\"?>\n" + "<!DOCTYPE foo [\n" + " <!ENreplacedY bar SYSTEM 'systemBar'>\n" + "]>\n" + "<foo>&bar;</foo>");
ExpatReader reader = new ExpatReader();
Handler handler = new Handler();
reader.setContentHandler(handler);
reader.setEnreplacedyResolver(handler);
InputSource source = new InputSource(in);
source.setSystemId(server.getUrl("/systemFoo").toString());
reader.parse(source);
replacedertEquals(Arrays.asList("foo", "bar", "/bar", "/foo"), handler.elementNames);
server.shutdown();
}
17
Source : URLConnectionBenchmark.java
with Apache License 2.0
from lulululbj
with Apache License 2.0
from lulululbj
protected void setUp() throws Exception {
readBuffer = new byte[readBufferSize];
server = new MockWebServer();
MockResponse response = new MockResponse();
responseHeaders.apply(response);
transferEncoding.setBody(response, bodySize, chunkSize);
// keep serving the same response for all iterations
server.setDispatcher(new SingleResponseDispatcher(response));
server.play();
url = server.getUrl("/");
// ensure the server has started its threads, etc.
get();
}
16
Source : HttpsURLConnectionTest.java
with Apache License 2.0
from lulululbj
with Apache License 2.0
from lulululbj
private static MockWebServer createServer(SSLContext ctx, Dispatcher dispatcher, boolean handleProxying) throws IOException {
MockWebServer webServer = new MockWebServer();
webServer.useHttps(ctx.getSocketFactory(), handleProxying);
webServer.setDispatcher(dispatcher);
webServer.play();
return webServer;
}
15
Source : OldCookieHandlerTest.java
with Apache License 2.0
from lulululbj
with Apache License 2.0
from lulululbj
public void test_get_put() throws Exception {
MockCookieHandler mch = new MockCookieHandler();
CookieHandler defaultHandler = CookieHandler.getDefault();
try {
CookieHandler.setDefault(mch);
server.play();
server.enqueue(new MockResponse().addHeader("Set-Cookie2: a=\"android\"; " + "Comment=\"this cookie is delicious\"; " + "CommentURL=\"http://google.com/\"; " + "Discard; " + "Domain=\"" + server.getCookieDomain() + "\"; " + "Max-Age=\"60\"; " + "Path=\"/path\"; " + "Port=\"80,443," + server.getPort() + "\"; " + "Secure; " + "Version=\"1\""));
URLConnection connection = server.getUrl("/path/foo").openConnection();
connection.getContent();
replacedertTrue(mch.wasGetCalled());
replacedertTrue(mch.wasPutCalled());
} finally {
CookieHandler.setDefault(defaultHandler);
}
}
14
Source : HttpsURLConnectionTest.java
with Apache License 2.0
from lulululbj
with Apache License 2.0
from lulululbj
/**
* Tests HTTPS connection process made through the proxy server.
* Proxy server needs authentication but client fails to authenticate
* (Authenticator was not set up in the system).
*/
public void testProxyAuthConnectionFailed() throws Throwable {
// set up the properties pointing to the key/trust stores
setUpStoreProperties();
// set the HostnameVerifier required to satisfy SSL - always returns "verified".
HttpsURLConnection.setDefaultHostnameVerifier(new TestHostnameVerifier());
// create a server that pretends to be both a proxy that requests authentication.
MockWebServer proxyAndWebServer = new MockWebServer();
ProxyConnectAuthFailDispatcher authFailDispatcher = new ProxyConnectAuthFailDispatcher();
proxyAndWebServer.setDispatcher(authFailDispatcher);
proxyAndWebServer.play();
// create HttpsURLConnection to be tested
URL proxyUrl = proxyAndWebServer.getUrl("/");
InetSocketAddress proxyAddress = new InetSocketAddress("localhost", proxyUrl.getPort());
URL url = new URL("https://requested.host:55555/requested.data");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, proxyAddress));
connection.setSSLSocketFactory(getContext().getSocketFactory());
// perform the interaction between the peers and check the results
try {
executeClientRequest(connection, false);
} catch (IOException e) {
// SSL Tunnelling failed
if (DO_LOG) {
System.out.println("Got expected IOException: " + e.getMessage());
}
}
proxyAndWebServer.shutdown();
}