org.mockserver.model.HttpRequest.withPath()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(145)

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

HttpRequest.withPath介绍

[英]The path to match on such as "/some_mocked_path" any servlet context path is ignored for matching and should not be specified here regex values are also supported such as "._path", see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html for full details of the supported regex syntax
[中]要匹配的路径,例如“/some\u mocked\u path”任何servlet上下文路径都会被忽略以进行匹配,不应在此处指定正则表达式值,例如“.
\u path”,请参阅http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html有关受支持的正则表达式语法的完整详细信息

代码示例

代码示例来源:origin: jamesdbloom/mockserver

/**
 * Reset MockServer by clearing all expectations
 */
public MockServerClient reset() {
  MockServerEventBus.getInstance().publish(EventType.RESET);
  sendRequest(request().withMethod("PUT").withPath(calculatePath("reset")));
  return clientClass.cast(this);
}

代码示例来源:origin: jamesdbloom/mockserver

/**
 * Clear expectations, logs or both that match the http
 *
 * @param httpRequest the http request that is matched against when deciding whether to clear each expectation if null all expectations are cleared
 * @param type        the type to clear, EXPECTATION, LOG or BOTH
 */
public MockServerClient clear(HttpRequest httpRequest, ClearType type) {
  sendRequest(request().withMethod("PUT").withPath(calculatePath("clear")).withQueryStringParameter("type", type.name().toLowerCase()).withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", StandardCharsets.UTF_8));
  return clientClass.cast(this);
}

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest buildObject() {
  return new HttpRequest()
    .withMethod(method)
    .withPath(path)
    .withQueryStringParameters(queryStringParameters)
    .withBody((body != null ? Not.not(body.buildObject(), body.getNot()) : null))
    .withHeaders(headers)
    .withCookies(cookies)
    .withSecure(secure)
    .withKeepAlive(keepAlive);
}

代码示例来源:origin: Netflix/eureka

@Test
public void testHeartbeatReplicationWithNoResponseBody() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("PUT")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName() + '/' + instanceInfo.getId())
  ).respond(
      response().withStatusCode(200)
  );
  EurekaHttpResponse<InstanceInfo> response = replicationClient.sendHeartBeat(instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo, InstanceStatus.DOWN);
  assertThat(response.getStatusCode(), is(equalTo(200)));
  assertThat(response.getEntity(), is(nullValue()));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testRegistrationReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("POST")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName())
  ).respond(
      response().withStatusCode(200)
  );
  EurekaHttpResponse<Void> response = replicationClient.register(instanceInfo);
  assertThat(response.getStatusCode(), is(equalTo(200)));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testRegistrationReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("POST")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName())
  ).respond(
      response().withStatusCode(200)
  );
  EurekaHttpResponse<Void> response = replicationClient.register(instanceInfo);
  assertThat(response.getStatusCode(), is(equalTo(200)));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testHeartbeatReplicationWithNoResponseBody() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("PUT")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName() + '/' + instanceInfo.getId())
  ).respond(
      response().withStatusCode(200)
  );
  EurekaHttpResponse<InstanceInfo> response = replicationClient.sendHeartBeat(instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo, InstanceStatus.DOWN);
  assertThat(response.getStatusCode(), is(equalTo(200)));
  assertThat(response.getEntity(), is(nullValue()));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testAsgStatusUpdateReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("PUT")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/asg/" + instanceInfo.getASGName() + "/status")
  ).respond(
      response().withStatusCode(200)
  );
  EurekaHttpResponse<Void> response = replicationClient.statusUpdate(instanceInfo.getASGName(), ASGStatus.ENABLED);
  assertThat(response.getStatusCode(), is(equalTo(200)));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testAsgStatusUpdateReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("PUT")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/asg/" + instanceInfo.getASGName() + "/status")
  ).respond(
      response().withStatusCode(200)
  );
  EurekaHttpResponse<Void> response = replicationClient.statusUpdate(instanceInfo.getASGName(), ASGStatus.ENABLED);
  assertThat(response.getStatusCode(), is(equalTo(200)));
}

代码示例来源:origin: oblac/jodd

