当前位置: 首页>>代码示例>>Java>>正文


Java Expectation类代码示例

本文整理汇总了Java中org.mockserver.mock.Expectation的典型用法代码示例。如果您正苦于以下问题:Java Expectation类的具体用法?Java Expectation怎么用?Java Expectation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Expectation类属于org.mockserver.mock包,在下文中一共展示了Expectation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldPassVerificationWithAtLeastZeroTimes

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldPassVerificationWithAtLeastZeroTimes() {
    // given
    HttpRequest httpRequest = new HttpRequest().withPath("some_path");
    HttpRequest otherHttpRequest = new HttpRequest().withPath("some_other_path");
    MockServerEventLog logFilter = new MockServerEventLog(mock(MockServerLogger.class), scheduler);

    // when
    logFilter.add(new ExpectationMatchLogEntry(httpRequest, new Expectation(httpRequest).thenRespond(response("some_response"))));
    logFilter.add(new ExpectationMatchLogEntry(otherHttpRequest, new Expectation(otherHttpRequest).thenRespond(response("some_response"))));
    logFilter.add(new ExpectationMatchLogEntry(httpRequest, new Expectation(httpRequest).thenRespond(response("some_response"))));

    // then
    assertThat(logFilter.verify(
        verification()
            .withRequest(
                new HttpRequest().withPath("some_non_matching_path")
            )
            .withTimes(atLeast(0))
        ),
        is(""));
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:23,代码来源:LogFilterExpectationMatchLogEntryVerificationTest.java

示例2: shouldPassVerificationWithExactlyZeroTimes

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldPassVerificationWithExactlyZeroTimes() {
    // given
    HttpRequest httpRequest = new HttpRequest().withPath("some_path");
    HttpRequest otherHttpRequest = new HttpRequest().withPath("some_other_path");
    MockServerEventLog logFilter = new MockServerEventLog(mock(MockServerLogger.class), scheduler);

    // when
    logFilter.add(new ExpectationMatchLogEntry(httpRequest, new Expectation(httpRequest).thenRespond(response("some_response"))));
    logFilter.add(new ExpectationMatchLogEntry(otherHttpRequest, new Expectation(otherHttpRequest).thenRespond(response("some_response"))));
    logFilter.add(new ExpectationMatchLogEntry(httpRequest, new Expectation(httpRequest).thenRespond(response("some_response"))));

    // then
    assertThat(logFilter.verify(
            verification()
                    .withRequest(
                            new HttpRequest()
                                    .withPath("some_non_matching_path")
                    )
                    .withTimes(exactly(0))
            ),
            is(""));
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:24,代码来源:LogFilterMixedLogEntryVerificationTest.java

示例3: shouldSetupExpectationWithResponse

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldSetupExpectationWithResponse() {
    // given
    HttpRequest httpRequest =
        new HttpRequest()
            .withPath("/some_path")
            .withBody(new StringBody("some_request_body"));
    HttpResponse httpResponse =
        new HttpResponse()
            .withBody("some_response_body")
            .withHeaders(new Header("responseName", "responseValue"));

    // when
    ForwardChainExpectation forwardChainExpectation = mockServerClient.when(httpRequest);
    forwardChainExpectation.respond(httpResponse);

    // then
    Expectation expectation = forwardChainExpectation.getExpectation();
    assertTrue(expectation.isActive());
    assertSame(httpResponse, expectation.getHttpResponse());
    assertEquals(Times.unlimited(), expectation.getTimes());
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:23,代码来源:MockServerClientTest.java

示例4: shouldSetupExpectationWithForward

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldSetupExpectationWithForward() {
    // given
    HttpRequest httpRequest =
        new HttpRequest()
            .withPath("/some_path")
            .withBody(new StringBody("some_request_body"));
    HttpForward httpForward =
        new HttpForward()
            .withHost("some_host")
            .withPort(9090)
            .withScheme(HttpForward.Scheme.HTTPS);

    // when
    ForwardChainExpectation forwardChainExpectation = mockServerClient.when(httpRequest);
    forwardChainExpectation.forward(httpForward);

    // then
    Expectation expectation = forwardChainExpectation.getExpectation();
    assertTrue(expectation.isActive());
    assertSame(httpForward, expectation.getHttpForward());
    assertEquals(Times.unlimited(), expectation.getTimes());
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:24,代码来源:MockServerClientTest.java

示例5: shouldSetupExpectationWithForwardClassCallback

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldSetupExpectationWithForwardClassCallback() {
    // given
    HttpRequest httpRequest =
        new HttpRequest()
            .withPath("/some_path")
            .withBody(new StringBody("some_request_body"));
    HttpClassCallback httpClassCallback =
        new HttpClassCallback()
            .withCallbackClass("some_class");

    // when
    ForwardChainExpectation forwardChainExpectation = mockServerClient.when(httpRequest);
    forwardChainExpectation.forward(httpClassCallback);

    // then
    Expectation expectation = forwardChainExpectation.getExpectation();
    assertTrue(expectation.isActive());
    assertSame(httpClassCallback, expectation.getHttpForwardClassCallback());
    assertEquals(Times.unlimited(), expectation.getTimes());
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:22,代码来源:MockServerClientTest.java

示例6: shouldRetrieveExpectationsWithNullRequest

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldRetrieveExpectationsWithNullRequest() {
    // given
    Expectation[] expectations = {};
    when(mockHttpClient.sendRequest(any(HttpRequest.class), anyLong(), any(TimeUnit.class))).thenReturn(response().withBody("body"));
    when(mockExpectationSerializer.deserializeArray("body")).thenReturn(expectations);

    // when
    assertSame(expectations, mockServerClient.retrieveRecordedExpectations(null));

    // then
    verify(mockHttpClient).sendRequest(
        request()
            .withHeader(HOST.toString(), "localhost:" + 1080)
            .withMethod("PUT")
            .withPath("/retrieve")
            .withQueryStringParameter("type", RetrieveType.RECORDED_EXPECTATIONS.name())
            .withQueryStringParameter("format", Format.JSON.name())
            .withBody("", StandardCharsets.UTF_8),
        20000,
        TimeUnit.MILLISECONDS
    );
    verify(mockExpectationSerializer).deserializeArray("body");
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:25,代码来源:MockServerClientTest.java

示例7: shouldRetrieveRecordedExpectations

import org.mockserver.mock.Expectation; //导入依赖的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"))
    )));
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:23,代码来源:MockServerServletTest.java

示例8: shouldClear

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldClear() {
    // given
    httpStateHandler.add(new Expectation(request("request_one")).thenRespond(response("response_one")));
    httpStateHandler.log(new RequestLogEntry(request("request_one")));
    MockHttpServletRequest clearRequest = buildHttpServletRequest(
        "PUT",
        "/clear",
        httpRequestSerializer.serialize(request("request_one"))
    );

    // when
    proxyServlet.service(clearRequest, response);

    // then
    assertResponse(response, 200, "");
    assertThat(httpStateHandler.firstMatchingExpectation(request("request_one")), is(nullValue()));
    assertThat(httpStateHandler.retrieve(request("/retrieve")
        .withMethod("PUT")
        .withBody(
            httpRequestSerializer.serialize(request("request_one"))
        )), is(response().withBody("[]", JSON_UTF_8).withStatusCode(200)));
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:24,代码来源:ProxyServletTest.java

示例9: shouldPassVerificationSequenceWithNoRequest

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldPassVerificationSequenceWithNoRequest() {
    // given
    MockServerEventLog logFilter = new MockServerEventLog(mock(MockServerLogger.class), scheduler);

    // when
    logFilter.add(new RequestLogEntry(request("one")));
    logFilter.add(new RequestResponseLogEntry(request("multi"), response("multi")));
    logFilter.add(new ExpectationMatchLogEntry(request("three"), new Expectation(request("three")).thenRespond(response("three"))));
    logFilter.add(new RequestLogEntry(request("multi")));
    logFilter.add(new RequestResponseLogEntry(request("four"), response("four")));

    // then
    assertThat(logFilter.verify(
            new VerificationSequence()
                    .withRequests(

                    )
            ),
            is(""));
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:22,代码来源:LogFilterMixedLogEntryVerificationSequenceTest.java

示例10: shouldPassVerificationWithExactlyTwoTimes

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldPassVerificationWithExactlyTwoTimes() {
    // given
    HttpRequest httpRequest = new HttpRequest().withPath("some_path");
    HttpRequest otherHttpRequest = new HttpRequest().withPath("some_other_path");
    MockServerEventLog logFilter = new MockServerEventLog(mock(MockServerLogger.class), scheduler);

    // when
    logFilter.add(new ExpectationMatchLogEntry(httpRequest, new Expectation(httpRequest).thenRespond(response("some_response"))));
    logFilter.add(new ExpectationMatchLogEntry(otherHttpRequest, new Expectation(otherHttpRequest).thenRespond(response("some_response"))));
    logFilter.add(new ExpectationMatchLogEntry(httpRequest, new Expectation(httpRequest).thenRespond(response("some_response"))));

    // then
    assertThat(logFilter.verify(
        verification()
            .withRequest(
                new HttpRequest()
                    .withPath("some_path")
            )
            .withTimes(exactly(2))
        ),
        is(""));
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:24,代码来源:LogFilterExpectationMatchLogEntryVerificationTest.java

示例11: shouldClear

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldClear() {
    // given
    httpStateHandler.add(new Expectation(request("request_one")).thenRespond(response("response_one")));
    httpStateHandler.log(new RequestLogEntry(request("request_one")));
    HttpRequest clearRequest = request("/clear")
        .withMethod("PUT")
        .withBody(
            httpRequestSerializer.serialize(request("request_one"))
        );

    // when
    embeddedChannel.writeInbound(clearRequest);

    // then
    assertResponse(200, "");
    assertThat(httpStateHandler.firstMatchingExpectation(request("request_one")), is(nullValue()));
    assertThat(httpStateHandler.retrieve(request("/retrieve")
        .withMethod("PUT")
        .withBody(
            httpRequestSerializer.serialize(request("request_one"))
        )), is(response().withBody("[]", JSON_UTF_8).withStatusCode(200)));
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:24,代码来源:MockServerHandlerTest.java

示例12: shouldRetrieveRecordedExpectations

import org.mockserver.mock.Expectation; //导入依赖的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"))
    )));
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:23,代码来源:MockServerHandlerTest.java

示例13: shouldRetrieveActiveExpectations

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldRetrieveActiveExpectations() {
    // given
    Expectation expectationOne = new Expectation(request("request_one")).thenRespond(response("response_one"));
    httpStateHandler.add(expectationOne);
    HttpRequest expectationRetrieveExpectationsRequest = request("/retrieve")
        .withMethod("PUT")
        .withQueryStringParameter("type", RetrieveType.ACTIVE_EXPECTATIONS.name())
        .withBody(
            httpRequestSerializer.serialize(request("request_one"))
        );

    // when
    embeddedChannel.writeInbound(expectationRetrieveExpectationsRequest);

    // then
    assertResponse(200, expectationSerializer.serialize(Collections.singletonList(
        expectationOne
    )));
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:21,代码来源:MockServerHandlerTest.java

示例14: deserialize

import org.mockserver.mock.Expectation; //导入依赖的package包/类
public Expectation deserialize(String jsonExpectation) {
    if (Strings.isNullOrEmpty(jsonExpectation)) {
        throw new IllegalArgumentException("1 error:" + NEW_LINE + " - an expectation is required but value was \"" + String.valueOf(jsonExpectation) + "\"");
    } else {
        String validationErrors = expectationValidator.isValid(jsonExpectation);
        if (validationErrors.isEmpty()) {
            Expectation expectation = null;
            try {
                ExpectationDTO expectationDTO = objectMapper.readValue(jsonExpectation, ExpectationDTO.class);
                if (expectationDTO != null) {
                    expectation = expectationDTO.buildObject();
                }
            } catch (Exception e) {
                mockServerLogger.error("Exception while parsing [" + jsonExpectation + "] for Expectation", e);
                throw new RuntimeException("Exception while parsing [" + jsonExpectation + "] for Expectation", e);
            }
            return expectation;
        } else {
            mockServerLogger.info("Validation failed:{}" + NEW_LINE + " Expectation:{}" + NEW_LINE + " Schema:{}", validationErrors, jsonExpectation, expectationValidator.getSchema());
            throw new IllegalArgumentException(validationErrors);
        }
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:24,代码来源:ExpectationSerializer.java

示例15: shouldProcessResponseTemplateAction

import org.mockserver.mock.Expectation; //导入依赖的package包/类
@Test
public void shouldProcessResponseTemplateAction() {
    // given
    HttpTemplate template = template(HttpTemplate.TemplateType.JAVASCRIPT, "some_template");
    expectation = new Expectation(request, Times.unlimited(), TimeToLive.unlimited()).thenRespond(template);
    when(mockHttpStateHandler.firstMatchingExpectation(request)).thenReturn(expectation);

    // when
    actionHandler.processAction(request, mockResponseWriter, null, new HashSet<String>(), false, true);

    // then
    verify(mockHttpResponseTemplateActionHandler).handle(template, request);
    verify(mockResponseWriter).writeResponse(request, 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:{}", response, request, expectation);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:17,代码来源:ActionHandlerTest.java


注:本文中的org.mockserver.mock.Expectation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。