本文整理了Java中org.mockserver.model.HttpRequest.withMethod()
方法的一些代码示例,展示了HttpRequest.withMethod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.withMethod()
方法的具体详情如下:
包路径:org.mockserver.model.HttpRequest
类名称:HttpRequest
方法名:withMethod
[英]The HTTP method to match on such as "GET" or "POST"
[中]要匹配的HTTP方法,如“GET”或“POST”
代码示例来源: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 all expectations and logs 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
*/
public MockServerClient clear(HttpRequest httpRequest) {
sendRequest(request().withMethod("PUT").withPath(calculatePath("clear")).withBody(httpRequest != null ? httpRequestSerializer.serialize(httpRequest) : "", StandardCharsets.UTF_8));
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: apache/incubator-gobblin
private void mockExample()
throws IOException {
mockServer.when(HttpRequest.request().withMethod("CONNECT").withPath("example.org:80"))
.respond(HttpResponse.response().withStatusCode(200));
mockServer.when(HttpRequest.request().withMethod("GET").withPath("/"))
.respond(HttpResponse.response(IOUtils.toString(getClass().getResourceAsStream("/example.org.html"))));
}
代码示例来源:origin: jamesdbloom/mockserver
void sendExpectation(Expectation expectation) {
HttpResponse httpResponse = sendRequest(request().withMethod("PUT").withPath(calculatePath("expectation")).withBody(expectation != null ? expectationSerializer.serialize(expectation) : "", StandardCharsets.UTF_8));
if (httpResponse != null && httpResponse.getStatusCode() != 201) {
throw new ClientException(formatLogMessage("error:{}while submitted expectation:{}", httpResponse.getBody(), expectation));
}
}
代码示例来源:origin: jamesdbloom/mockserver
/**
* Bind new ports to listen on
*/
public List<Integer> bind(Integer... ports) {
String boundPorts = sendRequest(request().withMethod("PUT").withPath(calculatePath("bind")).withBody(portBindingSerializer.serialize(portBinding(ports)), StandardCharsets.UTF_8)).getBodyAsString();
return portBindingSerializer.deserialize(boundPorts).getPorts();
}
代码示例来源: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: 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: 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: 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)));
}
内容来源于网络,如有侵权,请联系作者删除!