Search in sources :

Example 21 with DslPart

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

the class PactDslJsonBodyTest method largeBodyTest.

@Test
public void largeBodyTest() {
    PactDslJsonBody metadata = new PactDslJsonBody().stringType("origin", "product-data").datetimeExpression("dateCreated", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    PactDslJsonBody title = new PactDslJsonBody().stringType("mainTitle", "Lorem ipsum dolor sit amet, consectetur adipiscing elit").stringType("webTitle", "sample_data").minArrayLike("attributes", 1).stringType("key", "sample_data").stringType("value", "sample_data").closeObject().closeArray().asBody();
    PactDslJsonBody description = new PactDslJsonBody().stringType("longDescription", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tellus pellentesque eu tincidunt tortor aliquam nulla facilisi cras. Nunc sed id semper risus in. Sit amet consectetur adipiscing elit pellentesque. Gravida neque convallis a cras. Auctor augue mauris augue neque gravida. Lectus quam id leo in vitae turpis massa sed elementum. Quisque sagittis purus sit amet volutpat consequat. Interdum velit euismod in pellentesque massa. Eu scelerisque felis imperdiet proin fermentum leo. Vel orci porta non pulvinar neque laoreet suspendisse. Netus et malesuada fames ac turpis egestas maecenas pharetra convallis. Sagittis aliquam malesuada bibendum arcu vitae. Risus in hendrerit gravida rutrum. Varius duis at consectetur lorem donec massa sapien. Platea dictumst quisque sagittis purus sit amet volutpat. Dui sapien eget mi proin sed libero enim. Tincidunt praesent semper feugiat nibh sed pulvinar. Sollicitudin tempor id eu nisl nunc mi. Hac habitasse platea dictumst vestibulum rhoncus.").stringType("shortDescription", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tellus pellentesque eu tincidunt tortor aliquam nulla facilisi cras. Nunc sed id semper risus in. Sit amet consectetur adipiscing elit pellentesque. Gravida neque convallis a cras. Auctor augue mauris augue neque gravida. Lectus quam id leo in vitae turpis massa sed elementum. Quisque sagittis purus sit amet volutpat consequat. Interdum velit euismod in pellentesque massa. Eu scelerisque felis imperdiet proin fermentum leo. Vel orci porta non pulvinar neque laoreet suspendisse. Netus et malesuada fames ac turpis egestas maecenas pharetra convallis. Sagittis aliquam malesuada bibendum arcu vitae. Risus in hendrerit gravida rutrum. Varius duis at consectetur lorem donec massa sapien. Platea dictumst quisque sagittis purus sit amet volutpat. Dui sapien eget mi proin sed libero enim.").minArrayLike("attributes", 1).stringType("key", "sample_data").stringType("value", "sample_data").closeObject().closeArray().asBody();
    PactDslJsonBody productSpecification = new PactDslJsonBody().integerType("multiPackQuantity", 1).booleanType("copyrightInd", false).stringType("copyrightDets", "sample_data").booleanType("batteryRequired", true).booleanType("batteryIncluded", false).booleanType("beabApproved", false).stringType("beabCertNo", "sample_data").booleanType("plugRequired", false).booleanType("plugIncluded", false).booleanType("bulbRequired", false).booleanType("bulbIncluded", false).decimalType("voltage", 10.10).decimalType("wattage", 10.10);
    PactDslJsonBody dimensions = new PactDslJsonBody().decimalType("length", 10.10).decimalType("width", 10.10).decimalType("height", 10.10).decimalType("pileHeight", 10.10).stringType("uom", "METRE");
    PactDslJsonBody brand = new PactDslJsonBody().stringType("name", "sample_data");
    PactDslJsonBody eventHistories = new PactDslJsonBody().stringType("eventService", "fam-service").datetimeExpression("eventCreationDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").stringType("eventType", "UPDATE").datetimeExpression("eventProcessedDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    PactDslJsonBody colours = new PactDslJsonBody().stringType("name", "sample_data").booleanType("primary", false).stringType("colourCode", "sample_data").stringType("hexCode", "sample_data").stringType("rgbCode", "sample_data");
    PactDslJsonBody images = new PactDslJsonBody().stringType("name", "sample_data").stringType("linkType", "URI").stringType("uri", "153-7908284-BOK434X.jpg").stringType("description", "sample_data").stringType("type", "sample_data").stringType("status", "sample_data").minArrayLike("attributes", 1).stringType("key", "channelFormat").stringType("value", "X").closeObject().closeArray().asBody();
    PactDslJsonBody caseDimensions = new PactDslJsonBody().decimalType("length", 10.10).decimalType("width", 10.10).decimalType("height", 10.10).decimalType("weight", 10.10).stringType("lwhUom", "MILLIMETRE").stringType("weightUom", "GRAM");
    DslPart body = new PactDslJsonBody().object("metadata", metadata).integerType("version", 1).object("wrapper").stringType("w", "17f78aqr").minArrayLike("identifiers", 1).stringType("alias", "sku").minArrayLike("value", 1, PactDslJsonRootValue.stringType("7908284"), 1).closeArray().asBody().minArrayLike("aliases", 1, PactDslJsonRootValue.stringType("17f78aqr"), 1).closeObject().asBody().stringType("itemType", "ITEM").object("parentWrapper").stringType("p", "xf7kabqd").minArrayLike("identifiers", 1).stringType("alias", "sku").minArrayLike("value", 1, PactDslJsonRootValue.stringType("135325620.P"), 1).closeArray().asBody().minArrayLike("aliases", 1, PactDslJsonRootValue.stringType("xf7kabqd"), 1).closeObject().asBody().object("master").stringType("source", "PDS").object("title", title).object("description", description).object("brand", brand).object("productSpecification", productSpecification).minArrayLike("attributes", 1).stringType("scope", "DESCRIPTIVE").stringType("key", "sample_data").minArrayLike("values", 1, PactDslJsonRootValue.stringType("sample_data"), 1).closeObject().closeArray().asBody().minArrayLike("colours", 1, colours).object("weightsAndMeasures").object("dimensions", dimensions).object("weight").decimalType("weight", 10.10).decimalType("netWeight", 10.10).decimalType("catchWeight", 10.10).decimalType("pileWeight", 10.10).stringType("uom", "KILOGRAM").closeObject().asBody().object("volume").decimalType("liquidVolume", 10.10).stringType("uom", "LITRE").closeObject().asBody().object("scannedData").datetimeExpression("fileTimestamp", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").decimalType("averageWeight", 10.10).stringType("averageWeightUom", "GRAM").object("shipmentCase", caseDimensions).object("vendorCase", caseDimensions).closeObject().asBody().closeObject().asBody().minArrayLike("packages", 1).integerType("packageType", 1).object("weightsAndMeasures").object("dimensions", dimensions).object("weight").decimalType("weight", 10.10).decimalType("netWeight", 10.10).decimalType("catchWeight", 10.10).decimalType("pileWeight", 10.10).stringType("uom", "KILOGRAM").closeObject().asBody().object("volume").decimalType("liquidVolume", 10.10).stringType("uom", "LITRE").closeObject().asBody().object("scannedData").datetimeExpression("fileTimestamp", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").decimalType("averageWeight", 10.10).stringType("averageWeightUom", "GRAM").object("shipmentCase", caseDimensions).object("vendorCase", caseDimensions).closeObject().asBody().closeObject().asBody().closeObject().closeArray().asBody().object("media").minArrayLike("images", 1, images).closeObject().asBody().object("safety").booleanType("ageRestrictedFlag", false).booleanType("safetyIndicator", false).booleanType("safetyIndicatorFlag", false).booleanType("safetyIndicatorOverrideFlag", false).closeObject().asBody().object("waste").stringType("wasteType", "sample_data").decimalType("percentage", 10.10).decimalType("defaultPercentage", 10.10).datetimeExpression("effectiveFromDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").datetimeExpression("effectiveToDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").minArrayLike("attributes", 1).stringType("key", "associatedProductNumber").stringType("value", "sample_data").closeObject().closeArray().asBody().closeObject().asBody().object("optionalTypes").object("jewellery").decimalType("totalWeight", 10.10).decimalType("metalWeight", 10.10).decimalType("stoneWeight", 10.10).decimalType("chainLength", 10.10).stringType("ringSize", "sample_data").stringType("ringSizeFrom", "sample_data").stringType("ringSizeTo", "sample_data").closeObject().asBody().object("clothing").stringType("size", "sample_data").closeObject().asBody().eachLike("batteries", 0).closeArray().asBody().closeObject().asBody().object("productDataAudit").datetimeExpression("createdDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").datetimeExpression("lastModifiedDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").stringType("lastModifiedBy", "argos-pim-backfeed-adapter-service").datetimeExpression("deletedDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").closeObject().asBody().closeObject().asBody().object("division").stringType("masterSource", "DIV").object("title", title).object("description", description).object("brand", brand).object("productSpecification", productSpecification).minArrayLike("attributes", 1).stringType("scope", "DESCRIPTIVE").stringType("key", "sample_data").minArrayLike("values", 1, PactDslJsonRootValue.stringType("sample_data"), 1).closeObject().closeArray().asBody().minArrayLike("colours", 1, colours).object("weightsAndMeasures").object("dimensions", dimensions).object("weight").decimalType("weight", 10.10).decimalType("netWeight", 10.10).decimalType("catchWeight", 10.10).decimalType("pileWeight", 10.10).stringType("uom", "KILOGRAM").closeObject().asBody().object("volume").decimalType("liquidVolume", 10.10).stringType("uom", "LITRE").closeObject().asBody().object("scannedData").datetimeExpression("fileTimestamp", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").decimalType("averageWeight", 10.10).stringType("averageWeightUom", "GRAM").object("shipmentCase", caseDimensions).object("vendorCase", caseDimensions).closeObject().asBody().closeObject().asBody().minArrayLike("packages", 1).integerType("packageType", 1).object("weightsAndMeasures").object("dimensions", dimensions).object("weight").decimalType("weight", 10.10).decimalType("netWeight", 10.10).decimalType("catchWeight", 10.10).decimalType("pileWeight", 10.10).stringType("uom", "KILOGRAM").closeObject().asBody().object("volume").decimalType("liquidVolume", 10.10).stringType("uom", "LITRE").closeObject().asBody().object("scannedData").datetimeExpression("fileTimestamp", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").decimalType("averageWeight", 10.10).stringType("averageWeightUom", "GRAM").object("shipmentCase", caseDimensions).object("vendorCase", caseDimensions).closeObject().asBody().closeObject().asBody().closeObject().closeArray().asBody().object("media").minArrayLike("images", 1, images).closeObject().asBody().object("safety").booleanType("ageRestrictedFlag", false).booleanType("safetyIndicator", false).booleanType("safetyIndicatorFlag", false).booleanType("safetyIndicatorOverrideFlag", false).closeObject().asBody().object("waste").stringType("wasteType", "sample_data").decimalType("percentage", 10.10).decimalType("defaultPercentage", 10.10).datetimeExpression("effectiveFromDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").datetimeExpression("effectiveToDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").minArrayLike("attributes", 1).stringType("key", "weeeAssociatedProductNumber").stringType("value", "sample_data").closeObject().closeArray().asBody().closeObject().asBody().object("optionalTypes").object("jewellery").decimalType("totalWeight", 10.10).decimalType("metalWeight", 10.10).decimalType("stoneWeight", 10.10).decimalType("chainLength", 10.10).stringType("ringSize", "sample_data").stringType("ringSizeFrom", "sample_data").stringType("ringSizeTo", "sample_data").closeObject().asBody().object("clothing").stringType("size", "sample_data").closeObject().asBody().eachLike("batteries", 0).closeArray().asBody().closeObject().asBody().object("productDataAudit").datetimeExpression("createdDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").datetimeExpression("lastModifiedDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").stringType("lastModifiedBy", "bam").datetimeExpression("deletedDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").closeObject().asBody().closeObject().asBody().object("exxer").stringType("masterSource", "EXXER").closeObject().asBody().object("itemAudit").datetimeExpression("createdDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").datetimeExpression("lastModifiedDate", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").stringType("lastModifiedBy", "bam").minArrayLike("eventHistories", 1, eventHistories).closeObject().asBody();
    JsonValue jsonValue = body.getBody();
    assertThat(jsonValue.asObject().getEntries().keySet(), is(equalTo(new HashSet<>(Arrays.asList("division", "metadata", "itemType", "itemAudit", "exxer", "wrapper", "parentWrapper", "version", "master")))));
    assertThat(jsonValue.asObject().get("itemAudit").asObject().getEntries().keySet(), is(equalTo(new HashSet<>(Arrays.asList("createdDate", "eventHistories", "lastModifiedBy", "lastModifiedDate")))));
    assertThat(jsonValue.asObject().get("itemAudit").get("eventHistories").asArray().getValues().get(0).asObject().getEntries().keySet(), is(equalTo(new HashSet<>(Arrays.asList("eventProcessedDate", "eventType", "eventService", "eventCreationDate")))));
}
Also used : JsonValue(au.com.dius.pact.core.support.json.JsonValue) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) DslPart(au.com.dius.pact.consumer.dsl.DslPart) Test(org.junit.Test)

Example 22 with DslPart

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

the class LambdaDslTest method testUnorderedArrayWithObjects.

@Test
public void testUnorderedArrayWithObjects() {
    /*
            [
                {
                    "foo": "Foo"
                },
                {
                    "bar": "Bar"
                }
            ]
         */
    // Old DSL
    final DslPart pactDslJson = PactDslJsonArray.newUnorderedArray().object().stringValue("foo", "Foo").closeObject().object().stringValue("bar", "Bar").closeObject().close();
    // Lambda DSL
    final DslPart lambdaPactDsl = LambdaDsl.newJsonArrayUnordered(array -> array.object(o -> o.stringValue("foo", "Foo")).object(o -> o.stringValue("bar", "Bar"))).build().close();
    assertThat(lambdaPactDsl.getBody().toString(), is(pactDslJson.getBody().toString()));
    assertThat(lambdaPactDsl.getMatchers(), is(pactDslJson.getMatchers()));
}
Also used : Test(org.junit.jupiter.api.Test) CoreMatchers.is(org.hamcrest.CoreMatchers.is) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) DslPart(au.com.dius.pact.consumer.dsl.DslPart) LambdaDsl(au.com.dius.pact.consumer.dsl.LambdaDsl) PactDslJsonArray(au.com.dius.pact.consumer.dsl.PactDslJsonArray) IOException(java.io.IOException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DslPart(au.com.dius.pact.consumer.dsl.DslPart) Test(org.junit.jupiter.api.Test)

Example 23 with DslPart

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

the class LambdaDslTest method testArrayWithObjects.

@Test
public void testArrayWithObjects() throws IOException {
    /*
            [
                {
                    "foo": "Foo"
                },
                {
                    "bar": "Bar"
                }
            ]
         */
    // Old DSL
    final String pactDslJson = new PactDslJsonArray().object().stringValue("foo", "Foo").closeObject().object().stringValue("bar", "Bar").closeObject().getBody().toString();
    // Lambda DSL
    final DslPart actualPactDsl = LambdaDsl.newJsonArray((array) -> {
        array.object((o) -> {
            o.stringValue("foo", "Foo");
        }).object((o) -> {
            o.stringValue("bar", "Bar");
        });
    }).build();
    String actualJson = actualPactDsl.getBody().toString();
    assertThat(actualJson, is(pactDslJson));
}
Also used : Test(org.junit.jupiter.api.Test) CoreMatchers.is(org.hamcrest.CoreMatchers.is) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) DslPart(au.com.dius.pact.consumer.dsl.DslPart) LambdaDsl(au.com.dius.pact.consumer.dsl.LambdaDsl) PactDslJsonArray(au.com.dius.pact.consumer.dsl.PactDslJsonArray) IOException(java.io.IOException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) PactDslJsonArray(au.com.dius.pact.consumer.dsl.PactDslJsonArray) DslPart(au.com.dius.pact.consumer.dsl.DslPart) Test(org.junit.jupiter.api.Test)

Example 24 with DslPart

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

the class PactDslJsonBodyTest method matcherPathTest.

@Test
public void matcherPathTest() {
    DslPart body = new PactDslJsonBody().id("1").stringType("@field").hexValue("200", "abc").integerType(K_DEPRECIATION_BIPS);
    Set<String> expectedMatchers = new HashSet<String>(Arrays.asList(".200", ".1", ".@field", ".10k-depreciation-bips"));
    assertThat(body.getMatchers().getMatchingRules().keySet(), is(equalTo(expectedMatchers)));
    assertThat(body.getBody().asObject().keys(), is(equalTo(new HashSet(Arrays.asList("200", K_DEPRECIATION_BIPS, "1", "@field")))));
}
Also used : PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) DslPart(au.com.dius.pact.consumer.dsl.DslPart) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with DslPart

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

