Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/DiUS/pact-jvm into featur…
Browse files Browse the repository at this point in the history
…e/publish-to-broker
  • Loading branch information
markozz committed Aug 26, 2020
2 parents db8edb2 + 9c592ff commit 34cbb0c
Show file tree
Hide file tree
Showing 75 changed files with 1,298 additions and 396 deletions.
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
To generate the log, run `git log --pretty='* %h - %s (%an, %ad)' TAGNAME..HEAD` replacing TAGNAME and HEAD as appropriate.

# 4.1.7 - Bugfix Release

* 119421456 - fix: the matcher paths generated by the XML builder should take into account namespaces #1186 (Ronald Holshausen, Sun Aug 9 17:00:04 2020 +1000)
* c07def5c3 - fix: corrected the matcher paths generated by the XML builder #1186 (Ronald Holshausen, Sun Aug 9 15:41:50 2020 +1000)
* 4443e8f43 - Merge pull request #1182 from paweusz/feature/webflux-support (Ronald Holshausen, Sun Aug 9 10:27:24 2020 +1000)
* d84fd3ba3 - Revert version bump (Pawel Pelczar, Sat Aug 8 11:37:16 2020 +0200)
* 1bfeacce7 - fix: JAX-B dependencies for JDK 9+ (Ronald Holshausen, Sat Aug 8 17:19:46 2020 +1000)
* 633c91455 - chore: add example test #1176 (Ronald Holshausen, Sat Aug 8 16:04:40 2020 +1000)
* 52b0bcc90 - fix: remove Gson as a dependency #1180 (Ronald Holshausen, Sat Aug 8 15:44:23 2020 +1000)
* 517c4cf6a - feat: updated the XML builder to be able to set an elements text content (Ronald Holshausen, Wed Aug 5 12:45:01 2020 +1000)
* 467598410 - Support webflux controllers (Pawel Pelczar, Fri Jul 31 21:56:34 2020 +0200)
* e15cf4479 - Extract common part for mvc and webclient targets (Pawel Pelczar, Wed Jul 29 17:49:13 2020 +0200)
* 320da5e27 - Bump version (Pawel Pelczar, Mon Jul 27 20:39:59 2020 +0200)
* 6f1988d32 - Unit test for WebFlux provider verifier based on mvc version (Pawel Pelczar, Sun Jul 26 14:53:08 2020 +0200)
* 1198763c9 - Merge pull request #1175 from amitojduggal/patch-1 (Ronald Holshausen, Sat Jul 25 14:15:54 2020 +1000)
* ec50a9442 - fix: add application/x-www-form-urlencoded as a sub-type of text #1164 (Ronald Holshausen, Sat Jul 25 13:38:55 2020 +1000)
* d383ef75d - doc: update the description of pending pacts #1134 (Ronald Holshausen, Sat Jul 25 12:43:14 2020 +1000)
* 53e7ed9e1 - Unit test for WebFlux target based on mvc version (Pawel Pelczar, Thu Jul 23 08:41:07 2020 +0200)
* ac18c8e68 - Fixed links for consumer/provider and Clojure test (Amitoj Duggal, Wed Jul 22 17:08:13 2020 +0200)
* 4728f06cf - Merge pull request #1172 from JoaoGFarias/patch-2 (Ronald Holshausen, Wed Jul 22 10:47:33 2020 +1000)
* 6edb7422f - Fix request mappings not being found (missing @Controller annotation) (Pawel Pelczar, Tue Jul 21 17:21:33 2020 +0200)
* 48f86f89f - Fixing link to ExampleMessageConsumerTest (João Farias, Tue Jul 21 11:25:33 2020 +0200)
* 46d479284 - WebFlux target skeleton (Pawel Pelczar, Tue Jul 21 07:47:10 2020 +0200)
* dbbf63725 - fix: return the most relevant response from the mock server #1171 (Ronald Holshausen, Mon Jul 20 16:38:18 2020 +1000)
* 5e64bcf72 - feat: allow the provider name to be set from system properties #1160 (Ronald Holshausen, Sun Jul 12 17:10:22 2020 +1000)
* fa0f3f9c7 - fix: don't split header values for known single value headers #1159 (Ronald Holshausen, Sun Jul 12 16:34:02 2020 +1000)
* 576ac530c - fix: don't decode/re-encode URLs when fetched from a broker #1154 (Ronald Holshausen, Sun Jul 12 14:44:22 2020 +1000)
* 5d57acd70 - fix: renamed providerVersion to consumerVersion in Gradle publish task (Ronald Holshausen, Sun Jul 12 14:35:05 2020 +1000)
* 460aecd2a - fix: publishing pacts was broken since 4.0 -> 4.1 refactor (double encoded URLs) (Ronald Holshausen, Sun Jul 12 14:31:49 2020 +1000)
* d7f360a27 - fix: guard against incorrect POM configuration #1153 (Ronald Holshausen, Sun Jul 12 12:18:10 2020 +1000)
* b2d6aed5c - feat: print error response bodies to the console when publishing pacts #1150 (Ronald Holshausen, Sun Jul 12 11:40:51 2020 +1000)
* 3d56a8ab3 - chore: [JUnit 5] rename AmpqTestTarget to MessageTestTarget #383 (Ronald Holshausen, Sun Jul 12 10:05:22 2020 +1000)
* 5978e5a1e - Merge branch 'tinexw-junit5-filtered-pacts-fix' (Ronald Holshausen, Fri Jul 10 10:28:41 2020 +1000)
* 6e071b546 - chore: simplify code a bit (Ronald Holshausen, Fri Jul 10 10:27:51 2020 +1000)
* 73f30e005 - fix: codenarc errors (Ronald Holshausen, Fri Jul 10 10:27:28 2020 +1000)
* 9a1a65871 - Merge pull request #1165 from tinexw/patch-2 (Ronald Holshausen, Fri Jul 10 09:28:01 2020 +1000)
* 0727ff4c1 - fix: Don't publish incomplete verification results #1166 (Kristine Jetzke, Thu Jul 9 22:58:47 2020 +0200)
* ef157cd7b - Add note about not being able to publishing results to @PactFilter section (Kristine Jetzke, Wed Jul 8 23:24:41 2020 +0200)
* 5ce944749 - bump version to 4.1.7 (anto, Fri Jul 3 08:34:10 2020 +0100)

