本文整理汇总了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")));
}
示例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")));
}
示例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")));
}
示例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]);
}
}
示例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)));
}
示例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
}
示例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")));
}
示例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")));
}
示例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)));
}
示例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, ""));
}
示例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));
}
示例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]);
}
}
示例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)));
}
示例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);
}
示例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);
}