okhttp3.mockwebserver.MockWebServer.getHostName()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(123)

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

MockWebServer.getHostName介绍

暂无

代码示例

代码示例来源:origin: square/okhttp

/**
 * Returns a URL for connecting to this server.
 *
 * @param path the request path, such as "/".
 */
public HttpUrl url(String path) {
 return new HttpUrl.Builder()
   .scheme(sslSocketFactory != null ? "https" : "http")
   .host(getHostName())
   .port(getPort())
   .build()
   .resolve(path);
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void issuerWhenAllInformationThenSuccess() throws Exception {
  ClientRegistration registration = registration("");
  ClientRegistration.ProviderDetails provider = registration.getProviderDetails();
  assertThat(registration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.BASIC);
  assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE);
  assertThat(registration.getRegistrationId()).isEqualTo(this.server.getHostName());
  assertThat(registration.getClientName()).isEqualTo(this.issuer);
  assertThat(registration.getScopes()).containsOnly("openid", "email", "profile");
  assertThat(provider.getAuthorizationUri()).isEqualTo("https://example.com/o/oauth2/v2/auth");
  assertThat(provider.getTokenUri()).isEqualTo("https://example.com/oauth2/v4/token");
  assertThat(provider.getJwkSetUri()).isEqualTo("https://example.com/oauth2/v3/certs");
  assertThat(provider.getConfigurationMetadata()).containsKeys("authorization_endpoint", "claims_supported",
      "code_challenge_methods_supported", "id_token_signing_alg_values_supported", "issuer", "jwks_uri",
      "response_types_supported", "revocation_endpoint", "scopes_supported", "subject_types_supported",
      "grant_types_supported", "token_endpoint", "token_endpoint_auth_methods_supported", "userinfo_endpoint");
  assertThat(provider.getUserInfoEndpoint().getUri()).isEqualTo("https://example.com/oauth2/v3/userinfo");
}

代码示例来源:origin: SonarSource/sonarqube

private void setUpWithHttpUrl(ProcessId processId) {
  try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(ipcSharedDir, processId.getIpcIndex())) {
   processCommands.setUp();
   processCommands.setHttpUrl(format("http://%s:%d", server.getHostName(), server.getPort()));
  }
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void use_proxy_authentication() throws Exception {
 try (MockWebServer proxy = new MockWebServer()) {
  proxy.start();
  underTest = HttpConnector.newBuilder()
   .url(serverUrl)
   .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostName(), proxy.getPort())))
   .proxyCredentials("theProxyLogin", "theProxyPassword")
   .build();
  GetRequest request = new GetRequest("api/issues/search");
  proxy.enqueue(new MockResponse().setResponseCode(407));
  proxy.enqueue(new MockResponse().setBody("OK!"));
  underTest.call(request);
  RecordedRequest recordedRequest = proxy.takeRequest();
  assertThat(recordedRequest.getHeader("Proxy-Authorization")).isNull();
  recordedRequest = proxy.takeRequest();
  assertThat(recordedRequest.getHeader("Proxy-Authorization")).isEqualTo(basic("theProxyLogin", "theProxyPassword"));
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void use_proxy_authentication_wrong_crendentials() throws Exception {
 try (MockWebServer proxy = new MockWebServer()) {
  proxy.start();
  underTest = HttpConnector.newBuilder()
   .url(serverUrl)
   .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy.getHostName(), proxy.getPort())))
   .proxyCredentials("theProxyLogin", "wrongPassword")
   .build();
  GetRequest request = new GetRequest("api/issues/search");
  proxy.enqueue(new MockResponse().setResponseCode(407));
  proxy.enqueue(new MockResponse().setResponseCode(407));
  proxy.enqueue(new MockResponse().setResponseCode(407));
  underTest.call(request);
  RecordedRequest recordedRequest = proxy.takeRequest();
  assertThat(recordedRequest.getHeader("Proxy-Authorization")).isNull();
  recordedRequest = proxy.takeRequest();
  assertThat(recordedRequest.getHeader("Proxy-Authorization")).isEqualTo(basic("theProxyLogin", "wrongPassword"));
  assertThat(proxy.getRequestCount()).isEqualTo(2);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void retrieveSystemInfo_throws_ISE_if_http_error() {
 server.enqueue(new MockResponse().setResponseCode(500));
 // initialize registration of process
 setUpWithHttpUrl(ProcessId.COMPUTE_ENGINE);
 expectedException.expect(IllegalStateException.class);
 expectedException.expectMessage("Failed to call HTTP server of process " + ProcessId.COMPUTE_ENGINE);
 expectedException.expectCause(hasType(IOException.class)
  .andMessage(format("Server returned HTTP response code: 500 for URL: http://%s:%d/systemInfo", server.getHostName(), server.getPort())));
 underTest.retrieveSystemInfo();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void changeLogLevel_throws_ISE_if_http_error() {
 String message = "blah";
 server.enqueue(new MockResponse().setResponseCode(500).setBody(message));
 // initialize registration of process
 setUpWithHttpUrl(ProcessId.COMPUTE_ENGINE);
 expectedException.expect(IllegalStateException.class);
 expectedException.expectMessage("Failed to call HTTP server of process " + ProcessId.COMPUTE_ENGINE);
 expectedException.expectCause(hasType(IOException.class)
  .andMessage(format("Failed to change log level in Compute Engine. Code was '500' and response was 'blah' for url " +
   "'http://%s:%s/changeLogLevel'", server.getHostName(), server.getPort())));
 underTest.changeLogLevel(LoggerLevel.DEBUG);
}

代码示例来源:origin: fabric8io/mockwebserver

public String getHostName() {
 return server.getHostName();
}

代码示例来源:origin: io.zipkin.zipkin2/zipkin-junit

/** Use this to connect. The zipkin v1 interface will be under "/api/v1" */
public String httpUrl() {
 return String.format("http://%s:%s", server.getHostName(), server.getPort());
}

代码示例来源:origin: Rabtman/WsManager

public static void main(String[] args) {
  System.out.println("java test!");
  initMockServer();
  initWsClient("ws://" + mockWebServer.getHostName() + ":" + mockWebServer.getPort() + "/");
}

代码示例来源:origin: snowplow/snowplow-android-tracker

@SuppressLint("DefaultLocale")
public String getMockServerURI(MockWebServer mockServer) {
  if (mockServer != null) {
    return String.format("%s:%d", mockServer.getHostName(), mockServer.getPort());
  }
  return null;
}

代码示例来源:origin: snowplow/snowplow-android-tracker

@SuppressLint("DefaultLocale")
  public String getMockServerURI(MockWebServer mockServer) {
    if (mockServer != null) {
      return String.format("%s:%d", mockServer.getHostName(), mockServer.getPort());
    }
    return null;
  }
}

