com.squareup.okhttp.mockwebserver.MockWebServer.takeRequest()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(126)

本文整理了Java中com.squareup.okhttp.mockwebserver.MockWebServer.takeRequest()方法的一些代码示例,展示了MockWebServer.takeRequest()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockWebServer.takeRequest()方法的具体详情如下:
包路径:com.squareup.okhttp.mockwebserver.MockWebServer
类名称:MockWebServer
方法名:takeRequest

MockWebServer.takeRequest介绍

[英]Awaits the next HTTP request, removes it, and returns it. Callers should use this to verify the request was sent as intended. This method will block until the request is available, possibly forever.
[中]等待下一个HTTP请求,将其删除并返回。呼叫者应使用此功能验证请求是否按预期发送。此方法将一直阻止,直到请求可用为止,可能是永远。

代码示例

代码示例来源:origin: google/data-transfer-project

RecordedRequest calendarBatch = server.takeRequest();
Map<String, Object> calendarBody =
  (Map<String, Object>) mapper.readValue(calendarBatch.getBody().readUtf8(), Map.class);
RecordedRequest eventBatch = server.takeRequest();
Map<String, Object> eventRequests =
  (Map<String, Object>) mapper.readValue(eventBatch.getBody().readUtf8(), Map.class);

代码示例来源:origin: appnexus/mobile-sdk-android

