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

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

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

MockWebServer.url介绍

[英]Returns a URL for connecting to this server.
[中]返回用于连接到此服务器的URL。

代码示例

代码示例来源:origin: facebook/stetho

@Test
public void testWithResponseCompression() throws IOException {
 ByteArrayOutputStream capturedOutput = hookAlmostRealInterpretResponseStream(mMockEventReporter);
 byte[] uncompressedData = repeat(".", 1024).getBytes();
 byte[] compressedData = compress(uncompressedData);
 MockWebServer server = new MockWebServer();
 server.start();
 server.enqueue(new MockResponse()
   .setBody(new Buffer().write(compressedData))
   .addHeader("Content-Encoding: gzip"));
 Request request = new Request.Builder()
   .url(server.url("/"))
   .build();
 Response response = mClientWithInterceptor.newCall(request).execute();
 // Verify that the final output and the caller both saw the uncompressed stream.
 assertArrayEquals(uncompressedData, response.body().bytes());
 assertArrayEquals(uncompressedData, capturedOutput.toByteArray());
 // And verify that the StethoInterceptor was able to see both.
 Mockito.verify(mMockEventReporter)
   .dataReceived(
     anyString(),
     eq(compressedData.length),
     eq(uncompressedData.length));
 server.shutdown();
}

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

@Test
public void testExport() throws Exception {
 server.enqueue(new MockResponse().setBody(CALENDARS_RESPONSE));
 server.enqueue(new MockResponse().setBody(CALENDAR1_EVENTS_RESPONSE));
 server.enqueue(new MockResponse().setBody(CALENDAR2_EVENTS_RESPONSE));
 server.start();
 HttpUrl baseUrl = server.url("");
 MicrosoftCalendarExporter exporter =
   new MicrosoftCalendarExporter(baseUrl.toString(), client, mapper, transformerService);
 ExportResult<CalendarContainerResource> resource = exporter
   .export(UUID.randomUUID(), token, Optional.empty());
 CalendarContainerResource calendarResource = resource.getExportedData();
 Assert.assertEquals(2, calendarResource.getCalendars().size());
 Assert.assertFalse(
   calendarResource
     .getCalendars()
     .stream()
     .anyMatch(c -> "Calendar1".equals(c.getId()) && "Calendar2".equals(c.getId())));
 Assert.assertEquals(2, calendarResource.getEvents().size());
 Assert.assertFalse(
   calendarResource
     .getEvents()
     .stream()
     .anyMatch(
       e ->
         "Test Appointment 1".equals(e.getTitle())
           && "Test Appointment 2".equals(e.getTitle())));
}

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

server.start();
HttpUrl baseUrl = server.url("");
MicrosoftCalendarImporter importer =
  new MicrosoftCalendarImporter(

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

HttpUrl baseUrl = server.url("");
MicrosoftPhotosExporter exporter = new MicrosoftPhotosExporter(baseUrl.toString(), client,
  mapper, jobStore);

代码示例来源:origin: com.squareup.okhttp/mockwebserver

/**
 * Returns a URL for connecting to this server.
 * @param path the request path, such as "/".
 */
@Deprecated
public URL getUrl(String path) {
 return url(path).url();
}

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

public static String url(MockWebServer server, String path)
{
  return server.url(path).toString();
}

代码示例来源:origin: com.squareup.okhttp/mockwebserver

private void pushPromises(FramedStream stream, List<PushPromise> promises) throws IOException {
  for (PushPromise pushPromise : promises) {
   List<Header> pushedHeaders = new ArrayList<>();
   pushedHeaders.add(new Header(stream.getConnection().getProtocol() == Protocol.SPDY_3
     ? Header.TARGET_HOST
     : Header.TARGET_AUTHORITY, url(pushPromise.getPath()).host()));
   pushedHeaders.add(new Header(Header.TARGET_METHOD, pushPromise.getMethod()));
   pushedHeaders.add(new Header(Header.TARGET_PATH, pushPromise.getPath()));
   Headers pushPromiseHeaders = pushPromise.getHeaders();
   for (int i = 0, size = pushPromiseHeaders.size(); i < size; i++) {
    pushedHeaders.add(new Header(pushPromiseHeaders.name(i), pushPromiseHeaders.value(i)));
   }
   String requestLine = pushPromise.getMethod() + ' ' + pushPromise.getPath() + " HTTP/1.1";
   List<Integer> chunkSizes = Collections.emptyList(); // No chunked encoding for SPDY.
   requestQueue.add(new RecordedRequest(requestLine, pushPromise.getHeaders(), chunkSizes, 0,
     new Buffer(), sequenceNumber.getAndIncrement(), socket));
   boolean hasBody = pushPromise.getResponse().getBody() != null;
   FramedStream pushedStream =
     stream.getConnection().pushStream(stream.getId(), pushedHeaders, hasBody);
   writeResponse(pushedStream, pushPromise.getResponse());
  }
 }
}

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