代码示例来源:origin: snowplow/snowplow-android-tracker

@SuppressLint("DefaultLocale")
public String getMockServerURI(MockWebServer mockServer) {
  if (mockServer != null) {
    return String.format("%s:%d", mockServer.getHostName(), mockServer.getPort());
  }
  return null;
}

代码示例来源:origin: com.github.ljun20160606/mockwebserver

/**
 * Returns a URL for connecting to this server.
 *
 * @param path the request path, such as "/".
 */
public HttpUrl url(String path) {
 return new HttpUrl.Builder()
   .scheme(sslSocketFactory != null ? "https" : "http")
   .host(getHostName())
   .port(getPort())
   .build()
   .resolve(path);
}

代码示例来源:origin: tcplugins/tcWebHooks

@Before
public void setup() throws IOException {
  server = new MockWebServer();
  server.start(getPort());
  
  System.out.println(String.format("MockServer started on http://%s:%s ",
      server.getHostName(),
      server.getPort()
  ));
}

代码示例来源:origin: Gitteroid/GitterJavaSDK

public static HttpUrl getRequestUrl(MockWebServer webServer) throws InterruptedException {
  String path = webServer.takeRequest().getPath();
  HttpUrl requestUrl = new HttpUrl.Builder().host(webServer.getHostName())
                       .port(webServer.getPort())
                       .scheme("https")
                       .build();
  return HttpUrl.parse(requestUrl + path);
}

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

@BeforeEach
public void beforeEach() {
  server = mockWebServerExt.get();
  server.useHttps(MockWebServerResources.getSSLSocketFactory(), false);
  mockServerHostPort = String.format("%s:%s/", server.getHostName(), server.getPort());
  //setup mock IAM server
  mockIamServer = mockIamServerExt.get();
  iamSystemPropertyMock.setMockIamTokenEndpointUrl(mockIamServer.url(iamTokenEndpoint)
      .toString());
}

代码示例来源:origin: line/line-bot-sdk-java

@Before
public void setUp() throws Exception {
  mockWebServer = new MockWebServer();
  final String apiEndPoint =
      "http://" + mockWebServer.getHostName() + ':' + mockWebServer.getPort()
      + "/CanContainsRelative/";
  target = LineMessagingClient
      .builder("SECRET")
      .apiEndPoint(apiEndPoint)
      .build();
}

代码示例来源:origin: palantir/conjure-java-runtime

@Test
public void testUserAgent_usesUnknownAgentIfBogusAgentIsGiven() throws InterruptedException, IOException {
  TestService service = Retrofit2Client.create(
      TestService.class,
      UserAgents.tryParse("bogus user agent"),
      new HostMetricsRegistry(),
      createTestConfig(String.format("http://%s:%s/api/",
          server.getHostName().toUpperCase(),
          server.getPort())));
  server.enqueue(new MockResponse().setBody("\"server\""));
  service.get().execute();
  RecordedRequest capturedRequest = server.takeRequest();
  assertThat(capturedRequest.getHeader("User-Agent"), startsWith("unknown/0.0.0"));
}

代码示例来源:origin: palantir/conjure-java-runtime

@Test
public void testUserAgent_defaultHeaderIsSent() throws InterruptedException, IOException {
  TestService service = Retrofit2Client.create(TestService.class,
      AGENT,
      new HostMetricsRegistry(),
      createTestConfig(String.format("http://%s:%s/api/",
          server.getHostName().toUpperCase(),
          server.getPort())));
  server.enqueue(new MockResponse().setBody("\"server\""));
  service.get().execute();
  RecordedRequest capturedRequest = server.takeRequest();
  assertThat(capturedRequest.getHeader("User-Agent"), startsWith(UserAgents.format(AGENT)));
}

相关文章