@Test
void testDirect() {
  HttpResponse response = HttpRequest.get("http://localhost:1080/get_books").send();
  assertEquals(200, response.statusCode());
  assertTrue(response.body().contains("Tatum"));
  proxy.verify(request().withPath("/get_books"), exactly(0));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testCancelReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("DELETE")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName() + '/' + instanceInfo.getId())
  ).respond(
      response().withStatusCode(204)
  );
  EurekaHttpResponse<Void> response = replicationClient.cancel(instanceInfo.getAppName(), instanceInfo.getId());
  assertThat(response.getStatusCode(), is(equalTo(204)));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testCancelReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("DELETE")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName() + '/' + instanceInfo.getId())
  ).respond(
      response().withStatusCode(204)
  );
  EurekaHttpResponse<Void> response = replicationClient.cancel(instanceInfo.getAppName(), instanceInfo.getId());
  assertThat(response.getStatusCode(), is(equalTo(204)));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testDeleteStatusOverrideReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("DELETE")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName() + '/' + instanceInfo.getId() + "/status")
  ).respond(
      response().withStatusCode(204)
  );
  EurekaHttpResponse<Void> response = replicationClient.deleteStatusOverride(instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo);
  assertThat(response.getStatusCode(), is(equalTo(204)));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testDeleteStatusOverrideReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("DELETE")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName() + '/' + instanceInfo.getId() + "/status")
  ).respond(
      response().withStatusCode(204)
  );
  EurekaHttpResponse<Void> response = replicationClient.deleteStatusOverride(instanceInfo.getAppName(), instanceInfo.getId(), instanceInfo);
  assertThat(response.getStatusCode(), is(equalTo(204)));
}

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest clone() {
  return not(request(), not)
    .withMethod(method)
    .withPath(path)
    .withQueryStringParameters(getQueryStringParameters().clone())
    .withBody(body)
    .withHeaders(getHeaders().clone())
    .withCookies(getCookies().clone())
    .withKeepAlive(keepAlive)
    .withSecure(secure);
}

代码示例来源:origin: Netflix/eureka

@Test
public void testStatusUpdateReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("PUT")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName() + '/' + instanceInfo.getId() + "/status")
  ).respond(
      response().withStatusCode(200)
  );
  EurekaHttpResponse<Void> response = replicationClient.statusUpdate(instanceInfo.getAppName(), instanceInfo.getId(), InstanceStatus.DOWN, instanceInfo);
  assertThat(response.getStatusCode(), is(equalTo(200)));
}

代码示例来源:origin: Netflix/eureka

@Test
public void testStatusUpdateReplication() throws Exception {
  serverMockClient.when(
      request()
          .withMethod("PUT")
          .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
          .withPath("/eureka/v2/apps/" + instanceInfo.getAppName() + '/' + instanceInfo.getId() + "/status")
  ).respond(
      response().withStatusCode(200)
  );
  EurekaHttpResponse<Void> response = replicationClient.statusUpdate(instanceInfo.getAppName(), instanceInfo.getId(), InstanceStatus.DOWN, instanceInfo);
  assertThat(response.getStatusCode(), is(equalTo(200)));
}

代码示例来源:origin: oblac/jodd

@Test
void testDirectHttps() {
  HttpResponse response = HttpRequest.get("https://localhost:1080/get_books").trustAllCerts(true).send();
  assertEquals(200, response.statusCode());
  assertTrue(response.body().contains("Tatum"));
  proxy.verify(request().withPath("/get_books"), exactly(0));
}

代码示例来源:origin: oblac/jodd

@Test
void testSocks5Proxy() {
  SocketHttpConnectionProvider s = new SocketHttpConnectionProvider();
  s.useProxy(ProxyInfo.socks5Proxy("localhost", 1090, null, null));
  HttpResponse response = HttpRequest.get("http://localhost:1080/get_books")
    .withConnectionProvider(s)
    .send();
  assertEquals(200, response.statusCode());
  assertTrue(response.body().contains("Tatum"));
  proxy.verify(request().withPath("/get_books"), exactly(1));
}

代码示例来源:origin: oblac/jodd

@Test
void testSocks5ProxyWithHttps() {
  SocketHttpConnectionProvider s = new SocketHttpConnectionProvider();
  s.useProxy(ProxyInfo.socks5Proxy("localhost", 1090, null, null));
  HttpResponse response = HttpRequest.get("https://localhost:1080/get_books")
    .withConnectionProvider(s)
    .trustAllCerts(true)
    .send();
  assertEquals(200, response.statusCode());
  assertTrue(response.body().contains("Tatum"));
  proxy.verify(request().withPath("/get_books"), exactly(1));
}

相关文章