Java Examples for com.github.tomakehurst.wiremock.http.Fault
The following java examples will help you to understand the usage of com.github.tomakehurst.wiremock.http.Fault. These source code samples are taken from different open source projects.
Example 1
| Project: gitlab-jira-integration-master File: JiraServiceTestIT.java View source code |
@Test
public void isExistingIssueWithAServerError() throws Exception {
String issue = "TEST-1";
wireMockRule.stubFor(get(urlEqualTo("/rest/api/2/issue/" + issue)).withHeader("Authorization", matching("Basic .*")).willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
assertThat(jiraService.isExistingIssue(issue)).isFalse();
wireMockRule.verify(getRequestedFor(urlEqualTo("/rest/api/2/issue/" + issue)).withHeader("Authorization", matching("Basic .*")));
}Example 2
| Project: flume-master File: TestHttpSinkIT.java View source code |
@Test
public void ensureEventsResentOnNetworkFailure() throws Exception {
String errorScenario = "Error Scenario";
service.stubFor(post(urlEqualTo("/endpoint")).inScenario(errorScenario).whenScenarioStateIs(STARTED).withRequestBody(equalToJson(event("NETWORK_ERROR"))).willReturn(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE)).willSetStateTo("Error Sent"));
service.stubFor(post(urlEqualTo("/endpoint")).inScenario(errorScenario).whenScenarioStateIs("Error Sent").withRequestBody(equalToJson(event("NETWORK_ERROR"))).willReturn(aResponse().withStatus(200)));
addEventToChannel(event("NETWORK_ERROR"), Status.BACKOFF);
addEventToChannel(event("NETWORK_ERROR"), Status.READY);
service.verify(2, postRequestedFor(urlEqualTo("/endpoint")).withRequestBody(equalToJson(event("NETWORK_ERROR"))));
}Example 3
| Project: gerrit-trigger-plugin-master File: GerritMissedEventsPlaybackManagerTest.java View source code |
/**
* Given a Gerrit Server with Events-log plugin installed
* When we request the events from a time range
* And we receive a malformed response
* Then we log an error
* And we return an empty set of events.
*/
@Test
public void testHandleMalformedConnection() {
GerritMissedEventsPlaybackManager missingEventsPlaybackManager = setupManager();
stubFor(get(urlMatching(EVENTS_LOG_CHANGE_EVENTS_URL_REGEXP)).willReturn(aResponse().withFault(Fault.MALFORMED_RESPONSE_CHUNK)));
List<GerritTriggeredEvent> events = new ArrayList<GerritTriggeredEvent>();
try {
events = missingEventsPlaybackManager.getEventsFromDateRange(missingEventsPlaybackManager.getDateFromTimestamp());
} catch (IOException e) {
fail(e.getMessage());
}
Assert.assertTrue("Should have 0 event", events.size() == 0);
}Example 4
| Project: hibernate-search-master File: DefaultElasticsearchClientFactoryTest.java View source code |
@Test
@TestForIssue(jiraKey = "HSEARCH-2469")
public void multipleHosts_failover_fault() throws Exception {
SearchConfigurationForTest configuration = new SearchConfigurationForTest().addProperty(CLIENT_PROPERTY_PREFIX + ElasticsearchEnvironment.SERVER_URI, httpUrlFor(wireMockRule1) + " " + httpUrlFor(wireMockRule2)).addProperty(CLIENT_PROPERTY_PREFIX + ElasticsearchEnvironment.SERVER_READ_TIMEOUT, /* 1s */
"1000");
String payload = "{ \"foo\": \"bar\" }";
wireMockRule1.stubFor(post(urlPathLike("/myIndex/myType")).withRequestBody(equalToJson(payload)).willReturn(elasticsearchResponse().withStatus(200)));
wireMockRule2.stubFor(post(urlPathLike("/myIndex/myType")).withRequestBody(equalToJson(payload)).willReturn(elasticsearchResponse().withStatus(200).withFault(Fault.MALFORMED_RESPONSE_CHUNK)));
try (ElasticsearchClient client = clientFactory.create(CLIENT_SCOPE_NAME, configuration.getProperties())) {
Response result = doPost(client, "/myIndex/myType", payload);
assertThat(result.getStatusLine().getStatusCode()).as("status code").isEqualTo(200);
result = doPost(client, "/myIndex/myType", payload);
assertThat(result.getStatusLine().getStatusCode()).as("status code").isEqualTo(200);
wireMockRule1.verify(2, postRequestedFor(urlPathLike("/myIndex/myType")));
wireMockRule2.verify(1, postRequestedFor(urlPathLike("/myIndex/myType")));
wireMockRule1.resetRequests();
wireMockRule2.resetRequests();
result = doPost(client, "/myIndex/myType", payload);
assertThat(result.getStatusLine().getStatusCode()).as("status code").isEqualTo(200);
result = doPost(client, "/myIndex/myType", payload);
assertThat(result.getStatusLine().getStatusCode()).as("status code").isEqualTo(200);
// Must not use the failing node anymore
wireMockRule1.verify(2, postRequestedFor(urlPathLike("/myIndex/myType")));
wireMockRule2.verify(0, postRequestedFor(urlPathLike("/myIndex/myType")));
}
}Example 5
| Project: ride-master File: RideRequestButtonControllerTest.java View source code |
@Test
public void testLoadInformation_whenPriceFails() throws Exception {
stubTimeApi(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE));
stubPriceApiSuccessful();
controller.loadRideInformation(rideParameters);
countDownLatch.await(3, TimeUnit.SECONDS);
verify(callback, never()).onRideInformationLoaded();
ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(callback).onError(errorCaptor.capture());
assertThat(errorCaptor.getValue()).isNotNull();
verify(view, never()).showEstimate(any(TimeEstimate.class));
verify(view, never()).showEstimate(any(TimeEstimate.class), any(PriceEstimate.class));
verify(view).showDefaultView();
}Example 6
| Project: rides-android-sdk-master File: RideRequestButtonControllerTest.java View source code |
@Test
public void testLoadInformation_whenPriceFails() throws Exception {
stubTimeApi(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE));
stubPriceApiSuccessful();
controller.loadRideInformation(rideParameters);
countDownLatch.await(3, TimeUnit.SECONDS);
verify(callback, never()).onRideInformationLoaded();
ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(callback).onError(errorCaptor.capture());
assertThat(errorCaptor.getValue()).isNotNull();
verify(view, never()).showEstimate(any(TimeEstimate.class));
verify(view, never()).showEstimate(any(TimeEstimate.class), any(PriceEstimate.class));
verify(view).showDefaultView();
}Example 7
| Project: dokuJClient-master File: Test_BadQueries.java View source code |
@org.junit.Test(expected = DokuUnknownException.class)
public void corruptedReply() throws Exception {
stubFor(post(urlEqualTo("/lib/exe/xmlrpc.php")).willReturn(aResponse().withStatus(200).withFault(Fault.MALFORMED_RESPONSE_CHUNK)));
makeADummyCall(buildClient());
}