當前位置: 首頁>>代碼示例>>Java>>正文


Java WireMock.verify方法代碼示例

本文整理匯總了Java中com.github.tomakehurst.wiremock.client.WireMock.verify方法的典型用法代碼示例。如果您正苦於以下問題:Java WireMock.verify方法的具體用法?Java WireMock.verify怎麽用?Java WireMock.verify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.github.tomakehurst.wiremock.client.WireMock的用法示例。


在下文中一共展示了WireMock.verify方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDoubleEncodedUrlForGetForObject

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testDoubleEncodedUrlForGetForObject() {
    initialAuthenticationMock();
    mockCsrfTokenEndpoint();

    WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/api/assets?path=abc%5Cdef"))
            .willReturn(WireMock.aResponse()
                    .withStatus(HttpStatus.FOUND.value())
                    .withHeader("Location", "/api/assets?path=abc%5Cdefs")
                    .withBody("")));

    Map<String, String> uriVariables = new HashMap<>();
    uriVariables.put("path", "abc\\def");
    authenticatedRestTemplate.getForObjectWithQueryStringParams("/api/assets", String.class, uriVariables);

    WireMock.verify(WireMock.getRequestedFor(WireMock.urlEqualTo("/api/assets?path=abc%5Cdef")));
}
 
開發者ID:box,項目名稱:mojito,代碼行數:18,代碼來源:AuthenticatedRestTemplateTest.java

示例2: testAuthRestTemplateForSessionTimeoutWithPostForObject

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testAuthRestTemplateForSessionTimeoutWithPostForObject() {
    initialAuthenticationMock();
    mockCsrfTokenEndpoint();

    logger.debug("Mock returns 403 for POST request when session timeout");
    WireMock.stubFor(
            WireMock.post(WireMock.urlEqualTo("/random-403-endpoint"))
                    .willReturn(WireMock.aResponse().withStatus(HttpStatus.FORBIDDEN.value()))
    );

    String response = null;
    try {
        response = authenticatedRestTemplate.postForObject("random-403-endpoint", new HashMap<String, String>(), String.class);
    } catch (RestClientException e) {
        logger.debug("Expecting this to fail because the response for /random-403-endpoint has been stubbed to be always returning a 403");
        Assert.assertEquals("Tried to re-authenticate but the response remains to be unauthenticated", e.getMessage());
    }

    Assert.assertNull(response);

    WireMock.verify(2, WireMock.getRequestedFor(WireMock.urlMatching("/login")).withHeader("Accept", WireMock.matching("text/plain.*")));
    WireMock.verify(2, WireMock.postRequestedFor(WireMock.urlMatching("/login")).withHeader("Accept", WireMock.matching("text/plain.*")));
    WireMock.verify(2, WireMock.postRequestedFor(WireMock.urlMatching("/random-403-endpoint")).withHeader("Accept", WireMock.matching("text/plain.*")).withHeader("X-CSRF-TOKEN", WireMock.matching("madeup-csrf-value")));
}
 
開發者ID:box,項目名稱:mojito,代碼行數:26,代碼來源:AuthenticatedRestTemplateTest.java

示例3: testAuthRestTemplateFor401

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testAuthRestTemplateFor401() {
    initialAuthenticationMock();
    mockCsrfTokenEndpoint();

    logger.debug("Mock returns 401 for POST request when session timeout");
    WireMock.stubFor(
            WireMock.post(WireMock.urlEqualTo("/random-401-endpoint"))
                    .willReturn(WireMock.aResponse().withStatus(HttpStatus.UNAUTHORIZED.value()))
    );

    String response = null;
    try {
        response = authenticatedRestTemplate.postForObject("random-401-endpoint", new HashMap<String, String>(), String.class);
    } catch (RestClientException e) {
        logger.debug("Expecting this to fail because the response for /random-401-endpoint has been stubbed to be always returning a 401");
        Assert.assertEquals("Tried to re-authenticate but the response remains to be unauthenticated", e.getMessage());
    }

    Assert.assertNull(response);

    WireMock.verify(2, WireMock.getRequestedFor(WireMock.urlMatching("/login")).withHeader("Accept", WireMock.matching("text/plain.*")));
    WireMock.verify(2, WireMock.postRequestedFor(WireMock.urlMatching("/login")).withHeader("Accept", WireMock.matching("text/plain.*")));
    WireMock.verify(2, WireMock.postRequestedFor(WireMock.urlMatching("/random-401-endpoint")).withHeader("Accept", WireMock.matching("text/plain.*")).withHeader("X-CSRF-TOKEN", WireMock.matching("madeup-csrf-value")));
}
 
