Search in sources :

Example 1 with PactDslRootValue

use of au.com.dius.pact.consumer.dsl.PactDslRootValue in project pact-jvm by DiUS.

the class PactDslRootValueTest method rootValueTest.

@Test
public void rootValueTest() {
    PactDslRootValue rootValueBody = new PactDslRootValue();
    rootValueBody.setValue("Brent");
    rootValueBody.setMatcher(new RegexMatcher(".{5}"));
    PactDslWithProvider dsl = new PactDslWithProvider(new ConsumerPactBuilder("consumer"), "provider");
    Map<String, String> headers = new HashMap<String, String>() {

        {
            put("Content-Type", "text/plain");
        }
    };
    RequestResponsePact frag = dsl.given("I am testing root values").uponReceiving("A request for text/plain").path("/some/blah/path").headers(headers).willRespondWith().headers(headers).status(200).body(rootValueBody).toPact().asRequestResponsePact().component1();
    Assert.assertEquals(1, frag.getInteractions().size());
    assertThat(frag.getInteractions().get(0).asSynchronousRequestResponse().getResponse().getBody().valueAsString(), is("Brent"));
    Map<String, MatchingRuleGroup> matchingGroups = frag.getInteractions().get(0).asSynchronousRequestResponse().getResponse().getMatchingRules().rulesForCategory("body").getMatchingRules();
    List<MatchingRule> rules = matchingGroups.get("$").getRules();
    Assert.assertEquals(1, rules.size());
    Assert.assertEquals(".{5}", rules.get(0).toMap(PactSpecVersion.V3).get("regex"));
}
Also used : MatchingRuleGroup(au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup) PactDslRootValue(au.com.dius.pact.consumer.dsl.PactDslRootValue) HashMap(java.util.HashMap) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact) RegexMatcher(au.com.dius.pact.core.model.matchingrules.RegexMatcher) PactDslWithProvider(au.com.dius.pact.consumer.dsl.PactDslWithProvider) MatchingRule(au.com.dius.pact.core.model.matchingrules.MatchingRule) Test(org.junit.Test)

Aggregations

PactDslRootValue (au.com.dius.pact.consumer.dsl.PactDslRootValue)1 PactDslWithProvider (au.com.dius.pact.consumer.dsl.PactDslWithProvider)1 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)1 MatchingRule (au.com.dius.pact.core.model.matchingrules.MatchingRule)1 MatchingRuleGroup (au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup)1 RegexMatcher (au.com.dius.pact.core.model.matchingrules.RegexMatcher)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1