本文整理汇总了Java中org.mockserver.matchers.TimeToLive类的典型用法代码示例。如果您正苦于以下问题:Java TimeToLive类的具体用法?Java TimeToLive怎么用?Java TimeToLive使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TimeToLive类属于org.mockserver.matchers包,在下文中一共展示了TimeToLive类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emulateV0_2
import org.mockserver.matchers.TimeToLive; //导入依赖的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)));
}
示例2: emulateV0_2
import org.mockserver.matchers.TimeToLive; //导入依赖的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: startServer
import org.mockserver.matchers.TimeToLive; //导入依赖的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")
);
}
示例4: startServer
import org.mockserver.matchers.TimeToLive; //导入依赖的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)));
}
示例5: expectations
import org.mockserver.matchers.TimeToLive; //导入依赖的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")
);
}
示例6: shouldRetrieveRecordedExpectations
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Test
public void shouldRetrieveRecordedExpectations() {
// given
httpStateHandler.log(new RequestResponseLogEntry(
request("request_one"),
response("response_one")
));
MockHttpServletRequest expectationRetrieveExpectationsRequest = buildHttpServletRequest(
"PUT",
"/retrieve",
httpRequestSerializer.serialize(request("request_one"))
);
expectationRetrieveExpectationsRequest.setQueryString("type=" + RetrieveType.RECORDED_EXPECTATIONS.name());
// when
mockServerServlet.service(expectationRetrieveExpectationsRequest, response);
// then
assertResponse(response, 200, expectationSerializer.serialize(Collections.singletonList(
new Expectation(request("request_one"), Times.once(), TimeToLive.unlimited()).thenRespond(response("response_one"))
)));
}
示例7: shouldRetrieveRecordedExpectations
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Test
public void shouldRetrieveRecordedExpectations() {
// given
httpStateHandler.log(new RequestResponseLogEntry(
request("request_one"),
response("response_one")
));
MockHttpServletRequest expectationRetrieveExpectationsRequest = buildHttpServletRequest(
"PUT",
"/retrieve",
httpRequestSerializer.serialize(request("request_one"))
);
expectationRetrieveExpectationsRequest.setQueryString("type=" + RetrieveType.RECORDED_EXPECTATIONS.name());
// when
proxyServlet.service(expectationRetrieveExpectationsRequest, response);
// then
assertResponse(response, 200, expectationSerializer.serialize(Collections.singletonList(
new Expectation(request("request_one"), Times.once(), TimeToLive.unlimited()).thenRespond(response("response_one"))
)));
}
示例8: shouldRetrieveRecordedExpectations
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Test
public void shouldRetrieveRecordedExpectations() {
// given
httpStateHandler.log(new RequestResponseLogEntry(
request("request_one"),
response("response_one")
));
HttpRequest expectationRetrieveExpectationsRequest = request("/retrieve")
.withMethod("PUT")
.withQueryStringParameter("type", RetrieveType.RECORDED_EXPECTATIONS.name())
.withBody(
httpRequestSerializer.serialize(request("request_one"))
);
// when
embeddedChannel.writeInbound(expectationRetrieveExpectationsRequest);
// then
assertResponse(200, expectationSerializer.serialize(Collections.singletonList(
new Expectation(request("request_one"), Times.once(), TimeToLive.unlimited()).thenRespond(response("response_one"))
)));
}
示例9: shouldClearNoExpectations
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Test
public void shouldClearNoExpectations() {
// given
HttpResponse httpResponse = new HttpResponse().withBody("somebody");
Expectation[] expectations = new Expectation[]{
new Expectation(new HttpRequest().withPath("somepath"), Times.unlimited(), TimeToLive.unlimited()).thenRespond(httpResponse),
new Expectation(new HttpRequest().withPath("somepath"), Times.unlimited(), TimeToLive.unlimited()).thenRespond(httpResponse)
};
for (Expectation expectation : expectations) {
mockServerMatcher.add(expectation);
}
List<HttpRequestMatcher> httpRequestMatchers = new ArrayList<>(mockServerMatcher.httpRequestMatchers);
// when
mockServerMatcher.clear(new HttpRequest().withPath("foobar"));
// then
assertThat(mockServerMatcher.httpRequestMatchers, is(httpRequestMatchers));
}
示例10: shouldHandleNullFieldInput
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Test
public void shouldHandleNullFieldInput() {
// when
ExpectationDTO expectationDTO = new ExpectationDTO(new Expectation(null, null, TimeToLive.unlimited()));
// then
assertThat(expectationDTO.getHttpRequest(), is(nullValue()));
assertThat(expectationDTO.getTimes(), is(nullValue()));
assertThat(expectationDTO.getHttpResponse(), is(nullValue()));
assertThat(expectationDTO.getHttpResponseTemplate(), is(nullValue()));
assertThat(expectationDTO.getHttpResponseClassCallback(), is(nullValue()));
assertThat(expectationDTO.getHttpResponseObjectCallback(), is(nullValue()));
assertThat(expectationDTO.getHttpForward(), is(nullValue()));
assertThat(expectationDTO.getHttpForwardTemplate(), is(nullValue()));
assertThat(expectationDTO.getHttpForwardClassCallback(), is(nullValue()));
assertThat(expectationDTO.getHttpForwardObjectCallback(), is(nullValue()));
assertThat(expectationDTO.getHttpOverrideForwardedRequest(), is(nullValue()));
assertThat(expectationDTO.getHttpError(), is(nullValue()));
}
示例11: respondWhenPathMatchesExpectationWithMultipleResponses
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Test
public void respondWhenPathMatchesExpectationWithMultipleResponses() {
// when
Expectation expectationZero = new Expectation(new HttpRequest().withPath("somepath"), Times.exactly(2), TimeToLive.unlimited()).thenRespond(httpResponse[0].withBody("somebody1"));
mockServerMatcher.add(expectationZero);
Expectation expectationOne = new Expectation(new HttpRequest().withPath("somepath"), Times.exactly(1), TimeToLive.unlimited()).thenRespond(httpResponse[1].withBody("somebody2"));
mockServerMatcher.add(expectationOne);
Expectation expectationTwo = new Expectation(new HttpRequest().withPath("somepath")).thenRespond(httpResponse[2].withBody("somebody3"));
mockServerMatcher.add(expectationTwo);
// then
assertEquals(expectationZero, mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("somepath")));
assertEquals(expectationZero, mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("somepath")));
assertEquals(expectationOne, mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("somepath")));
assertEquals(expectationTwo, mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("somepath")));
}
示例12: shouldRemoveMultipleExpiredExpectations
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Test
public void shouldRemoveMultipleExpiredExpectations() throws InterruptedException {
// when
mockServerMatcher.add(new Expectation(httpRequest.withPath("somePath"), Times.unlimited(), TimeToLive.exactly(TimeUnit.MICROSECONDS, 0L)).thenRespond(httpResponse.withBody("someBody")));
Expectation expectationToExpireAfter3Seconds = new Expectation(httpRequest.withPath("somePath"), Times.unlimited(), TimeToLive.exactly(TimeUnit.SECONDS, 3L));
mockServerMatcher.add(expectationToExpireAfter3Seconds.thenRespond(httpResponse.withBody("someBody")));
// then
assertThat(mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("somePath")), is(expectationToExpireAfter3Seconds));
assertThat(mockServerMatcher.httpRequestMatchers.size(), is(1));
// when
TimeUnit.SECONDS.sleep(3);
// then - after 3 seconds
assertThat(mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("someOtherPath")), nullValue());
assertThat(mockServerMatcher.httpRequestMatchers, empty());
}
示例13: shouldNotRemoveAfterTimesComplete
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Test
public void shouldNotRemoveAfterTimesComplete() {
// when
Expectation expectation = new Expectation(new HttpRequest().withPath("somepath"), Times.exactly(2), TimeToLive.unlimited()).thenRespond(httpResponse.withBody("someBody"));
mockServerMatcher.add(expectation);
Expectation notRemovedExpectation = new Expectation(httpRequest.withPath("someOtherPath"), Times.exactly(2), TimeToLive.unlimited());
mockServerMatcher.add(notRemovedExpectation.thenRespond(response().withBody("someOtherBody")));
// then
assertEquals(expectation, mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("somepath")));
assertEquals(expectation, mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("somepath")));
assertEquals(notRemovedExpectation, mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("someOtherPath")));
assertThat(mockServerMatcher.httpRequestMatchers.size(), is(1));
// then
assertEquals(notRemovedExpectation, mockServerMatcher.firstMatchingExpectation(new HttpRequest().withPath("someOtherPath")));
assertThat(mockServerMatcher.httpRequestMatchers.size(), is(0));
}
示例14: setupMocks
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Before
public void setupMocks() {
mockHttpStateHandler = mock(HttpStateHandler.class);
when(mockHttpStateHandler.getScheduler()).thenReturn(scheduler);
actionHandler = new ActionHandler(mockHttpStateHandler, null);
initMocks(this);
request = request("some_path");
response = response("some_body");
responseFuture = SettableFuture.create();
responseFuture.set(response);
expectation = new Expectation(request, Times.unlimited(), TimeToLive.unlimited()).thenRespond(response);
when(mockHttpStateHandler.firstMatchingExpectation(request)).thenReturn(expectation);
when(mockHttpResponseActionHandler.handle(any(HttpResponse.class))).thenReturn(response);
when(mockHttpResponseTemplateActionHandler.handle(any(HttpTemplate.class), any(HttpRequest.class))).thenReturn(response);
when(mockHttpResponseClassCallbackActionHandler.handle(any(HttpClassCallback.class), any(HttpRequest.class))).thenReturn(response);
when(mockHttpForwardActionHandler.handle(any(HttpForward.class), any(HttpRequest.class))).thenReturn(responseFuture);
when(mockHttpForwardTemplateActionHandler.handle(any(HttpTemplate.class), any(HttpRequest.class))).thenReturn(responseFuture);
when(mockHttpForwardClassCallbackActionHandler.handle(any(HttpClassCallback.class), any(HttpRequest.class))).thenReturn(responseFuture);
when(mockHttpOverrideForwardedRequestActionHandler.handle(any(HttpOverrideForwardedRequest.class), any(HttpRequest.class))).thenReturn(responseFuture);
}
示例15: shouldProcessResponseAction
import org.mockserver.matchers.TimeToLive; //导入依赖的package包/类
@Test
public void shouldProcessResponseAction() {
// given
HttpResponse response = response("some_template");
expectation = new Expectation(request, Times.unlimited(), TimeToLive.unlimited()).thenRespond(response);
when(mockHttpStateHandler.firstMatchingExpectation(request)).thenReturn(expectation);
// when
actionHandler.processAction(request, mockResponseWriter, null, new HashSet<String>(), false, true);
// then
verify(mockHttpResponseActionHandler).handle(response);
verify(mockResponseWriter).writeResponse(request, this.response, false);
verify(mockHttpStateHandler, times(1)).log(new ExpectationMatchLogEntry(request, expectation));
verify(mockLogFormatter).info(request, "returning response:{}" + NEW_LINE + " for request:{}" + NEW_LINE + " for expectation:{}", this.response, request, expectation);
}