開發者ID:box,項目名稱:mojito,代碼行數:26,代碼來源:AuthenticatedRestTemplateTest.java

示例4: testStreamMultipleEvent

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testStreamMultipleEvent() throws Exception {
    final String[] events = getEvents();
    final String body = Arrays.stream(events).collect(Collectors.joining(RxHttpRequest.BATCH_SPLITTER));
    stubFor(get(urlEqualTo(EVENTS_RESOURCE)).willReturn(aResponse().withStatus(200).withBody(body)));

    final Observable<HttpResponseChunk> observable = rxHttpRequest.createRequest(mockRequestProducer);
    final TestSubscriber<HttpResponseChunk> testSubscriber = new TestSubscriber<>();
    observable.subscribe(testSubscriber);
    testSubscriber.assertNoErrors();
    WireMock.verify(1, getRequestedFor(urlEqualTo(EVENTS_RESOURCE)));

    final List<HttpResponseChunk> chunks = testSubscriber.getOnNextEvents();
    assertThat(chunks).hasSize(events.length);
    for (int i = 0; i < events.length; i++) {
        assertThat(chunks.get(i)).extracting("statusCode", "content").containsOnly(200, events[i]);
    }
}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:19,代碼來源:RxHttpRequestTest.java

示例5: testCursorAndAuthorization

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testCursorAndAuthorization() throws Exception {

    final String headerName = "X-Nakadi-Cursors";
    final String headerValue = "[{\"partition\": \"0\", \"offset\":\"BEGIN\"}]";
    final String authorization = "Bearer b09bb129-3820-4178-af1e-1158a5464b56";
    final String body = "TEST";

    when(mockRequestProducer.getHeaders()).thenReturn(Collections.singletonMap(headerName, headerValue));
    rxHttpRequest = new RxHttpRequest(TimeUnit.MINUTES.toMillis(10), () -> authorization);

    stubFor(get(urlEqualTo(EVENTS_RESOURCE)).withHeader("Authorization", equalTo(authorization)).withHeader(
            headerName, equalTo(headerValue)).willReturn(aResponse().withStatus(200).withBody(body)));

    final Observable<HttpResponseChunk> observable = rxHttpRequest.createRequest(mockRequestProducer);
    final TestSubscriber<HttpResponseChunk> testSubscriber = new TestSubscriber<>();
    observable.subscribe(testSubscriber);
    testSubscriber.assertNoErrors();

    final List<HttpResponseChunk> chunks = testSubscriber.getOnNextEvents();
    assertThat(chunks).hasSize(1);
    assertThat(chunks).extracting("statusCode", "content").containsOnly(Tuple.tuple(200, body));
    WireMock.verify(1, getRequestedFor(urlEqualTo(EVENTS_RESOURCE)));
}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:25,代碼來源:RxHttpRequestTest.java