# 4.1.6 - Bugfix Release

* 8807d254c - fix: fix a problem where the provider version trim property is ignored (#1156) (e-ivaldi, Fri Jul 3 07:15:05 2020 +0100)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ You want to look at: [groovy](consumer/groovy) or [junit](consumer/junit)
### (Use Clojure I)

Clojure can call out to Java, so have a look at [junit](consumer/junit). For an example
look at [example_clojure_consumer_pact_test.clj](consumer/junit/src/test/clojure/au/com/dius/pact/consumer/junit/example_clojure_consumer_pact_test.clj).
look at [example_clojure_consumer_pact_test.clj](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/clojure/au/com/dius/pact/consumer/junit/example_clojure_consumer_pact_test.clj).

### I Use some other jvm language or test framework

Expand All @@ -86,7 +86,7 @@ You want to look at: [Consumer](consumer)
### My Consumer interacts with a Message Queue

As part of the V3 pact specification, we have defined a new pact file for interactions with message queues. For an
implementation of a Groovy consumer test with a message pact, have a look at [PactMessageBuilderSpec.groovy](consumer/groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/messaging/PactMessageBuilderSpec.groovy).
implementation of a Groovy consumer test with a message pact, have a look at [PactMessageBuilderSpec.groovy](https://github.com/DiUS/pact-jvm/blob/master/consumer/groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/messaging/PactMessageBuilderSpec.groovy).

## Service Providers

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ subprojects {
return
}

version = '4.1.7'
version = '4.1.8'

buildscript {
repositories {
Expand Down
2 changes: 1 addition & 1 deletion consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ DslPart body = new PactDslJsonBody()

```

For an example, have a look at [WildcardKeysTest](/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/WildcardKeysTest.java).
For an example, have a look at [WildcardKeysTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/WildcardKeysTest.java).

**NOTE:** The `eachKeyLike` method adds a `*` to the matching path, so the matching definition will be applied to all keys
of the map if there is not a more specific matcher defined for a particular key. Having more than one `eachKeyLike` condition
Expand Down
4 changes: 2 additions & 2 deletions consumer/groovy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ withBody {
}
```

For an example, have a look at [WildcardPactSpec](/consumer/groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/WildcardPactSpec.groovy).
For an example, have a look at [WildcardPactSpec](https://github.com/DiUS/pact-jvm/blob/master/consumer/groovy/src/test/groovy/au/com/dius/pact/consumer/groovy/WildcardPactSpec.groovy).

**NOTE:** The `keyLike` method adds a `*` to the matching path, so the matching definition will be applied to all keys
of the map if there is not a more specific matcher defined for a particular key. Having more than one `keyLike` condition
Expand Down Expand Up @@ -539,7 +539,7 @@ overwritten, set the Java system property `pact.writer.overwrite` to `true`.

# Publishing your pact files to a pact broker

If you use Gradle, you can use the [pact Gradle plugin](../../provider/gradle#publishing-pact-files-to-a-pact-broker) to publish your pact files.
If you use Gradle, you can use the [pact Gradle plugin](https://github.com/DiUS/pact-jvm/tree/master/provider/gradle#publishing-pact-files-to-a-pact-broker) to publish your pact files.

# Pact Specification V3

Expand Down
20 changes: 10 additions & 10 deletions consumer/junit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ You can leave the provider name out. It will then use the provider name of the f
}
```

For an example, have a look at [ExampleJavaConsumerPactRuleTest](src/test/java/au/com/dius/pact/consumer/examples/ExampleJavaConsumerPactRuleTest.java)
For an example, have a look at [ExampleJavaConsumerPactRuleTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/examples/ExampleJavaConsumerPactRuleTest.java)

### Requiring a test with multiple providers

The Pact Rule can be used to test with multiple providers. Just add a rule to the test class for each provider, and
then include all the providers required in the `@PactVerification` annotation. For an example, look at
[PactMultiProviderTest](src/test/java/au/com/dius/pact/consumer/pactproviderrule/PactMultiProviderTest.java).
[PactMultiProviderTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/pactproviderrule/PactMultiProviderTest.java).

Note that if more than one provider fails verification for the same test, you will only receive a failure for one of them.
Also, to have multiple tests in the same test class, the providers must be setup with random ports (i.e. don't specify
Expand All @@ -192,12 +192,12 @@ E.g.:
PactSpecVersion.V2, this); // ^^^^
```

For an example test doing this, see [PactProviderHttpsTest](src/test/java/au/com/dius/pact/consumer/pactproviderrule/PactProviderHttpsTest.java).
For an example test doing this, see [PactProviderHttpsTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/pactproviderrule/PactProviderHttpsTest.java).

**NOTE:** The provider will start handling HTTPS requests using a self-signed certificate. Most HTTP clients will not accept
connections to a self-signed server as the certificate is untrusted. You may need to enable insecure HTTPS with your client
for this test to work. For an example of how to enable insecure HTTPS client connections with Apache Http Client, have a
look at [InsecureHttpsRequest](src/test/java/org/apache/http/client/fluent/InsecureHttpsRequest.java).
look at [InsecureHttpsRequest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/org/apache/http/client/fluent/InsecureHttpsRequest.java).

### Requiring the mock server to run with HTTPS with a keystore

Expand All @@ -212,7 +212,7 @@ E.g.:
"/path/to/your/keystore.jks", "your-keystore-password", PactSpecVersion.V2, this);
```

For an example test doing this, see [PactProviderHttpsKeystoreTest](src/test/java/au/com/dius/pact/consumer/pactproviderrule/PactProviderHttpsKeystoreTest.java).
For an example test doing this, see [PactProviderHttpsKeystoreTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/pactproviderrule/PactProviderHttpsKeystoreTest.java).

### Setting default expected request and response values

Expand All @@ -239,7 +239,7 @@ For example:
}
```

For an example test that uses these, have a look at [PactProviderWithMultipleFragmentsTest](src/test/java/au/com/dius/pact/consumer/pactproviderrule/PactProviderWithMultipleFragmentsTest.java)
For an example test that uses these, have a look at [PactProviderWithMultipleFragmentsTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/pactproviderrule/PactProviderWithMultipleFragmentsTest.java)

### Note on HTTP clients and persistent connections

Expand Down Expand Up @@ -347,7 +347,7 @@ is verified. It is only recorded in the consumer tests and used by the provider

### Building JSON bodies with PactDslJsonBody DSL

**NOTE:** If you are using Java 8, there is [an updated DSL for consumer tests](../java8).
**NOTE:** If you are using Java 8, there is [an updated DSL for consumer tests](https://github.com/DiUS/pact-jvm/tree/master/consumer/java8).

The body method of the ConsumerPactBuilder can accept a PactDslJsonBody, which can construct a JSON body as well as
define regex and type matchers.
Expand Down Expand Up @@ -520,7 +520,7 @@ DslPart body = new PactDslJsonBody()

```

For an example, have a look at [WildcardKeysTest](src/test/java/au/com/dius/pact/consumer/WildcardKeysTest.java).
For an example, have a look at [WildcardKeysTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/WildcardKeysTest.java).

**NOTE:** The `eachKeyLike` method adds a `*` to the matching path, so the matching definition will be applied to all keys
of the map if there is not a more specific matcher defined for a particular key. Having more than one `eachKeyLike` condition
Expand Down Expand Up @@ -677,7 +677,7 @@ overwritten, set the Java system property `pact.writer.overwrite` to `true`.

# Publishing your pact files to a pact broker

If you use Gradle, you can use the [pact Gradle plugin](../../provider/gradle#publishing-pact-files-to-a-pact-broker) to publish your pact files.
If you use Gradle, you can use the [pact Gradle plugin](https://github.com/DiUS/pact-jvm/tree/master/provider/gradle#publishing-pact-files-to-a-pact-broker) to publish your pact files.

# Pact Specification V3

Expand Down Expand Up @@ -712,7 +712,7 @@ If you are using the `PactProviderRule`, you can pass the version into the const
For testing a consumer of messages from a message queue, the `MessagePactProviderRule` rule class works in much the
same way as the `PactProviderRule` class for Request-Response interactions, but will generate a V3 format message pact file.

For an example, look at [ExampleMessageConsumerTest](src/test/java/au/com/dius/pact/consumer/junit/v3/ExampleMessageConsumerTest.java)
For an example, look at [ExampleMessageConsumerTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/v3/ExampleMessageConsumerTest.java)

# Having values injected from provider state callbacks (3.6.11+)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void provider2Fails() throws IOException {
mockTestProvider2.validateResultWith((result, t) -> {
assertThat(t, is(instanceOf(AssertionError.class)));
assertThat(t.getMessage(), is("The following mismatched requests occurred:\n" +
"BodyMismatch: $.name Expected 'larry' (String) but received 'farry' (String)"));
"body - $.name: Expected 'larry' (String) but received 'farry' (String)"));
assertThat(result, is(instanceOf(PactVerificationResult.Mismatches.class)));
PactVerificationResult.Mismatches error = (PactVerificationResult.Mismatches) result;
assertThat(error.getMismatches(), hasSize(1));
Expand Down Expand Up @@ -152,7 +152,7 @@ public void bothprovidersFail() throws IOException {
mockTestProvider2.validateResultWith((result, t) -> {
assertThat(t, is(instanceOf(AssertionError.class)));
assertThat(t.getMessage(), is("The following mismatched requests occurred:\n" +
"BodyMismatch: $.name Expected 'larry' (String) but received 'farry' (String)"));
"body - $.name: Expected 'larry' (String) but received 'farry' (String)"));
assertThat(result, is(instanceOf(PactVerificationResult.Mismatches.class)));
PactVerificationResult.Mismatches error = (PactVerificationResult.Mismatches) result;
assertThat(error.getMismatches(), hasSize(1));
Expand Down
8 changes: 4 additions & 4 deletions consumer/junit5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ interactions for the test.

Then the final step is to use the `@PactTestFor` annotation to tell the Pact extension how to setup the Pact test. You
can either put this annotation on the test class, or on the test method. For examples see
[ArticlesTest](src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java) and
[MultiTest](src/test/groovy/au/com/dius/pact/consumer/junit5/MultiTest.groovy).
[ArticlesTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java) and
[MultiTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/MultiTest.groovy).

The `@PactTestFor` annotation allows you to control the mock server in the same way as the JUnit 4 `PactProviderRule`. It
allows you to set the hostname to bind to (default is `localhost`) and the port (default is to use a random port). You
Expand All @@ -72,13 +72,13 @@ public class ExampleJavaConsumerPactTest {
#### Matching the interactions by provider name

If you set the `providerName` on the `@PactTestFor` annotation, then the first method with a `@Pact` annotation with the
same provider name will be used. See [ArticlesTest](src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java) for
same provider name will be used. See [ArticlesTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java) for
an example.

#### Matching the interactions by method name

If you set the `pactMethod` on the `@PactTestFor` annotation, then the method with the provided name will be used (it still
needs a `@Pact` annotation). See [MultiTest](src/test/groovy/au/com/dius/pact/consumer/junit5/MultiTest.groovy) for an example.
needs a `@Pact` annotation). See [MultiTest](https://github.com/DiUS/pact-jvm/blob/master/consumer/junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/MultiTest.groovy) for an example.

### Injecting the mock server into the test

Expand Down
5 changes: 5 additions & 0 deletions consumer/junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ dependencies {
exclude group: 'org.codehaus.groovy'
}
testCompile "org.apache.httpcomponents:httpclient:${project.httpClientVersion}"
testCompile 'com.jayway.restassured:rest-assured:2.9.0'

// JAX-B dependencies for JDK 9+
testCompile "jakarta.xml.bind:jakarta.xml.bind-api:2.3.2"
testCompile "org.glassfish.jaxb:jaxb-runtime:2.3.2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package au.com.dius.pact.consumer.junit5;

import au.com.dius.pact.consumer.MockServer;
import au.com.dius.pact.consumer.dsl.PactDslWithProvider;
import au.com.dius.pact.core.model.RequestResponsePact;
import au.com.dius.pact.core.model.annotations.Pact;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.filter.log.RequestLoggingFilter;
import com.jayway.restassured.filter.log.ResponseLoggingFilter;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.Collections;
import java.util.Map;

import static com.jayway.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@ExtendWith({PactConsumerTestExt.class})
public class Issue1176Test {
private static final String CONFIG_URL = "/config";

@BeforeEach
public void setUp(MockServer mockServer) {
assertNotNull(mockServer);
}

@Pact(provider = "config-service", consumer = "test-integration")
public RequestResponsePact validCredentials(PactDslWithProvider builder) {
Map<String, String> headers = Collections.singletonMap("Content-Type", ContentType.TEXT.toString());

RequestResponsePact pact = builder
.uponReceiving("valid configuration")
.path(CONFIG_URL)
.method("GET")
.headers(headers)
.body("text")
.willRespondWith()
.status(200)
.body("{\"data\":\"\", \"status\":\"success\"}")
.toPact();

return pact;
}

@Test
@PactTestFor(hostInterface = "localhost", pactMethod = "validCredentials", port = "7001")
public void runTest(MockServer mockServer) {
RequestLoggingFilter requestLoggingFilter = new RequestLoggingFilter();
ResponseLoggingFilter responseLoggingFilter = new ResponseLoggingFilter();

RequestSpecification requestSpec = new RequestSpecBuilder()
.setContentType(ContentType.TEXT)
.setPort(mockServer.getPort())
.setBasePath(CONFIG_URL)
.addFilter(requestLoggingFilter)
.addFilter(responseLoggingFilter)
.setBody("text")
.build();

Response response = given().spec(requestSpec).get();
assertEquals("success", response.body().jsonPath().get("status"));
}
}
Loading

0 comments on commit 34cbb0c

Please sign in to comment.