@Test
public void getHrefWhenLinkAndRelativeHrefReturnsAbsoluteUrl()
{
  server().enqueue(new MockResponse().setBody("<html><head>"
    + "<link rel='x' href='x'/>"
    + "</head></html>"));
  
  URL actual = newBrowser().get(url(server()))
    .getLink("x")
    .getHref();
  
  assertThat("link href", actual, is(server().url("/x").url()));
}

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

@Test
public void getHrefWhenAnchorAndRelativeHrefReturnsAbsoluteUrl()
{
  server().enqueue(new MockResponse().setBody("<html><body>"
    + "<a rel='r' href='x'/>"
    + "</body></html>"));
  
  URL actual = newBrowser().get(url(server()))
    .getLink("r")
    .getHref();
  
  assertThat("link href", actual, is(server().url("/x").url()));
}

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

@Before
public void setUp() throws Exception {
 server = new MockWebServer();
 server.start();
 PlivoClient.BASE_URL = server.url("/").toString();
 Plivo.init(authId, authToken);
 Plivo.getClient().setTesting(true);
}

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

@Before
public void setup() {
  Robolectric.getBackgroundThreadScheduler().reset();
  Robolectric.getForegroundThreadScheduler().reset();
  ShadowLog.stream = System.out;
  activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get();
  shadowOf(activity).grantPermissions("android.permission.INTERNET");
  server= new MockWebServer();
  try {
    server.start();
    HttpUrl url= server.url("/");
    UTConstants.REQUEST_BASE_URL_UT = url.toString();
    System.out.println(UTConstants.REQUEST_BASE_URL_UT);
    ShadowSettings.setTestURL(url.toString());
  } catch (IOException e) {
    System.out.print("IOException");
  }
  bgScheduler = Robolectric.getBackgroundThreadScheduler();
  uiScheduler = Robolectric.getForegroundThreadScheduler();
  Robolectric.flushBackgroundThreadScheduler();
  Robolectric.flushForegroundThreadScheduler();
  bgScheduler.pause();
  uiScheduler.pause();
}

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

@Before
public void setup() {
  Robolectric.getBackgroundThreadScheduler().reset();
  Robolectric.getForegroundThreadScheduler().reset();
  ShadowLog.stream = System.out;
  activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get();
  shadowOf(activity).grantPermissions("android.permission.INTERNET");
  server= new MockWebServer();
  try {
    server.start();
    HttpUrl url= server.url("/");
    UTConstants.REQUEST_BASE_URL_UT = url.toString();
    System.out.println(UTConstants.REQUEST_BASE_URL_UT);
    ShadowSettings.setTestURL(url.toString());
    TestResponsesUT.setTestURL(url.toString());
  } catch (IOException e) {
    System.out.print("IOException");
  }
  bgScheduler = Robolectric.getBackgroundThreadScheduler();
  uiScheduler = Robolectric.getForegroundThreadScheduler();
  Robolectric.flushBackgroundThreadScheduler();
  Robolectric.flushForegroundThreadScheduler();
  bgScheduler.pause();
  uiScheduler.pause();
}

相关文章