示例6: saxParserShouldNotExposeLocalFileSystem

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test(expected = VerificationException.class)
public void saxParserShouldNotExposeLocalFileSystem() throws Exception {
    File tmpFile = temporaryFolder.newFile("contents.txt");
    Files.write(tmpFile.toPath(), "hello-world".getBytes(StandardCharsets.UTF_8));

    String payload = "<?xml version=\"1.0\" ?> \n" +
                     "<!DOCTYPE a [ \n" +
                     "<!ENTITY % asd SYSTEM \"http://127.0.0.1:" + wireMockServer.port() + "/payload.dtd\"> \n" +
                     "%asd; \n" +
                     "%c; \n" +
                     "]> \n" +
                     "<a>&rrr;</a>";

    String entityString = "<!ENTITY % file SYSTEM \"file://" + tmpFile.getAbsolutePath() + "\"> \n" +
                          "<!ENTITY % c \"<!ENTITY rrr SYSTEM 'http://127.0.0.1:" + wireMockServer.port() + "/?%file;'>\">";

    stubFor(get(urlPathEqualTo("/payload.dtd")).willReturn(aResponse().withBody(entityString)));
    stubFor(get(urlPathEqualTo("/?hello-world")).willReturn(aResponse()));

    StaxResponseHandler<String> responseHandler = new StaxResponseHandler<>(dummyUnmarshaller());

    HttpResponse response = mock(HttpResponse.class);
    when(response.getContent()).thenReturn(new ByteArrayInputStream(payload.getBytes(Charset.forName("UTF-8"))));

    try {
        responseHandler.handle(response, mock(ExecutionAttributes.class));
    } catch (Exception e) {
        //expected
    }

    WireMock.verify(getRequestedFor(urlPathEqualTo("/?hello-world"))); //We expect this to fail, this call should not be made
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:33,代碼來源:StaxResponseHandlerComponentTest.java

示例7: testUnPreparedAuthRestTemplateAndSessionTimeoutForGetForObject

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testUnPreparedAuthRestTemplateAndSessionTimeoutForGetForObject() {
    initialAuthenticationMock();
    mockCsrfTokenEndpoint();

    WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/session-timeout-endpoint"))
            .willReturn(WireMock.aResponse()
                    .withStatus(HttpStatus.FOUND.value())
                    .withHeader("Location", "/login")
                    .withBody("")));

    String response = null;
    try {
        response = authenticatedRestTemplate.getForObject("session-timeout-endpoint", String.class);
    } catch (RestClientException e) {
        logger.debug("Expecting this to fail because the response for /session-timeout-endpoint has been stubbed to be always returning a 302");
        Assert.assertEquals("Tried to re-authenticate but the response remains to be unauthenticated", e.getMessage());
    }

    Assert.assertNull("There should have been no response", response);

    // Expecting 2 requests for each because initially, the AuthenticatedRestTemplate has not been prepared,
    // there hasn't been any session set or csrf token, so it'll authenticate first.
    // Then it'll resume the original request (ie. session-timeout-endpoint) but the response session timeout, so it
    // retries the auth flow again, and lastly, tries the session-timeout-endpoint again.
    // So in summary, this is the following expected flow:
    // 1. GET /login - because it has not been prepped, it starts auth flow
    // 2. POST /login
    // 3. GET /session-timeout-endpoint - response 302/login
    // 4. GET /login
    // 5. POST /login
    // 6. GET /session-timeout-endpoint
    WireMock.verify(2, WireMock.getRequestedFor(WireMock.urlMatching("/login")).withHeader("Accept", WireMock.matching("text/plain.*")));
    WireMock.verify(2, WireMock.postRequestedFor(WireMock.urlMatching("/login")).withHeader("Accept", WireMock.matching("text/plain.*")));
    WireMock.verify(2, WireMock.getRequestedFor(WireMock.urlMatching("/session-timeout-endpoint")).withHeader("Accept", WireMock.matching("text/plain.*")).withHeader("X-CSRF-TOKEN", WireMock.matching("madeup-csrf-value")));
}
 
開發者ID:box,項目名稱:mojito,代碼行數:37,代碼來源:AuthenticatedRestTemplateTest.java