private RecordedRequest takeNoAdURLRequestFromQueue(int position){
  RecordedRequest request = null;
  for (int i = 1; i <= position; i++) {
    try {
      request  = server.takeRequest();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
  return request;
}

代码示例来源:origin: cfg4j/cfg4j

@Test
void connectsToSpecifiedAgent() throws Exception {
 RecordedRequest request = server.takeRequest(0, TimeUnit.MILLISECONDS);
 assertThat(request).isNotNull();
}

代码示例来源:origin: appnexus/mobile-sdk-android

private void assertNoAdURL() {
  RecordedRequest request = null;
  try {
    request = server.takeRequest();
    String no_AdURL = request.getRequestLine();
    System.out.print("no_ad_URL::" + no_AdURL + "\n");
    assertTrue(no_AdURL.startsWith("GET /no_ad? HTTP/1.1"));
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: appnexus/mobile-sdk-android

private void assertNoAdURL() {
  RecordedRequest request = null;
  try {
    request = server.takeRequest();
    String no_AdURL = request.getRequestLine();
    System.out.print("no_ad_URL::" + no_AdURL + "\n");
    assertTrue(no_AdURL.startsWith("GET /no_ad? HTTP/1.1"));
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: appnexus/mobile-sdk-android

private void assertNoAdURL() {
  RecordedRequest request = null;
  try {
    request = server.takeRequest();
    String no_AdURL = request.getRequestLine();
    System.out.print("no_ad_URL::" + no_AdURL + "\n");
    assertTrue(no_AdURL.startsWith("GET /no_ad? HTTP/1.1"));
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: plivo/plivo-java

protected void assertRequest(String method, String format, Object... objects)
 throws InterruptedException, MalformedURLException, UnsupportedEncodingException {
 assertRequest(server.takeRequest(), method, "/Account/" + authId + "/" + format,
  new LinkedHashMap<>(), objects);
}

代码示例来源:origin: apache/jclouds

/**
* Ensures server received authentication request.
*/
public void assertAuthentication(MockWebServer server) {
 assertTrue(server.getRequestCount() >= 1);
 try {
   assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1");
 } catch (InterruptedException e) {
   Throwables.propagate(e);
 }
}

代码示例来源:origin: apache/jclouds

/**
* Ensures server received a <i>versioned</i> extensions request. This is necessary for testing APIs whose version
* is not included in the Endpoint's {@link Endpoint#getPublicURL() publicURL}.
*/
public void assertExtensions(MockWebServer server, String path) {
 assertTrue(server.getRequestCount() >= 1);
 try {
   assertEquals(server.takeRequest().getRequestLine(), "GET " + path + "/extensions HTTP/1.1");
 } catch (InterruptedException e) {
   Throwables.propagate(e);
 }
}

代码示例来源:origin: apache/jclouds

/** Stripping out authorization, ensures the following post params were sent. */
  protected RecordedRequest assertPosted(String region, String postParams) throws InterruptedException {
   RecordedRequest request = regionToServers.get(region).takeRequest();
   assertEquals(request.getMethod(), "POST");
   assertEquals(request.getPath(), "/");
   assertEquals(new String(request.getBody(), Charsets.UTF_8).replaceAll("&Signature.*", ""), postParams);
   return request;
  }
}

代码示例来源:origin: jclouds/jclouds-labs

protected RecordedRequest assertSent(String method, String path) throws InterruptedException {
 RecordedRequest request = server.takeRequest();
 assertedRequestCount++;
 assertThat(request.getMethod()).isEqualTo(method);
 assertThat(request.getPath()).isEqualTo(path);
 assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(MediaType.APPLICATION_JSON);
 assertThat(request.getHeader(HttpHeaders.AUTHORIZATION)).isEqualTo("Basic Og==");
 return request;
}

代码示例来源:origin: cdancy/jenkins-rest

protected RecordedRequest assertSentWithFormData(final MockWebServer server, 
    final String method, 
    final String path, 
    final String body) throws InterruptedException {
  RecordedRequest request = server.takeRequest();
  assertThat(request.getMethod()).isEqualTo(method);
  assertThat(request.getPath()).isEqualTo(path);
  assertThat(request.getUtf8Body()).isEqualTo(body);
  assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(APPLICATION_JSON);
  assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo(MediaType.APPLICATION_FORM_URLENCODED);
  return request;
}

代码示例来源:origin: apache/jclouds

private RecordedRequest assertSentNoAuth(MockWebServer server, String method, String path) throws InterruptedException {
 RecordedRequest request = server.takeRequest();
 assertEquals(request.getMethod(), method);
 assertEquals(request.getPath(), path);
 assertEquals(request.getHeader("Accept"), "application/json");
 return request;
}

代码示例来源:origin: apache/jclouds

protected RecordedRequest assertSent(MockWebServer server, String method, String path) throws InterruptedException {
 RecordedRequest request = server.takeRequest();
 assertEquals(request.getMethod(), method);
 assertEquals(request.getPath(), path);
 assertEquals(request.getHeader("Accept"), APPLICATION_JSON);
 assertEquals(request.getHeader("Authorization"), "Bearer " + credential);
 return request;
}

代码示例来源:origin: apache/jclouds

protected RecordedRequest assertSent(MockWebServer server, String method, String path, String type) throws InterruptedException {
 RecordedRequest request = server.takeRequest();
 assertEquals(request.getMethod(), method);
 assertEquals(request.getPath(), path);
 if (type != null){
   assertEquals(request.getHeader("Accept"), type);
 }
 assertEquals(request.getHeader("Authorization"), "Bearer " + credential);
 return request;
}

代码示例来源:origin: Karumi/MarvelApiClientAndroid

protected void assertRequestSentToContains(String... paths) throws InterruptedException {
 RecordedRequest request = server.takeRequest();
 for (String path : paths) {
  Assert.assertThat(request.getPath(), StringContains.containsString(path));
 }
}

代码示例来源:origin: apache/jclouds

private void assertRequests(MockWebServer server, int requestCount, String requestPath) throws InterruptedException {
   assertEquals(server.getRequestCount(), requestCount);
   assertAuthentication(server);
   assertExtensions(server, "/v2/da0d12be20394afb851716e10a49e4a7");
   if (requestPath != null) {
     assertRequest(server.takeRequest(), "GET", "/v2/da0d12be20394afb851716e10a49e4a7" + requestPath);
   }
  }
}

代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck

@Test
public void getRequestsPath() throws InterruptedException
{
  server().enqueue(new MockResponse());
  
  newBrowser().get(url(server(), "/x"));
  
  assertThat("request path", server().takeRequest().getPath(), is("/x"));
}

代码示例来源:origin: segmentio/analytics-android

@Test
public void fetchSettings() throws Exception {
 server.enqueue(new MockResponse());
 Client.Connection connection = client.fetchSettings();
 assertThat(connection.os).isNull();
 assertThat(connection.is).isNotNull();
 assertThat(connection.connection.getResponseCode()).isEqualTo(200);
 RecordedRequestAssert.assertThat(server.takeRequest())
   .hasRequestLine("GET /v1/projects/foo/settings HTTP/1.1")
   .containsHeader("User-Agent", ConnectionFactory.USER_AGENT)
   .containsHeader("Content-Type", "application/json");
}

代码示例来源:origin: appnexus/mobile-sdk-android

@Test
public void testNotifyURLForVideo() throws Exception {
  server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.rtbVASTVideo()));
  server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank()));
  executeUTRequest();
  assertCallbacks(true);
  assertTrue(bannerAdView.mAdFetcher.getState() == AdFetcher.STATE.STOPPED);
  request = server.takeRequest(); // Discard the first request since its a HTTP Post for /ut/v3 ad request call
  request = server.takeRequest();
  assertNotifyURL(request);
}

相关文章