本文整理了Java中org.mockserver.model.HttpResponse.withStatusCode()
方法的一些代码示例,展示了HttpResponse.withStatusCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.withStatusCode()
方法的具体详情如下:
包路径:org.mockserver.model.HttpResponse
类名称:HttpResponse
方法名:withStatusCode
[英]The status code to return, such as 200, 404, the status code specified here will result in the default status message for this status code for example for 200 the status message "OK" is used
[中]要返回的状态代码,如200、404,此处指定的状态代码将导致此状态代码的默认状态消息,例如,对于200,使用状态消息“OK”
代码示例来源:origin: jamesdbloom/mockserver
private void setStatusCode(HttpResponse httpResponse, FullHttpResponse fullHttpResponse) {
HttpResponseStatus status = fullHttpResponse.status();
httpResponse.withStatusCode(status.code());
httpResponse.withReasonPhrase(status.reasonPhrase());
}
代码示例来源:origin: jamesdbloom/mockserver
@Override
public void writeResponse(HttpRequest request, HttpResponseStatus responseStatus, String body, String contentType) {
HttpResponse response = response()
.withStatusCode(responseStatus.code())
.withBody(body);
if (body != null && !body.isEmpty()) {
response.replaceHeader(header(CONTENT_TYPE.toString(), contentType + "; charset=utf-8"));
}
writeResponse(request, response, true);
}
代码示例来源:origin: jamesdbloom/mockserver
/**
* Static builder to create a not found response.
*/
public static HttpResponse notFoundResponse() {
return new HttpResponse().withStatusCode(NOT_FOUND_404.code()).withReasonPhrase(NOT_FOUND_404.reasonPhrase());
}
代码示例来源:origin: jamesdbloom/mockserver
@Override
public void writeResponse(HttpRequest request, HttpResponseStatus responseStatus, String body, String contentType) {
HttpResponse response = response()
.withStatusCode(responseStatus.code())
.withReasonPhrase(responseStatus.reasonPhrase())
.withBody(body);
if (body != null && !body.isEmpty()) {
response.replaceHeader(header(CONTENT_TYPE.toString(), contentType + "; charset=utf-8"));
}
writeResponse(request, response, true);
}
代码示例来源:origin: jamesdbloom/mockserver
/**
* Static builder to create a response with a 200 status code and the string response body.
*
* @param body a string
*/
public static HttpResponse response(String body) {
return new HttpResponse().withStatusCode(OK_200.code()).withReasonPhrase(OK_200.reasonPhrase()).withBody(body);
}
代码示例来源:origin: jamesdbloom/mockserver
public HttpResponse clone() {
return response()
.withStatusCode(statusCode)
.withReasonPhrase(reasonPhrase)
.withBody(body)
.withHeaders(headers.clone())
.withCookies(cookies.clone())
.withDelay(getDelay())
.withConnectionOptions(connectionOptions);
}
}
代码示例来源:origin: jamesdbloom/mockserver
public HttpResponse buildObject() {
return new HttpResponse()
.withStatusCode(statusCode)
.withReasonPhrase(reasonPhrase)
.withBody(body != null ? body.buildObject() : null)
.withHeaders(headers)
.withCookies(cookies)
.withDelay((delay != null ? delay.buildObject() : null))
.withConnectionOptions((connectionOptions != null ? connectionOptions.buildObject() : null));
}
代码示例来源: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: 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: apache/incubator-gobblin
@Test(enabled=false, expectedExceptions = SocketException.class)
public void mustRefuseConnectionWhenProxyRefuses() throws Exception{
mockServer.when(HttpRequest.request().withMethod("CONNECT").withPath("www.us.apache.org:80"))
.respond(HttpResponse.response().withStatusCode(403));
Tunnel tunnel = Tunnel.build("example.org", 80, "localhost", PORT);
try {
int tunnelPort = tunnel.getPort();
fetchContent(tunnelPort);
} finally {
tunnel.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!