the class PactDslJsonBodyTest method allowSettingFieldsToNull.

@Test
public void allowSettingFieldsToNull() {
    DslPart body = new PactDslJsonBody().id().object("2").id().stringValue("test", (String) null).nullValue("nullValue").closeObject().array(NUMBERS).id().nullValue().stringValue(null).closeArray();
    JsonValue.Object jsonObject = body.getBody().asObject();
    assertThat(jsonObject.keys(), is(equalTo(new HashSet(Arrays.asList("2", NUMBERS, "id")))));
    assertThat(jsonObject.get("2").get("test"), is(JsonValue.Null.INSTANCE));
    JsonValue.Array numbers = jsonObject.get(NUMBERS).asArray();
    assertThat(numbers.size(), is(3));
    assertThat(numbers.get(0), is(not(JsonValue.Null.INSTANCE)));
    assertThat(numbers.get(1), is(JsonValue.Null.INSTANCE));
    assertThat(numbers.get(2), is(JsonValue.Null.INSTANCE));
}
Also used : JsonValue(au.com.dius.pact.core.support.json.JsonValue) PactDslJsonBody(au.com.dius.pact.consumer.dsl.PactDslJsonBody) DslPart(au.com.dius.pact.consumer.dsl.DslPart) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

DslPart (au.com.dius.pact.consumer.dsl.DslPart)32 PactDslJsonBody (au.com.dius.pact.consumer.dsl.PactDslJsonBody)26 PactDslJsonArray (au.com.dius.pact.consumer.dsl.PactDslJsonArray)15 Test (org.junit.Test)10 HashSet (java.util.HashSet)9 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)8 LambdaDsl (au.com.dius.pact.consumer.dsl.LambdaDsl)7 RequestResponsePact (au.com.dius.pact.model.RequestResponsePact)7 IOException (java.io.IOException)7 CoreMatchers.is (org.hamcrest.CoreMatchers.is)7 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)7 Test (org.junit.jupiter.api.Test)7 Pact (au.com.dius.pact.core.model.annotations.Pact)4 MatchingRuleGroup (au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup)3 Map (java.util.Map)3 MatchingRules (au.com.dius.pact.core.model.matchingrules.MatchingRules)2 RegexMatcher (au.com.dius.pact.core.model.matchingrules.RegexMatcher)2 JsonValue (au.com.dius.pact.core.support.json.JsonValue)2 JsonSlurper (groovy.json.JsonSlurper)2 MaxTypeMatcher (au.com.dius.pact.core.model.matchingrules.MaxTypeMatcher)1