本文整理汇总了Java中org.mockserver.model.HttpResponse类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponse类的具体用法?Java HttpResponse怎么用?Java HttpResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponse类属于org.mockserver.model包,在下文中一共展示了HttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startServer
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void startServer() {
mockServer = ClientAndServer.startClientAndServer(7755);
MockServerClient client = new MockServerClient("localhost", 7755)
.reset();
client.when(HttpRequest.request()
.withMethod("PUT")
.withPath("/v0.3/traces")
.withHeaders(new Header("Content-Type", "application/msgpack")),
Times.exactly(1), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
.respond(HttpResponse.response()
.withStatusCode(200)
.withHeaders(new Header("Content-Type", "text/plain"))
.withBody("OK\n")
);
}
示例2: emulateV0_2
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
@Before
public void emulateV0_2() {
MockServerClient client = new MockServerClient("localhost", APM_PORT).reset();
client.when(
HttpRequest.request()
.withMethod("PUT")
.withPath("/v0.3/traces"), Times.unlimited(), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
.respond(HttpResponse.response()
.withStatusCode(404)
.withHeaders(new Header("Content-Type", "text/plain")));
client.when(
HttpRequest.request()
.withMethod("PUT")
.withPath("/v0.2/traces"), Times.unlimited(), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
.respond(HttpResponse.response()
.withStatusCode(200)
.withHeaders(new Header("Content-Type", "text/plain"))
.withBody("OK\n").withDelay(new Delay(TimeUnit.MILLISECONDS, 20)));
}
示例3: emulateV0_2
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
@Before
public void emulateV0_2() {
MockServerClient client = new MockServerClient("localhost", APM_PORT)
.reset();
client
.when(HttpRequest.request().withMethod("PUT").withPath("/v0.3/traces"),
Times.unlimited(), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
.respond(HttpResponse.response().withStatusCode(404)
.withHeaders(new Header("Content-Type", "text/plain"))
);
client
.when(HttpRequest.request().withMethod("PUT").withPath("/v0.2/traces"),
Times.unlimited(), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
.respond(HttpResponse.response().withStatusCode(200)
.withHeaders(new Header("Content-Type", "text/plain")).withBody("OK\n")
.withDelay(new Delay(TimeUnit.MILLISECONDS, 20)));
}
示例4: emailUser
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void emailUser(MockServerClient mockServerClient) {
mockServerClient.
dumpToLog().
when(
HttpRequest.request()
.withMethod("POST")
.withCookie(Cookie.cookie("session", "0a1bc2a7-11ef-4781-9c06-8d9b42719797"))
.withCookie(Cookie.cookie("username", "jdoe"))
.withPath("/user/email")
.withBody("{\"name\":\"John Doe\"}"),
Times.unlimited()
).respond(
HttpResponse.response()
.withStatusCode(200)
);
}
示例5: mutateUser
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void mutateUser(MockServerClient mockServerClient) {
mockServerClient.
dumpToLog().
when(
HttpRequest.request()
.withMethod("PUT")
.withCookie(Cookie.cookie("session", "aa8a2e85-412e-46a2-889f-b2c133a59c89"))
.withPath("/user")
.withBody("{\"name\":\"John Doe\"}"),
Times.unlimited()
).respond(
HttpResponse.response()
.withStatusCode(200)
);
}
示例6: getUsers
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getUsers(MockServerClient mockServerClient) {
mockServerClient
.dumpToLog()
.when(
HttpRequest.request()
.withMethod("GET")
.withPath("/user")
.withHeader(Header.header("X-SESSION-ID", "020835c7-cf7e-4ba5-b117-4402e5d79079"))
.withQueryStringParameter(Parameter.param("byUsername", "jdoe")),
Times.unlimited()
).respond(
HttpResponse.response()
.withStatusCode(200)
.withBody("{ \"users\" : [{ \"name\" : \"John Doe\" }] }")
);
}
示例7: getUser
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getUser(MockServerClient mockServerClient) {
mockServerClient
.dumpToLog()
.when(
HttpRequest.request()
.withMethod("GET")
.withHeader(Header.header("X-SESSION-ID", "55892d6d-77df-4617-b728-6f5de97f5752"))
.withPath("/user/jdoe"),
Times.unlimited()
).respond(
HttpResponse.response()
.withStatusCode(200)
.withBody("{ \"name\" : \"John Doe\" }")
);
}
示例8: getCachedUser
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getCachedUser(MockServerClient mockServerClient) {
mockServerClient
.dumpToLog()
.when(
HttpRequest.request()
.withMethod("GET")
.withHeader(Header.header("X-SESSION-ID", "55892d6d-77df-4617-b728-6f5de97f5752"))
.withPath("/user/bdoe"),
Times.unlimited()
).respond(
HttpResponse.response()
.withStatusCode(200)
.withHeader(Header.header("Cache-Control","no-transform,public,max-age=300,s-maxage=900"))
.withBody("{ \"name\" : \"Bob Doe\" }")
);
}
示例9: getUserAddress
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getUserAddress(MockServerClient mockServerClient) {
mockServerClient
.dumpToLog()
.when(
HttpRequest.request()
.withMethod("GET")
.withHeader(Header.header("Cache-Control", "no-cache"))
.withPath("/user/address/jdoe"),
Times.unlimited()
).respond(
HttpResponse.response()
.withStatusCode(200)
.withBody("{ \"address\" : \"1060 W Addison St, Chicago, IL 60613\" }")
);
}
示例10: getRoleUsers
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getRoleUsers(MockServerClient mockServerClient) {
mockServerClient
.dumpToLog()
.when(
HttpRequest.request()
.withMethod("GET")
.withPath("/user/role")
.withQueryStringParameter(Parameter.param("byRole", "vanessa")),
Times.unlimited()
).respond(
HttpResponse.response()
.withStatusCode(200)
.withBody("{ \"users\" : [] }")
);
}
示例11: testEnableAuth
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
@Test
public void testEnableAuth() throws Exception {
VaultConfiguration conf = VaultConfigurationBuilder.newVaultConfiguration()
.withAddress(address)
.withToken(token)
.build();
new MockServerClient(localhost, mockServerRule.getPort())
.when(
HttpRequest.request()
.withMethod("POST")
.withHeader(tokenHeader)
.withPath("/v1/sys/auth/app-id")
.withBody("{\"type\":\"app-id\"}"),
Times.exactly(1)
)
.respond(
HttpResponse.response()
.withStatusCode(HttpStatusCode.NO_CONTENT_204.code())
.withHeader(contentJson)
);
VaultClient vault = new VaultClient(conf);
assertTrue(vault.sys().auth().enable("app-id", "app-id"));
}
示例12: addEndpoint
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void addEndpoint(String baseURL, String endpointName, MockServerClient mockServerClient) {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("mock_responses/" + endpointName + "_response.json")) {
String response = getStringFromResource(is);
mockServerClient.when(HttpRequest.request()
.withMethod("POST")
.withPath(baseURL + endpointName))
.respond(HttpResponse.response()
.withStatusCode(200)
.withHeaders(
new Header(HttpHeaders.CONTENT_TYPE, "application/json")
)
.withBody(response));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
示例13: addSentimentADM
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void addSentimentADM(String baseURL, MockServerClient mockServerClient) {
try (InputStream is = getClass().getClassLoader().getResourceAsStream("mock_responses/sentiment_adm_response.json")) {
String response = getStringFromResource(is);
mockServerClient.when(HttpRequest.request()
.withMethod("POST")
.withPath(baseURL + "sentiment").withQueryStringParameter(new Parameter("output", "rosette")))
.respond(HttpResponse.response()
.withStatusCode(200)
.withHeaders(
new Header(HttpHeaders.CONTENT_TYPE, "application/json")
)
.withBody(response));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
示例14: startServer
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
@Before
public void startServer() {
mockServer = ClientAndServer.startClientAndServer(7755);
new MockServerClient("localhost", 7755)
.when(HttpRequest.request().withMethod("PUT"),
Times.exactly(1),
TimeToLive.exactly(TimeUnit.MINUTES, 1l))
.respond(HttpResponse.response().withStatusCode(200)
.withHeaders(new Header("Content-Type", "text/plain")).withBody("OK\n")
.withDelay(new Delay(TimeUnit.SECONDS, 1)));
}
示例15: expectations
import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void expectations(int status) {
MockServerClient client = new MockServerClient("localhost", 7755)
.reset();
client.when(HttpRequest.request()
.withMethod("PUT")
.withPath("/v0.3/traces")
.withHeaders(new Header("Content-Type", "application/msgpack")),
Times.exactly(1), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
.respond(HttpResponse.response()
.withStatusCode(status)
.withHeaders(new Header("Content-Type", "text/plain"))
);
client.when(HttpRequest.request()
.withMethod("PUT")
.withPath("/v0.2/traces")
.withHeaders(new Header("Content-Type", "application/json")),
Times.exactly(1),
TimeToLive.exactly(TimeUnit.MINUTES, 1l))
.respond(HttpResponse.response()
.withStatusCode(200)
.withHeaders(new Header("Content-Type", "text/plain"))
.withBody("OK\n")
);
}