示例8: should_move_files_to_output_directory

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void should_move_files_to_output_directory() throws IOException {

    final File origin = temporaryFolder.newFolder("origin");

    byte[] content = "Contract File".getBytes();
    Files.copy(new ByteArrayInputStream(content), new File(origin, "pact.txt").toPath());

    String config = "provider: url\n" +
        "contractsFolder: " + origin.getAbsolutePath() + "\n" +
        "url: http://localhost:18081/pacts\n";

    final Map<String, String> params = new HashMap<>();
    params.put("publishContracts", "true");
    params.put("publishConfiguration", config);

    final AlgeronConsumerConfiguration pactConsumerConfiguration = AlgeronConsumerConfiguration.fromMap(params);
    bind(ApplicationScoped.class, AlgeronConsumerConfiguration.class, pactConsumerConfiguration);

    WireMock.stubFor(
        WireMock.post(WireMock.urlEqualTo("/pacts/pact.txt"))
            .withRequestBody(new ContainsPattern("Contract File"))
            .willReturn(WireMock.aResponse().withStatus(200)));

    fire(new AfterClass(UrlContractsPublisherObserverTest.class));

    WireMock.verify(WireMock.postRequestedFor(WireMock.urlEqualTo("/pacts/pact.txt"))
        .withRequestBody(new ContainsPattern("Contract File")));
}
 
開發者ID:arquillian,項目名稱:arquillian-algeron,代碼行數:30,代碼來源:UrlContractsPublisherObserverTest.java

示例9: testEmptyStreamOK

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testEmptyStreamOK() throws Exception {
    stubFor(get(urlEqualTo(EVENTS_RESOURCE)).willReturn(aResponse().withStatus(200).withBody("")));

    final Observable<HttpResponseChunk> observable = rxHttpRequest.createRequest(mockRequestProducer);
    final TestSubscriber<HttpResponseChunk> testSubscriber = new TestSubscriber<>();
    observable.subscribe(testSubscriber);
    testSubscriber.assertNoErrors();
    testSubscriber.assertNoValues();
    WireMock.verify(1, getRequestedFor(urlEqualTo(EVENTS_RESOURCE)));
}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:12,代碼來源:RxHttpRequestTest.java

示例10: testEmptyStreamForbidden

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testEmptyStreamForbidden() throws Exception {
    stubFor(get(urlEqualTo(EVENTS_RESOURCE)).willReturn(aResponse().withStatus(403).withBody("")));

    final Observable<HttpResponseChunk> observable = rxHttpRequest.createRequest(mockRequestProducer);
    final TestSubscriber<HttpResponseChunk> testSubscriber = new TestSubscriber<>();
    observable.subscribe(testSubscriber);
    testSubscriber.assertNoErrors();
    WireMock.verify(1, getRequestedFor(urlEqualTo(EVENTS_RESOURCE)));

    final List<HttpResponseChunk> chunks = testSubscriber.getOnNextEvents();
    assertThat(chunks).extracting("statusCode", "content").containsOnly(Tuple.tuple(403, ""));
}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:14,代碼來源:RxHttpRequestTest.java

示例11: testStream1Event

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testStream1Event() throws Exception {
    final String body = "TEST";
    stubFor(get(urlEqualTo(EVENTS_RESOURCE)).willReturn(aResponse().withStatus(200).withBody(body)));

    final Observable<HttpResponseChunk> observable = rxHttpRequest.createRequest(mockRequestProducer);
    final TestSubscriber<HttpResponseChunk> testSubscriber = new TestSubscriber<>();
    observable.subscribe(testSubscriber);
    testSubscriber.assertNoErrors();
    WireMock.verify(1, getRequestedFor(urlEqualTo(EVENTS_RESOURCE)));

    final List<HttpResponseChunk> chunks = testSubscriber.getOnNextEvents();
    assertThat(chunks).extracting("statusCode", "content").containsOnly(Tuple.tuple(200, body));
}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:15,代碼來源:RxHttpRequestTest.java

