本文整理汇总了Java中com.google.mockwebserver.RecordedRequest类的典型用法代码示例。如果您正苦于以下问题:Java RecordedRequest类的具体用法?Java RecordedRequest怎么用?Java RecordedRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RecordedRequest类属于com.google.mockwebserver包,在下文中一共展示了RecordedRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: runRedirectionTest
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
/**
* Run a redirection test consisting of
* 1) Request to REQUEST_PATH with 3xx response redirecting to another URI
* 2) Request to REDIRECTED_PATH with interrupted partial response
* 3) Resume request to complete download
* @return the last request sent to the server, resuming after the interruption
*/
private RecordedRequest runRedirectionTest(int status) throws Exception {
enqueueResponse(buildEmptyResponse(status)
.setHeader("Location", mServer.getUrl(REDIRECTED_PATH).toString()));
enqueueInterruptedDownloadResponses(5);
final Download download = enqueueRequest(getRequest());
download.runUntilStatus(DownloadManager.STATUS_PAUSED);
mSystemFacade.incrementTimeMillis(RETRY_DELAY_MILLIS);
download.runUntilStatus(DownloadManager.STATUS_SUCCESSFUL);
assertEquals(REQUEST_PATH, takeRequest().getPath());
assertEquals(REDIRECTED_PATH, takeRequest().getPath());
return takeRequest();
}
开发者ID:wuyexiong,项目名称:android-downloadprovider,代码行数:23,代码来源:PublicApiFunctionalTest.java
示例2: testDownloadTextFile
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
public void testDownloadTextFile() throws Exception {
enqueueResponse(buildResponse(HTTP_OK, FILE_CONTENT));
String path = "/download_manager_test_path";
Uri downloadUri = requestDownload(path);
assertEquals(Downloads.Impl.STATUS_PENDING, getDownloadStatus(downloadUri));
assertTrue(mTestContext.mHasServiceBeenStarted);
runUntilStatus(downloadUri, Downloads.Impl.STATUS_SUCCESS);
RecordedRequest request = takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(path, request.getPath());
assertEquals(FILE_CONTENT, getDownloadContents(downloadUri));
assertStartsWith(Environment.getExternalStorageDirectory().getPath(),
getDownloadFilename(downloadUri));
}
开发者ID:wuyexiong,项目名称:android-downloadprovider,代码行数:17,代码来源:DownloadProviderFunctionalTest.java
示例3: testImagePush
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void testImagePush() throws IOException, InterruptedException {
final String json = Resources.toString(getResource("image/image-push.json"), Charsets.UTF_8);
final Auth auth = new Auth("hannibal", "xxxx", "[email protected]");
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody(json));
server.play();
Docker docker = createDockerForMock(server);
Progress response = docker.imagePush("base", "reg", auth);
assertNotNull(response);
assertEquals(response.getError(), "Invalid...");
RecordedRequest recordedRequest = server.takeRequest();
String body = new String(recordedRequest.getBody());
Auth requestAuth = new Gson().fromJson(body, Auth.class);
assertEquals(auth.getEmail(), requestAuth.getEmail());
}
开发者ID:jboss-fuse,项目名称:fuse-docker,代码行数:17,代码来源:ImageTest.java
示例4: redirectToCachedResult
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test public void redirectToCachedResult() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").setBody("ABC"));
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_PERM)
.addHeader("Location: /foo"));
server.enqueue(new MockResponse().setBody("DEF"));
server.play();
assertEquals("ABC", readAscii(openConnection(server.getUrl("/foo"))));
RecordedRequest request1 = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request1.getRequestLine());
assertEquals(0, request1.getSequenceNumber());
assertEquals("ABC", readAscii(openConnection(server.getUrl("/bar"))));
RecordedRequest request2 = server.takeRequest();
assertEquals("GET /bar HTTP/1.1", request2.getRequestLine());
assertEquals(1, request2.getSequenceNumber());
// an unrelated request should reuse the pooled connection
assertEquals("DEF", readAscii(openConnection(server.getUrl("/baz"))));
RecordedRequest request3 = server.takeRequest();
assertEquals("GET /baz HTTP/1.1", request3.getRequestLine());
assertEquals(2, request3.getSequenceNumber());
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:24,代码来源:HttpResponseCacheTest.java
示例5: assertClientSuppliedCondition
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
private RecordedRequest assertClientSuppliedCondition(MockResponse seed, String conditionName,
String conditionValue) throws Exception {
server.enqueue(seed.setBody("A"));
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
server.play();
URL url = server.getUrl("/");
assertEquals("A", readAscii(openConnection(url)));
HttpURLConnection connection = openConnection(url);
connection.addRequestProperty(conditionName, conditionValue);
assertEquals(HttpURLConnection.HTTP_NOT_MODIFIED, connection.getResponseCode());
assertEquals("", readAscii(connection));
server.takeRequest(); // seed
return server.takeRequest();
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:18,代码来源:HttpResponseCacheTest.java
示例6: testServerClosesOutput
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
private void testServerClosesOutput(SocketPolicy socketPolicy) throws Exception {
server.enqueue(new MockResponse().setBody("This connection won't pool properly")
.setSocketPolicy(socketPolicy));
MockResponse responseAfter = new MockResponse().setBody("This comes after a busted connection");
server.enqueue(responseAfter);
server.enqueue(responseAfter); // Enqueue 2x because the broken connection may be reused.
server.play();
HttpURLConnection connection1 = client.open(server.getUrl("/a"));
connection1.setReadTimeout(100);
assertContent("This connection won't pool properly", connection1);
assertEquals(0, server.takeRequest().getSequenceNumber());
HttpURLConnection connection2 = client.open(server.getUrl("/b"));
connection2.setReadTimeout(100);
assertContent("This comes after a busted connection", connection2);
// Check that a fresh connection was created, either immediately or after attempting reuse.
RecordedRequest requestAfter = server.takeRequest();
if (server.getRequestCount() == 3) {
requestAfter = server.takeRequest(); // The failure consumed a response.
}
// sequence number 0 means the HTTP socket connection was not reused
assertEquals(0, requestAfter.getSequenceNumber());
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:25,代码来源:URLConnectionTest.java
示例7: clientConfiguredGzipContentEncoding
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test public void clientConfiguredGzipContentEncoding() throws Exception {
byte[] bodyBytes = gzip("ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes("UTF-8"));
server.enqueue(new MockResponse()
.setBody(bodyBytes)
.addHeader("Content-Encoding: gzip"));
server.play();
URLConnection connection = client.open(server.getUrl("/"));
connection.addRequestProperty("Accept-Encoding", "gzip");
InputStream gunzippedIn = new GZIPInputStream(connection.getInputStream());
assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", readAscii(gunzippedIn, Integer.MAX_VALUE));
assertEquals(bodyBytes.length, connection.getContentLength());
RecordedRequest request = server.takeRequest();
assertContains(request.getHeaders(), "Accept-Encoding: gzip");
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:17,代码来源:URLConnectionTest.java
示例8: setChunkedStreamingMode
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
/**
* Obnoxiously test that the chunk sizes transmitted exactly equal the
* requested data+chunk header size. Although setChunkedStreamingMode()
* isn't specific about whether the size applies to the data or the
* complete chunk, the RI interprets it as a complete chunk.
*/
@Test public void setChunkedStreamingMode() throws IOException, InterruptedException {
server.enqueue(new MockResponse());
server.play();
HttpURLConnection urlConnection = client.open(server.getUrl("/"));
urlConnection.setChunkedStreamingMode(8);
urlConnection.setDoOutput(true);
OutputStream outputStream = urlConnection.getOutputStream();
outputStream.write("ABCDEFGHIJKLMNOPQ".getBytes("US-ASCII"));
assertEquals(200, urlConnection.getResponseCode());
RecordedRequest request = server.takeRequest();
assertEquals("ABCDEFGHIJKLMNOPQ", new String(request.getBody(), "US-ASCII"));
assertEquals(Arrays.asList(3, 3, 3, 3, 3, 2), request.getChunkSizes());
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:22,代码来源:URLConnectionTest.java
示例9: testRedirected
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
private void testRedirected(TransferKind transferKind, boolean reuse) throws Exception {
MockResponse response = new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP)
.addHeader("Location: /foo");
transferKind.setBody(response, "This page has moved!", 10);
server.enqueue(response);
server.enqueue(new MockResponse().setBody("This is the new location!"));
server.play();
URLConnection connection = client.open(server.getUrl("/"));
assertEquals("This is the new location!",
readAscii(connection.getInputStream(), Integer.MAX_VALUE));
RecordedRequest first = server.takeRequest();
assertEquals("GET / HTTP/1.1", first.getRequestLine());
RecordedRequest retry = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", retry.getRequestLine());
if (reuse) {
assertEquals("Expected connection reuse", 1, retry.getSequenceNumber());
}
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:21,代码来源:URLConnectionTest.java
示例10: redirectedOnHttps
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test public void redirectedOnHttps() throws IOException, InterruptedException {
server.useHttps(sslContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP)
.addHeader("Location: /foo")
.setBody("This page has moved!"));
server.enqueue(new MockResponse().setBody("This is the new location!"));
server.play();
client.setSslSocketFactory(sslContext.getSocketFactory());
client.setHostnameVerifier(new RecordingHostnameVerifier());
HttpURLConnection connection = client.open(server.getUrl("/"));
assertEquals("This is the new location!",
readAscii(connection.getInputStream(), Integer.MAX_VALUE));
RecordedRequest first = server.takeRequest();
assertEquals("GET / HTTP/1.1", first.getRequestLine());
RecordedRequest retry = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", retry.getRequestLine());
assertEquals("Expected connection reuse", 1, retry.getSequenceNumber());
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:21,代码来源:URLConnectionTest.java
示例11: testResponseRedirectedWithPost
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
private void testResponseRedirectedWithPost(int redirectCode) throws Exception {
server.enqueue(new MockResponse().setResponseCode(redirectCode)
.addHeader("Location: /page2")
.setBody("This page has moved!"));
server.enqueue(new MockResponse().setBody("Page 2"));
server.play();
HttpURLConnection connection = client.open(server.getUrl("/page1"));
connection.setDoOutput(true);
byte[] requestBody = { 'A', 'B', 'C', 'D' };
OutputStream outputStream = connection.getOutputStream();
outputStream.write(requestBody);
outputStream.close();
assertEquals("Page 2", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
assertTrue(connection.getDoOutput());
RecordedRequest page1 = server.takeRequest();
assertEquals("POST /page1 HTTP/1.1", page1.getRequestLine());
assertEquals(Arrays.toString(requestBody), Arrays.toString(page1.getBody()));
RecordedRequest page2 = server.takeRequest();
assertEquals("GET /page2 HTTP/1.1", page2.getRequestLine());
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:24,代码来源:URLConnectionTest.java
示例12: veryLargeFixedLengthRequest
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test public void veryLargeFixedLengthRequest() throws Exception {
server.setBodyLimit(0);
server.enqueue(new MockResponse());
server.play();
HttpURLConnection connection = client.open(server.getUrl("/"));
connection.setDoOutput(true);
long contentLength = Integer.MAX_VALUE + 1L;
connection.setFixedLengthStreamingMode(contentLength);
OutputStream out = connection.getOutputStream();
byte[] buffer = new byte[1024 * 1024];
for (long bytesWritten = 0; bytesWritten < contentLength; ) {
int byteCount = (int) Math.min(buffer.length, contentLength - bytesWritten);
out.write(buffer, 0, byteCount);
bytesWritten += byteCount;
}
assertContent("", connection);
RecordedRequest request = server.takeRequest();
assertEquals(Long.toString(contentLength), request.getHeader("Content-Length"));
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:22,代码来源:URLConnectionTest.java
示例13: authenticate
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test public void authenticate() throws Exception {
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_UNAUTHORIZED)
.addHeader("www-authenticate: Basic realm=\"protected area\"")
.setBody("Please authenticate."));
server.enqueue(new MockResponse().setBody("Successful auth!"));
server.play();
Authenticator.setDefault(new RecordingAuthenticator());
HttpURLConnection connection = client.open(server.getUrl("/"));
assertEquals("Successful auth!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
RecordedRequest denied = server.takeRequest();
assertContainsNoneMatching(denied.getHeaders(), "authorization: Basic .*");
RecordedRequest accepted = server.takeRequest();
assertEquals("GET / HTTP/1.1", accepted.getRequestLine());
assertContains(accepted.getHeaders(),
"authorization: Basic " + RecordingAuthenticator.BASE_64_CREDENTIALS);
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:19,代码来源:HttpOverSpdyTest.java
示例14: acceptAndTransmitCookies
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test public void acceptAndTransmitCookies() throws Exception {
CookieManager cookieManager = new CookieManager();
client.setCookieHandler(cookieManager);
server.enqueue(
new MockResponse().addHeader("set-cookie: c=oreo; domain=" + server.getCookieDomain())
.setBody("A"));
server.enqueue(new MockResponse().setBody("B"));
server.play();
URL url = server.getUrl("/");
assertContent("A", client.open(url), Integer.MAX_VALUE);
Map<String, List<String>> requestHeaders = Collections.emptyMap();
assertEquals(Collections.singletonMap("Cookie", Arrays.asList("c=oreo")),
cookieManager.get(url.toURI(), requestHeaders));
assertContent("B", client.open(url), Integer.MAX_VALUE);
RecordedRequest requestA = server.takeRequest();
assertContainsNoneMatching(requestA.getHeaders(), "Cookie.*");
RecordedRequest requestB = server.takeRequest();
assertContains(requestB.getHeaders(), "cookie: c=oreo");
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:22,代码来源:HttpOverSpdyTest.java
示例15: post
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test public void post() throws Exception {
server.enqueue(new MockResponse().setBody("abc"));
server.play();
Request request = new Request.Builder(server.getUrl("/"))
.post(Request.Body.create(MediaType.parse("text/plain"), "def"))
.build();
client.enqueue(request, receiver);
receiver.await(request)
.assertCode(200)
.assertBody("abc");
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("def", recordedRequest.getUtf8Body());
assertEquals("3", recordedRequest.getHeader("Content-Length"));
}
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:18,代码来源:AsyncApiTest.java
示例16: testGet
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void testGet() throws IOException, InterruptedException {
server.enqueue(prepareResponse(SERIALIZED_STRING));
String to = endpoint.get("/", String.class);
Assert.assertNotNull("Recieved Object is null", to);
RecordedRequest request = server.takeRequest();
Assert.assertEquals("Incorrect Request Line", "GET / HTTP/1.1", request.getRequestLine());
}
开发者ID:reportportal,项目名称:client-java-rest-core,代码行数:10,代码来源:RestEndointTest.java
示例17: testPost
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void testPost() throws IOException, InterruptedException {
server.enqueue(prepareResponse(SERIALIZED_STRING));
String to = endpoint.post("/", String.format(SERIALIZED_STRING_PATTERN, 100, "test string"), String.class);
Assert.assertNotNull("Recieved Object is null", to);
RecordedRequest request = server.takeRequest();
Assert.assertEquals("Incorrect Request Line", "POST / HTTP/1.1", request.getRequestLine());
validateHeader(request);
Assert.assertEquals("Incorrect body", SERIALIZED_STRING, new String(request.getBody()));
}
开发者ID:reportportal,项目名称:client-java-rest-core,代码行数:12,代码来源:RestEndointTest.java
示例18: testPut
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void testPut() throws IOException, InterruptedException {
server.enqueue(prepareResponse(SERIALIZED_STRING));
String to = endpoint.put("/", String.format(SERIALIZED_STRING_PATTERN, 100, "test string"), String.class);
Assert.assertNotNull("Recieved Object is null", to);
RecordedRequest request = server.takeRequest();
Assert.assertEquals("Incorrect Request Line", "PUT / HTTP/1.1", request.getRequestLine());
validateHeader(request);
Assert.assertEquals("Incorrect body", SERIALIZED_STRING, new String(request.getBody()));
}
开发者ID:reportportal,项目名称:client-java-rest-core,代码行数:12,代码来源:RestEndointTest.java
示例19: testDelete
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void testDelete() throws IOException, InterruptedException {
server.enqueue(prepareResponse(SERIALIZED_STRING));
String to = endpoint.delete("/", String.class);
Assert.assertNotNull("Recieved Object is null", to);
RecordedRequest request = server.takeRequest();
Assert.assertEquals("Incorrect Request Line", "DELETE / HTTP/1.1", request.getRequestLine());
}
开发者ID:reportportal,项目名称:client-java-rest-core,代码行数:10,代码来源:RestEndointTest.java
示例20: testGetRestCall
import com.google.mockwebserver.RecordedRequest; //导入依赖的package包/类
@Test
public void testGetRestCall() throws InterruptedException {
server.enqueue(new MockResponse().setBody("{}"));
service.get();
RecordedRequest request = server.takeRequest();
assertEquals(request.getPath(),"/testGetService");
assertEquals(request.getBody(), new byte[0]);
}
开发者ID:brooklyncentral,项目名称:brooklyn-ambari,代码行数:10,代码来源:AmbariRestClientTest.java
注:本文中的com.google.mockwebserver.RecordedRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论