Skip to content

Commit

Permalink
feat(compatibility-suite): Implemented remaining V1 scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jul 13, 2023
1 parent 3c10367 commit 31004ad
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
31 changes: 31 additions & 0 deletions compatibility-suite/README.md
Original file line number Diff line number Diff line change
@@ -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
```
6 changes: 6 additions & 0 deletions compatibility-suite/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -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'
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'),
Expand Down
13 changes: 13 additions & 0 deletions compatibility-suite/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="${ROOT_LOG_LEVEL}">
<appender-ref ref="STDOUT" />
</root>

</configuration>

0 comments on commit 31004ad

Please sign in to comment.