示例12: testGzippedResponse

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testGzippedResponse() throws Exception {
    final String[] events = getEvents();

    final String content = Arrays.stream(events).collect(Collectors.joining(RxHttpRequest.BATCH_SPLITTER));
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final GZIPOutputStream gzip = new GZIPOutputStream(baos);
    IOUtils.copy(new ByteArrayInputStream(content.getBytes()), gzip);
    gzip.close();

    final byte[] body = baos.toByteArray();
    stubFor(get(urlEqualTo(EVENTS_RESOURCE)).willReturn(
            aResponse().withStatus(200).withHeader("Content-Encoding", "gzip").withBody(body)));

    final Observable<HttpResponseChunk> observable = rxHttpRequest.createRequest(mockRequestProducer);
    final TestSubscriber<HttpResponseChunk> testSubscriber = new TestSubscriber<>();
    observable.subscribe(testSubscriber);
    testSubscriber.assertNoErrors();
    WireMock.verify(1, getRequestedFor(urlEqualTo(EVENTS_RESOURCE)));

    final List<HttpResponseChunk> chunks = testSubscriber.getOnNextEvents();
    assertThat(chunks).hasSize(events.length);
    assertThat(chunks).hasSize(events.length);
    for (int i = 0; i < events.length; i++) {
        assertThat(chunks.get(i)).extracting("statusCode", "content").containsOnly(200, events[i]);
    }
}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:28,代碼來源:RxHttpRequestTest.java

示例13: testSocketReadException

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
@Test
public void testSocketReadException() throws Exception {
    final int timeout = (int) TimeUnit.SECONDS.toMillis(2);
    rxHttpRequest = new RxHttpRequest(timeout, null);

    stubFor(get(urlEqualTo(EVENTS_RESOURCE)).willReturn(
            aResponse().withFixedDelay(timeout + 2000).withStatus(200).withBody("")));

    final Observable<HttpResponseChunk> observable = rxHttpRequest.createRequest(mockRequestProducer);
    final TestSubscriber<HttpResponseChunk> testSubscriber = new TestSubscriber<>();
    observable.subscribe(testSubscriber);
    testSubscriber.assertError(java.net.SocketTimeoutException.class);
    WireMock.verify(1, getRequestedFor(urlEqualTo(EVENTS_RESOURCE)));

}
 
開發者ID:zalando-nakadi,項目名稱:paradox-nakadi-consumer,代碼行數:16,代碼來源:RxHttpRequestTest.java

示例14: assertRequest

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 */
static void assertRequest(String endpoint, HttpMethod method) {
	UrlPattern urlPattern = urlEqualTo(endpoint);
	RequestMethod rqMethod = new RequestMethod(method.name());
	RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
	WireMock.verify(1, rq);
}
 
開發者ID:mjeanroy,項目名稱:junit-servers,代碼行數:13,代碼來源:WireMockTestUtils.java

示例15: assertRequestWithBody

import com.github.tomakehurst.wiremock.client.WireMock; //導入方法依賴的package包/類
/**
 * Verify that a given request has been triggered.
 *
 * @param endpoint Request endpoint.
 * @param method Request method.
 * @param body Request body.
 */
static void assertRequestWithBody(String endpoint, HttpMethod method, String body) {
	UrlPattern urlPattern = urlEqualTo(endpoint);
	RequestMethod rqMethod = new RequestMethod(method.name());
	RequestPatternBuilder rq = new RequestPatternBuilder(rqMethod, urlPattern);
	rq.withRequestBody(equalTo(body));
	WireMock.verify(1, rq);
}
 
開發者ID:mjeanroy,項目名稱:junit-servers,代碼行數:15,代碼來源:WireMockTestUtils.java


注:本文中的com.github.tomakehurst.wiremock.client.WireMock.verify方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。