use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.
the class PactProviderTest method runTestWithPactError.
@Test
@PactVerification(value = "test_provider")
public void runTestWithPactError() throws IOException {
mockTestProvider.validateResultWith((result, t) -> {
assertThat(t, is(instanceOf(AssertionError.class)));
assertThat(t.getMessage(), startsWith("The following requests were not received:\n" + "\tmethod: GET\n" + "\tpath: /"));
assertThat(result, is(instanceOf(PactVerificationResult.ExpectedButNotReceived.class)));
PactVerificationResult.ExpectedButNotReceived error = (PactVerificationResult.ExpectedButNotReceived) result;
assertThat(error.getExpectedRequests(), hasSize(1));
IRequest request = error.getExpectedRequests().get(0);
assertThat(request.getPath(), is("/"));
});
Assert.assertEquals(new ConsumerClient(mockTestProvider.getUrl()).options("/second"), 200);
}
use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.
the class PactProviderTest method runTestWithUserCodeFailure.
@Test
@PactVerification("test_provider")
public void runTestWithUserCodeFailure() throws IOException {
mockTestProvider.validateResultWith((result, t) -> {
assertThat(t, is(instanceOf(AssertionError.class)));
assertThat(t.getMessage(), is("Pact Test function failed with an exception: expected:" + "<{responsetest=true, name=harry}> but was:<{responsetest=true, name=fred}>"));
assertThat(result, is(instanceOf(PactVerificationResult.Error.class)));
PactVerificationResult.Error error = (PactVerificationResult.Error) result;
assertThat(error.getMockServerState(), is(instanceOf(PactVerificationResult.Ok.class)));
assertThat(error.getError(), is(instanceOf(AssertionError.class)));
});
Assert.assertEquals(new ConsumerClient(mockTestProvider.getUrl()).options("/second"), 200);
Map expectedResponse = new HashMap();
expectedResponse.put("responsetest", true);
expectedResponse.put("name", "fred");
assertEquals(new ConsumerClient(mockTestProvider.getUrl()).getAsMap("/", ""), expectedResponse);
}
use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.
the class UnexpectedRequestConsumerPassesTest method runTest.
@Override
protected void runTest(MockServer mockServer, PactTestExecutionContext context) throws IOException {
Map<String, Object> expectedResponse = new HashMap<String, Object>();
expectedResponse.put("responsetest", true);
expectedResponse.put("name", "fred");
ConsumerClient consumerClient = new ConsumerClient(mockServer.getUrl());
assertEquals(consumerClient.getAsMap("/", ""), expectedResponse);
consumerClient.options("/options");
}
use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.
the class ExampleJavaConsumerPactTest method runTest.
@Override
protected void runTest(MockServer mockServer, PactTestExecutionContext context) throws IOException {
Assert.assertEquals(new ConsumerClient(mockServer.getUrl()).options("/second"), 200);
Map expectedResponse = new HashMap();
expectedResponse.put("responsetest", true);
expectedResponse.put("name", "harry");
assertEquals(new ConsumerClient(mockServer.getUrl()).getAsMap("/", ""), expectedResponse);
assertEquals(new ConsumerClient(mockServer.getUrl()).options("/second"), 200);
}
use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.
the class PactMultiProviderTest method doTest.
private void doTest(String path, String json) throws IOException {
ConsumerClient consumerClient = new ConsumerClient(mockTestProvider.getUrl());
consumerClient.options("/second");
try {
consumerClient.getAsMap(path, "");
} catch (IOException e) {
}
try {
new ConsumerClient(mockTestProvider2.getUrl()).putAsMap("/", json);
} catch (IOException e) {
}
}
Aggregations