use of au.com.dius.pact.core.model.BasePact in project pact-jvm by DiUS.
the class PactQueryParameterTest method testMatchQueryWithComplexQueryParameter.
@Test
public void testMatchQueryWithComplexQueryParameter() throws Throwable {
// Given a pact expecting GET /hello?q=query%20containing%20%26%20and%20%3F%20characters
// created using the .matchQuery(...) method
String path = "/hello";
String parameterName = "q";
String decodedValue = "query containing & and ? characters";
String encodedValue = "query%20containing%20%26%20and%20%3F%20characters";
String encodedFullPath = path + "?" + parameterName + "=" + encodedValue;
BasePact pact = ConsumerPactBuilder.consumer("Some Consumer").hasPactWith("Some Provider").uponReceiving(encodedFullPath).path(path).matchQuery(parameterName, ".+", decodedValue).method("GET").willRespondWith().status(200).toPact();
// When sending the request, we expect no errors
verifyRequestMatches(pact, encodedFullPath);
}
use of au.com.dius.pact.core.model.BasePact in project pact-jvm by DiUS.
the class PactQueryParameterTest method testMatchQueryWithSimpleQueryParameter.
@Test
public void testMatchQueryWithSimpleQueryParameter() throws Throwable {
// Given a pact expecting GET /hello?q=simple created using the .matchQuery(...) method
String path = "/hello";
String parameterName = "q";
String decodedValue = "simple";
String encodedValue = "simple";
String encodedFullPath = path + "?" + parameterName + "=" + encodedValue;
BasePact pact = ConsumerPactBuilder.consumer("Some Consumer").hasPactWith("Some Provider").uponReceiving(encodedFullPath).path(path).matchQuery(parameterName, ".+", decodedValue).method("GET").willRespondWith().status(200).toPact();
// When sending the request, we expect no errors
verifyRequestMatches(pact, encodedFullPath);
}
use of au.com.dius.pact.core.model.BasePact in project pact-jvm by DiUS.
the class PactQueryParameterTest method testEncodedQueryWithComplexQueryParameter.
@Test
public void testEncodedQueryWithComplexQueryParameter() throws Throwable {
// Given a pact expecting GET /hello?q=query%20containing%20%26%20and%20%3F%20characters,
// created using the .query(...) method
String path = "/hello";
String parameterName = "q";
String encodedValue = "query%20containing%20%26%20and%20%3F%20characters";
String encodedQuery = parameterName + "=" + encodedValue;
String encodedFullPath = path + "?" + encodedQuery;
BasePact pact = ConsumerPactBuilder.consumer("Some Consumer").hasPactWith("Some Provider").uponReceiving(encodedFullPath).path(path).encodedQuery(encodedQuery).method("GET").willRespondWith().status(200).toPact();
// When sending the request, we expect no errors
verifyRequestMatches(pact, encodedFullPath);
}
use of au.com.dius.pact.core.model.BasePact in project pact-jvm by DiUS.
the class PactQueryParameterTest method testEncodedQueryWithSimpleQueryParameter.
@Test
public void testEncodedQueryWithSimpleQueryParameter() throws Throwable {
// Given a pact expecting GET /hello?q=simple, created using the .query(...) method
String path = "/hello";
String parameterName = "q";
String encodedValue = "simple";
String encodedQuery = parameterName + "=" + encodedValue;
String encodedFullPath = path + "?" + encodedQuery;
BasePact pact = ConsumerPactBuilder.consumer("Some Consumer").hasPactWith("Some Provider").uponReceiving(encodedFullPath).path(path).encodedQuery(encodedQuery).method("GET").willRespondWith().status(200).toPact();
// When sending the request, we expect no errors
verifyRequestMatches(pact, encodedFullPath);
}
use of au.com.dius.pact.core.model.BasePact in project pact-jvm by DiUS.
the class BaseProviderRule method evaluatePactVerifications.
private void evaluatePactVerifications(PactVerifications pactVerifications, Statement base) throws Throwable {
List<PactVerification> possiblePactVerifications = findPactVerifications(pactVerifications, this.provider);
if (possiblePactVerifications.isEmpty()) {
base.evaluate();
return;
}
final BasePact[] pact = { null };
possiblePactVerifications.forEach(pactVerification -> {
Optional<Method> possiblePactMethod = findPactMethod(pactVerification);
if (possiblePactMethod.isEmpty()) {
throw new UnsupportedOperationException("Could not find method with @Pact for the provider " + provider);
}
Method method = possiblePactMethod.get();
Pact pactAnnotation = method.getAnnotation(Pact.class);
PactDslWithProvider dslBuilder = ConsumerPactBuilder.consumer(ep.parseExpression(pactAnnotation.consumer(), DataType.RAW).toString()).pactSpecVersion(config.getPactVersion()).hasPactWith(provider);
updateAnyDefaultValues(dslBuilder);
try {
BasePact pactFromMethod = (BasePact) method.invoke(target, dslBuilder);
if (pact[0] == null) {
pact[0] = pactFromMethod;
} else {
pact[0].mergeInteractions(pactFromMethod.getInteractions());
}
} catch (Exception e) {
throw new RuntimeException("Failed to invoke pact method", e);
}
});
PactFolder pactFolder = target.getClass().getAnnotation(PactFolder.class);
PactDirectory pactDirectory = target.getClass().getAnnotation(PactDirectory.class);
PactVerificationResult result = runPactTest(base, pact[0], pactFolder, pactDirectory);
JUnitTestSupport.validateMockServerResult(result);
}
Aggregations