diff --git a/compatibility-suite/README.md b/compatibility-suite/README.md new file mode 100644 index 000000000..4e67af99d --- /dev/null +++ b/compatibility-suite/README.md @@ -0,0 +1,31 @@ +# Compatability Suite + +This is the implementation of the [Pact Compatability Suite](https://github.com/pact-foundation/pact-compatibility-suite) implemented with Cucumber JVM. + +## Running the suite + +The suite has Gradle tasks for each of the specification versions. For example, to run the V1 features: + +```console + ./gradlew :compatibility-suite:v1 +``` + +### Running just a consumer or provider set of features + +Features for just consumer, provider or messages are identified using Cucumber tags. You can run a subset of features +by providing the matching tags. I.e.: + +```console + ./gradlew :compatibility-suite:v1 -Pcucumber.filter.tags=@consumer +``` + +### Changing the log level + +By default, the suite runs with logging set to ERROR. To change it, either edit the file in +`compatibility-suite/src/test/resources/logback-test.xml` or provide the `cucumber.log.level` property. + +I.e., + +```console + ./gradlew :compatibility-suite:v1 -Pcucumber.log.level=DEBUG +``` diff --git a/compatibility-suite/build.gradle b/compatibility-suite/build.gradle index 6a2813fd8..2c19de97d 100644 --- a/compatibility-suite/build.gradle +++ b/compatibility-suite/build.gradle @@ -22,6 +22,7 @@ dependencies { exclude group: 'au.com.dius.pact.core' } testImplementation 'ch.qos.logback:logback-classic' + testImplementation 'ch.qos.logback:logback-core' implementation 'io.ktor:ktor-http-jvm' } @@ -44,6 +45,11 @@ tasks.register('v1') { classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output args = cucumberArgs systemProperty 'pact_do_not_track', 'true' + if (project.hasProperty('cucumber.log.level')) { + environment 'ROOT_LOG_LEVEL', project.property('cucumber.log.level') + } else { + environment 'ROOT_LOG_LEVEL', 'ERROR' + } } } } diff --git a/compatibility-suite/src/test/groovy/steps/shared/HttpProvider.groovy b/compatibility-suite/src/test/groovy/steps/shared/HttpProvider.groovy index 05fd19897..8aa35822f 100644 --- a/compatibility-suite/src/test/groovy/steps/shared/HttpProvider.groovy +++ b/compatibility-suite/src/test/groovy/steps/shared/HttpProvider.groovy @@ -41,6 +41,7 @@ import org.apache.hc.core5.http.ClassicHttpRequest import org.apache.hc.core5.http.io.entity.StringEntity import static io.ktor.http.HttpHeaderValueParserKt.parseHeaderValue +import static steps.shared.SharedSteps.configureBody @SuppressWarnings(['ThrowRuntimeException', 'AbcMetric']) class HttpProvider { @@ -111,23 +112,7 @@ class HttpProvider { } if (entry['body']) { - if (entry['body'].startsWith('JSON:')) { - interaction.response.headers['content-type'] = ['application/json'] - interaction.response.body = OptionalBody.body(entry['body'][5..-1].bytes, new ContentType('application/json')) - } else if (entry['body'].startsWith('XML:')) { - interaction.response.headers['content-type'] = ['application/xml'] - interaction.response.body = OptionalBody.body(entry['body'][4..-1].bytes, new ContentType('application/xml')) - } else { - String contentType = 'text/plain' - if (entry['content']) { - contentType = entry['content'] - } - interaction.response.headers['content-type'] = [contentType] - File contents = new File("pact-compatibility-suite/fixtures/${entry['body']}") - contents.withInputStream { - interaction.response.body = OptionalBody.body(it.readAllBytes(), new ContentType(contentType)) - } - } + configureBody(entry['body'], interaction.response) } Pact pact = new RequestResponsePact(new Provider('p'), diff --git a/compatibility-suite/src/test/resources/logback-test.xml b/compatibility-suite/src/test/resources/logback-test.xml new file mode 100644 index 000000000..cbe958bf9 --- /dev/null +++ b/compatibility-suite/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + +