本文整理汇总了Java中org.mockserver.model.Header类的典型用法代码示例。如果您正苦于以下问题:Java Header类的具体用法?Java Header怎么用?Java Header使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Header类属于org.mockserver.model包,在下文中一共展示了Header类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifications
import org.mockserver.model.Header; //导入依赖的package包/类
private void verifications() throws AssertionError {
new MockServerClient("localhost", 7755)
.verify(HttpRequest.request()
.withMethod("PUT")
.withPath("/v0.3/traces")
.withHeaders(new Header("Content-Type", "application/msgpack")),
VerificationTimes.exactly(1))
.verify(HttpRequest.request()
.withMethod("PUT")
.withPath("/v0.2/traces")
.withHeaders(new Header("Content-Type", "application/json")),
VerificationTimes.exactly(1));
}
示例2: startServer
import org.mockserver.model.Header; //导入依赖的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")
);
}
示例3: emulateV0_2
import org.mockserver.model.Header; //导入依赖的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: emulateV0_2
import org.mockserver.model.Header; //导入依赖的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)));
}
示例5: verifications
import org.mockserver.model.Header; //导入依赖的package包/类
private void verifications() throws AssertionError {
new MockServerClient("localhost", 7755)
.verify(HttpRequest.request()
.withMethod("PUT")
.withPath("/v0.3/traces")
.withHeaders(new Header("Content-Type", "application/msgpack")),
VerificationTimes.exactly(1));
}
示例6: getUsers
import org.mockserver.model.Header; //导入依赖的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.Header; //导入依赖的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.Header; //导入依赖的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.Header; //导入依赖的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: addEndpoint
import org.mockserver.model.Header; //导入依赖的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);
}
}
示例11: addSentimentADM
import org.mockserver.model.Header; //导入依赖的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);
}
}
示例12: startServer
import org.mockserver.model.Header; //导入依赖的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)));
}
示例13: expectations
import org.mockserver.model.Header; //导入依赖的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")
);
}
示例14: prepareMockServer
import org.mockserver.model.Header; //导入依赖的package包/类
private static void prepareMockServer(MockServerClient mockServerClient, Incident incident, int statusCode, String responseBody) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mockServerClient
.when(request()
.withMethod("POST")
.withPath(EVENT_END_POINT)
.withBody(exact(mapper.writeValueAsString(incident))),
exactly(1))
.respond(response()
.withStatusCode(statusCode)
.withHeaders(
new Header("Server", "MockServer"),
new Header("Date", new Date().toString()),
new Header("Content-Type", "application/json; charset=utf-8")
)
.withBody(responseBody)
.withDelay(new Delay(TimeUnit.SECONDS, 1))
);
}
示例15: serverCalledOnceInCacheTime
import org.mockserver.model.Header; //导入依赖的package包/类
@Test
public void serverCalledOnceInCacheTime() throws Exception {
mockServer.when(request().withPath(ElasticsearchClient.CLUSTER_STATS_ENDPOINT))
.respond(response()
.withBody(new JsonBody(clusterStatsJson))
.withHeaders(new Header("Content-Type", "application/json"))
.withStatusCode(HttpServletResponse.SC_OK));
ElasticsearchClusterStats clusterStats = esClient.getClusterStats();
assertThat(clusterStats).isNotNull();
assertThat(clusterStats.getStatus()).isEqualTo("red");
assertThat(clusterStats.getNodes().getFileSystem().getTotalBytes()).isEqualTo(206289465344L);
assertThat(clusterStats.getNodes().getFileSystem().getFreeBytes()).isEqualTo(132861665280L);
assertThat(clusterStats.getNodes().getFileSystem().getAvailableBytes()).isEqualTo(122359132160L);
// Call again, should hit cache
clusterStats = esClient.getClusterStats();
assertThat(clusterStats).isNotNull();
assertThat(clusterStats.getStatus()).isEqualTo("red");
assertThat(clusterStats.getNodes().getFileSystem().getTotalBytes()).isEqualTo(206289465344L);
assertThat(clusterStats.getNodes().getFileSystem().getFreeBytes()).isEqualTo(132861665280L);
assertThat(clusterStats.getNodes().getFileSystem().getAvailableBytes()).isEqualTo(122359132160L);
// Verify mockServer calls
mockServer.verify(request().withPath(ElasticsearchClient.CLUSTER_STATS_ENDPOINT), VerificationTimes.once());
}