Download JAR files tagged by defaults with all dependencies
datetime from group org.pojava (version 3.0.2)
POJava DateTime is a simple, light-weight Java-based API for parsing and manipulating dates.
It parses dates from most languages and formats out of the box without having to specify which
format is expected. Defaults such as time zones, and whether to interpret an internationally
ambiguous date like "03/06/2014" as DMY order or MDY order are inferred by system time zone
and locale and stored in a default config object that can be replaced or overridden. Multiple
languages for month names are supported without any additional configuration needed.
Artifact datetime
Group org.pojava
Version 3.0.2
Last update 04. June 2015
Organization not specified
URL http://www.pojava.org
License The Apache Software License, Version 2.0
Dependencies amount 0
Dependencies No dependencies
There are maybe transitive dependencies!
Group org.pojava
Version 3.0.2
Last update 04. June 2015
Organization not specified
URL http://www.pojava.org
License The Apache Software License, Version 2.0
Dependencies amount 0
Dependencies No dependencies
There are maybe transitive dependencies!
org.pojava.datetime from group org.pojava (version 3.0.0)
POJava DateTime is a simple, light-weight Java-based API for parsing and manipulating dates.
It parses dates from most languages and formats out of the box without having to specify which
format is expected. Defaults such as time zones, and whether to interpret an internationally
ambiguous date like "03/06/2014" as DMY order or MDY order are inferred by system time zone
and locale and stored in a default config object that can be replaced or overridden. Multiple
languages for month names are supported without any additional configuration needed.
The net effect the default parser for a server in Paris would have a different automatic
configuration from a server in New York. Throw a random local date at either, and it'll
parse it as expected. If your server supports customers from multiple locales and time zones,
then each can be specified when parsing a date/time to resolve any ambiguities.
Artifact org.pojava.datetime
Group org.pojava
Version 3.0.0
Last update 11. March 2014
Organization not specified
URL http://www.pojava.org
License The Apache Software License, Version 2.0
Dependencies amount 0
Dependencies No dependencies
There are maybe transitive dependencies!
Group org.pojava
Version 3.0.0
Last update 11. March 2014
Organization not specified
URL http://www.pojava.org
License The Apache Software License, Version 2.0
Dependencies amount 0
Dependencies No dependencies
There are maybe transitive dependencies!
pact-jvm-server_2.12 from group au.com.dius (version 3.6.15)
Pact server
===========
The pact server is a stand-alone interactions recorder and verifier, aimed at clients that are non-JVM or non-Ruby based.
The pact client for that platform will need to be implemented, but it only be responsible for generating the `JSON`
interactions, running the tests and communicating with the server.
The server implements a `JSON` `REST` Admin API with the following endpoints.
/ -> For diagnostics, currently returns a list of ports of the running mock servers.
/create -> For initialising a test server and submitting the JSON interactions. It returns a port
/complete -> For finalising and verifying the interactions with the server. It writes the `JSON` pact file to disk.
## Running the server
### Versions 2.2.6+
Pact server takes the following parameters:
```
Usage: pact-jvm-server [options] [port]
port
port to run on (defaults to 29999)
--help
prints this usage text
-h <value> | --host <value>
host to bind to (defaults to localhost)
-l <value> | --mock-port-lower <value>
lower bound to allocate mock ports (defaults to 20000)
-u <value> | --mock-port-upper <value>
upper bound to allocate mock ports (defaults to 40000)
-d | --daemon
run as a daemon process
-v <value> | --pact-version <value>
pact version to generate for (2 or 3)
-k <value> | --keystore-path <value>
Path to keystore
-p <value> | --keystore-password <value>
Keystore password
-s <value> | --ssl-port <value>
Ssl port the mock server should run on. lower and upper bounds are ignored
--debug
run with debug logging
```
### Using trust store 3.4.0+
Trust store can be used. However, it is limited to a single port for the time being.
### Prior to version 2.2.6
Pact server takes one optional parameter, the port number to listen on. If not provided, it will listen on 29999.
It requires an active console to run.
### Using a distribution archive
You can download a [distribution from maven central](http://search.maven.org/remotecontent?filepath=au/com/dius/pact-jvm-server_2.11/2.2.4/).
There is both a ZIP and TAR archive. Unpack it to a directory of choice and then run the script in the bin directory.
### Building a distribution bundle
You can build an application bundle with gradle by running (for 2.11 version):
$ ./gradlew :pact-jvm-server_2.11:installdist
This will create an app bundle in `build/2.11/install/pact-jvm-server_2.11`. You can then execute it with:
$ java -jar pact-jvm-server/build/2.10/install/pact-jvm-server_2.11/lib/pact-jvm-server_2.11-3.2.11.jar
or with the generated bundle script file:
$ pact-jvm-server/build/2.11/install/pact-jvm-server_2.11/bin/pact-jvm-server_2.11
By default will run on port `29999` but a port number can be optionally supplied.
### Running it with docker
You can use a docker image to execute the mock server as a docker container.
$ docker run -d -p 8080:8080 -p 20000-20010:20000-20010 uglyog/pact-jvm-server
This will run the main server on port 8080, and each created mock server on ports 20000-20010. You can map the ports to
any you require.
## Life cycle
The following actions are expected to occur
* The client calls `/create` to initialise a server with the expected `JSON` interactions and state
* The admin server will start a mock server on a random port and return the port number in the response
* The client will execute its interaction tests against the mock server with the supplied port
* Once finished, the client will call `/complete' on the Admin API, posting the port number
* The pact server will verify the interactions and write the `JSON` `pact` file to disk under `/target`
* The mock server running on the supplied port will be shutdown.
## Endpoints
### /create
The client will need `POST` to `/create` the generated `JSON` interactions, also providing a state as a query parameter
and a path.
For example:
POST http://localhost:29999/create?state=NoUsers&path=/sub/ref/path '{ "provider": { "name": "Animal_Service"}, ... }'
This will create a new running mock service provider on a randomly generated port. The port will be returned in the
`201` response:
{ "port" : 34423 }
But you can also reference the path from `/sub/ref/path` using the server port. The service will not strip
the prefix path, but instead will use it as a differentiator. If your services do not have differences
in the prefix of their path, then you will have to use the port method.
### /complete
Once the client has finished running its tests against the mock server on the supplied port (in this example port
`34423`) the client will need to `POST` to `/complete` the port number of the mock server that was used.
For example:
POST http://localhost:29999/complete '{ "port" : 34423 }'
This will cause the Pact server to verify the interactions, shutdown the mock server running on that port and writing
the pact `JSON` file to disk under the `target` directory.
### /
The `/` endpoint is for diagnostics and to check that the pact server is running. It will return all the currently
running mock servers port numbers.
For example:
GET http://localhost:29999/
'{ "ports": [23443,43232] }'
2 downloads
Artifact pact-jvm-server_2.12
Group au.com.dius
Version 3.6.15
Last update 29. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 4
Dependencies pact-jvm-consumer_2.12, logback-core, logback-classic, scopt_2.12,
There are maybe transitive dependencies!
Group au.com.dius
Version 3.6.15
Last update 29. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 4
Dependencies pact-jvm-consumer_2.12, logback-core, logback-classic, scopt_2.12,
There are maybe transitive dependencies!
pact-jvm-provider-spring_2.12 from group au.com.dius (version 3.6.15)
# Pact Spring/JUnit runner
## Overview
Library provides ability to play contract tests against a provider using Spring & JUnit.
This library is based on and references the JUnit package, so see the [Pact JUnit 4](../pact-jvm-provider-junit) or [Pact JUnit 5](../pact-jvm-provider-junit5) providers for more details regarding configuration using JUnit.
Supports:
- Standard ways to load pacts from folders and broker
- Easy way to change assertion strategy
- Spring Test MockMVC Controllers and ControllerAdvice using MockMvc standalone setup.
- MockMvc debugger output
- Multiple @State runs to test a particular Provider State multiple times
- **au.com.dius.pact.provider.junit.State** custom annotation - before each interaction that requires a state change,
all methods annotated by `@State` with appropriate the state listed will be invoked.
**NOTE:** For publishing provider verification results to a pact broker, make sure the Java system property `pact.provider.version`
is set with the version of your provider.
## Example of MockMvc test
```java
@RunWith(RestPactRunner.class) // Custom pact runner, child of PactRunner which runs only REST tests
@Provider("myAwesomeService") // Set up name of tested provider
@PactFolder("pacts") // Point where to find pacts (See also section Pacts source in documentation)
public class ContractTest {
//Create an instance of your controller. We cannot autowire this as we're not using (and don't want to use) a Spring test runner.
@InjectMocks
private AwesomeController awesomeController = new AwesomeController();
//Mock your service logic class. We'll use this to create scenarios for respective provider states.
@Mock
private AwesomeBusinessLogic awesomeBusinessLogic;
//Create an instance of your controller advice (if you have one). This will be passed to the MockMvcTarget constructor to be wired up with MockMvc.
@InjectMocks
private AwesomeControllerAdvice awesomeControllerAdvice = new AwesomeControllerAdvice();
//Create a new instance of the MockMvcTarget and annotate it as the TestTarget for PactRunner
@TestTarget
public final MockMvcTarget target = new MockMvcTarget();
@Before //Method will be run before each test of interaction
public void before() {
//initialize your mocks using your mocking framework
MockitoAnnotations.initMocks(this);
//configure the MockMvcTarget with your controller and controller advice
target.setControllers(awesomeController);
target.setControllerAdvice(awesomeControllerAdvice);
}
@State("default", "no-data") // Method will be run before testing interactions that require "default" or "no-data" state
public void toDefaultState() {
target.setRunTimes(3); //let's loop through this state a few times for a 3 data variants
when(awesomeBusinessLogic.getById(any(UUID.class)))
.thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.ONE))
.thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.TWO))
.thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.THREE));
}
@State("error-case")
public void SingleUploadExistsState_Success() {
target.setRunTimes(1); //tell the runner to only loop one time for this state
//you might want to throw exceptions to be picked off by your controller advice
when(awesomeBusinessLogic.getById(any(UUID.class)))
.then(i -> { throw new NotCoolException(i.getArgumentAt(0, UUID.class).toString()); });
}
}
```
## Using a Spring runner (version 3.5.7+)
You can use `SpringRestPactRunner` instead of the default Pact runner to use the Spring test annotations. This will
allow you to inject or mock spring beans.
For example:
```java
@RunWith(SpringRestPactRunner.class)
@Provider("pricing")
@PactBroker(protocol = "https", host = "${pactBrokerHost}", port = "443",
authentication = @PactBrokerAuth(username = "${pactBrokerUser}", password = "${pactBrokerPassword}"))
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class PricingServiceProviderPactTest {
@MockBean
private ProductClient productClient; // This will replace the bean with a mock in the application context
@TestTarget
@SuppressWarnings(value = "VisibilityModifier")
public final Target target = new HttpTarget(8091);
@State("Product X010000021 exists")
public void setupProductX010000021() throws IOException {
reset(productClient);
ProductBuilder product = new ProductBuilder()
.withProductCode("X010000021");
when(productClient.fetch((Set<String>) argThat(contains("X010000021")), any())).thenReturn(product);
}
@State("the product code X00001 can be priced")
public void theProductCodeX00001CanBePriced() throws IOException {
reset(productClient);
ProductBuilder product = new ProductBuilder()
.withProductCode("X00001");
when(productClient.find((Set<String>) argThat(contains("X00001")), any())).thenReturn(product);
}
}
```
### Using Spring Context Properties (version 3.5.14+)
From version 3.5.14 onwards, the SpringRestPactRunner will look up any annotation expressions (like `${pactBrokerHost}`)
above) from the Spring context. For Springboot, this will allow you to define the properties in the application test properties.
For instance, if you create the following `application.yml` in the test resources:
```yaml
pactbroker:
host: "your.broker.local"
port: "443"
protocol: "https"
auth:
username: "<your broker username>"
password: "<your broker password>"
```
Then you can use the defaults on the `@PactBroker` annotation.
```java
@RunWith(SpringRestPactRunner.class)
@Provider("My Service")
@PactBroker(
authentication = @PactBrokerAuth(username = "${pactbroker.auth.username}", password = "${pactbroker.auth.password}")
)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PactVerificationTest {
```
### Using a random port with a Springboot test (version 3.5.14+)
If you use a random port in a springboot test (by setting `SpringBootTest.WebEnvironment.RANDOM_PORT`), you can use the
`SpringBootHttpTarget` which will get the application port from the spring application context.
For example:
```java
@RunWith(SpringRestPactRunner.class)
@Provider("My Service")
@PactBroker
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PactVerificationTest {
@TestTarget
public final Target target = new SpringBootHttpTarget();
}
```
Group: au.com.dius Artifact: pact-jvm-provider-spring_2.12
Show all versions Show documentation Show source
Show all versions Show documentation Show source
1 downloads
Artifact pact-jvm-provider-spring_2.12
Group au.com.dius
Version 3.6.15
Last update 29. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 5
Dependencies pact-jvm-provider-junit_2.12, spring-boot-starter-test, spring-webmvc, javax.servlet-api, jackson-datatype-joda,
There are maybe transitive dependencies!
Group au.com.dius
Version 3.6.15
Last update 29. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 5
Dependencies pact-jvm-provider-junit_2.12, spring-boot-starter-test, spring-webmvc, javax.servlet-api, jackson-datatype-joda,
There are maybe transitive dependencies!
pact-jvm-server from group au.com.dius (version 4.0.10)
Pact server
===========
The pact server is a stand-alone interactions recorder and verifier, aimed at clients that are non-JVM or non-Ruby based.
The pact client for that platform will need to be implemented, but it only be responsible for generating the `JSON`
interactions, running the tests and communicating with the server.
The server implements a `JSON` `REST` Admin API with the following endpoints.
/ -> For diagnostics, currently returns a list of ports of the running mock servers.
/create -> For initialising a test server and submitting the JSON interactions. It returns a port
/complete -> For finalising and verifying the interactions with the server. It writes the `JSON` pact file to disk.
## Running the server
### Versions 2.2.6+
Pact server takes the following parameters:
```
Usage: pact-jvm-server [options] [port]
port
port to run on (defaults to 29999)
--help
prints this usage text
-h <value> | --host <value>
host to bind to (defaults to localhost)
-l <value> | --mock-port-lower <value>
lower bound to allocate mock ports (defaults to 20000)
-u <value> | --mock-port-upper <value>
upper bound to allocate mock ports (defaults to 40000)
-d | --daemon
run as a daemon process
-v <value> | --pact-version <value>
pact version to generate for (2 or 3)
-k <value> | --keystore-path <value>
Path to keystore
-p <value> | --keystore-password <value>
Keystore password
-s <value> | --ssl-port <value>
Ssl port the mock server should run on. lower and upper bounds are ignored
--debug
run with debug logging
```
### Using trust store 3.4.0+
Trust store can be used. However, it is limited to a single port for the time being.
### Prior to version 2.2.6
Pact server takes one optional parameter, the port number to listen on. If not provided, it will listen on 29999.
It requires an active console to run.
### Using a distribution archive
You can download a [distribution from maven central](http://search.maven.org/remotecontent?filepath=au/com/dius/pact-jvm-server_2.11/2.2.4/).
There is both a ZIP and TAR archive. Unpack it to a directory of choice and then run the script in the bin directory.
### Building a distribution bundle
You can build an application bundle with gradle by running (for 2.11 version):
$ ./gradlew :pact-jvm-server_2.11:installdist
This will create an app bundle in `build/2.11/install/pact-jvm-server_2.11`. You can then execute it with:
$ java -jar pact-jvm-server/build/2.10/install/pact-jvm-server_2.11/lib/pact-jvm-server_2.11-3.2.11.jar
or with the generated bundle script file:
$ pact-jvm-server/build/2.11/install/pact-jvm-server_2.11/bin/pact-jvm-server_2.11
By default will run on port `29999` but a port number can be optionally supplied.
### Running it with docker
You can use a docker image to execute the mock server as a docker container.
$ docker run -d -p 8080:8080 -p 20000-20010:20000-20010 uglyog/pact-jvm-server
This will run the main server on port 8080, and each created mock server on ports 20000-20010. You can map the ports to
any you require.
## Life cycle
The following actions are expected to occur
* The client calls `/create` to initialise a server with the expected `JSON` interactions and state
* The admin server will start a mock server on a random port and return the port number in the response
* The client will execute its interaction tests against the mock server with the supplied port
* Once finished, the client will call `/complete' on the Admin API, posting the port number
* The pact server will verify the interactions and write the `JSON` `pact` file to disk under `/target`
* The mock server running on the supplied port will be shutdown.
## Endpoints
### /create
The client will need `POST` to `/create` the generated `JSON` interactions, also providing a state as a query parameter
and a path.
For example:
POST http://localhost:29999/create?state=NoUsers&path=/sub/ref/path '{ "provider": { "name": "Animal_Service"}, ... }'
This will create a new running mock service provider on a randomly generated port. The port will be returned in the
`201` response:
{ "port" : 34423 }
But you can also reference the path from `/sub/ref/path` using the server port. The service will not strip
the prefix path, but instead will use it as a differentiator. If your services do not have differences
in the prefix of their path, then you will have to use the port method.
### /complete
Once the client has finished running its tests against the mock server on the supplied port (in this example port
`34423`) the client will need to `POST` to `/complete` the port number of the mock server that was used.
For example:
POST http://localhost:29999/complete '{ "port" : 34423 }'
This will cause the Pact server to verify the interactions, shutdown the mock server running on that port and writing
the pact `JSON` file to disk under the `target` directory.
### /
The `/` endpoint is for diagnostics and to check that the pact server is running. It will return all the currently
running mock servers port numbers.
For example:
GET http://localhost:29999/
'{ "ports": [23443,43232] }'
0 downloads
Artifact pact-jvm-server
Group au.com.dius
Version 4.0.10
Last update 18. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 0
Dependencies No dependencies
There are maybe transitive dependencies!
Group au.com.dius
Version 4.0.10
Last update 18. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 0
Dependencies No dependencies
There are maybe transitive dependencies!
pact-jvm-provider-spring_2.11 from group au.com.dius (version 3.5.24)
# Pact Spring/JUnit runner
## Overview
Library provides ability to play contract tests against a provider using Spring & JUnit.
This library is based on and references the JUnit package, so see [junit provider support](pact-jvm-provider-junit) for more details regarding configuration using JUnit.
Supports:
- Standard ways to load pacts from folders and broker
- Easy way to change assertion strategy
- Spring Test MockMVC Controllers and ControllerAdvice using MockMvc standalone setup.
- MockMvc debugger output
- Multiple @State runs to test a particular Provider State multiple times
- **au.com.dius.pact.provider.junit.State** custom annotation - before each interaction that requires a state change,
all methods annotated by `@State` with appropriate the state listed will be invoked.
**NOTE:** For publishing provider verification results to a pact broker, make sure the Java system property `pact.provider.version`
is set with the version of your provider.
## Example of MockMvc test
```java
@RunWith(RestPactRunner.class) // Custom pact runner, child of PactRunner which runs only REST tests
@Provider("myAwesomeService") // Set up name of tested provider
@PactFolder("pacts") // Point where to find pacts (See also section Pacts source in documentation)
public class ContractTest {
//Create an instance of your controller. We cannot autowire this as we're not using (and don't want to use) a Spring test runner.
@InjectMocks
private AwesomeController awesomeController = new AwesomeController();
//Mock your service logic class. We'll use this to create scenarios for respective provider states.
@Mock
private AwesomeBusinessLogic awesomeBusinessLogic;
//Create an instance of your controller advice (if you have one). This will be passed to the MockMvcTarget constructor to be wired up with MockMvc.
@InjectMocks
private AwesomeControllerAdvice awesomeControllerAdvice = new AwesomeControllerAdvice();
//Create a new instance of the MockMvcTarget and annotate it as the TestTarget for PactRunner
@TestTarget
public final MockMvcTarget target = new MockMvcTarget();
@Before //Method will be run before each test of interaction
public void before() {
//initialize your mocks using your mocking framework
MockitoAnnotations.initMocks(this);
//configure the MockMvcTarget with your controller and controller advice
target.setControllers(awesomeController);
target.setControllerAdvice(awesomeControllerAdvice);
}
@State("default", "no-data") // Method will be run before testing interactions that require "default" or "no-data" state
public void toDefaultState() {
target.setRunTimes(3); //let's loop through this state a few times for a 3 data variants
when(awesomeBusinessLogic.getById(any(UUID.class)))
.thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.ONE))
.thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.TWO))
.thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.THREE));
}
@State("error-case")
public void SingleUploadExistsState_Success() {
target.setRunTimes(1); //tell the runner to only loop one time for this state
//you might want to throw exceptions to be picked off by your controller advice
when(awesomeBusinessLogic.getById(any(UUID.class)))
.then(i -> { throw new NotCoolException(i.getArgumentAt(0, UUID.class).toString()); });
}
}
```
## Using a Spring runner (version 3.5.7+)
You can use `SpringRestPactRunner` instead of the default Pact runner to use the Spring test annotations. This will
allow you to inject or mock spring beans.
For example:
```java
@RunWith(SpringRestPactRunner.class)
@Provider("pricing")
@PactBroker(protocol = "https", host = "${pactBrokerHost}", port = "443",
authentication = @PactBrokerAuth(username = "${pactBrokerUser}", password = "${pactBrokerPassword}"))
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class PricingServiceProviderPactTest {
@MockBean
private ProductClient productClient; // This will replace the bean with a mock in the application context
@TestTarget
@SuppressWarnings(value = "VisibilityModifier")
public final Target target = new HttpTarget(8091);
@State("Product X010000021 exists")
public void setupProductX010000021() throws IOException {
reset(productClient);
ProductBuilder product = new ProductBuilder()
.withProductCode("X010000021");
when(productClient.fetch((Set<String>) argThat(contains("X010000021")), any())).thenReturn(product);
}
@State("the product code X00001 can be priced")
public void theProductCodeX00001CanBePriced() throws IOException {
reset(productClient);
ProductBuilder product = new ProductBuilder()
.withProductCode("X00001");
when(productClient.find((Set<String>) argThat(contains("X00001")), any())).thenReturn(product);
}
}
```
### Using Spring Context Properties (version 3.5.14+)
From version 3.5.14 onwards, the SpringRestPactRunner will look up any annotation expressions (like `${pactBrokerHost}`)
above) from the Spring context. For Springboot, this will allow you to define the properties in the application test properties.
For instance, if you create the following `application.yml` in the test resources:
```yaml
pactbroker:
host: "your.broker.local"
port: "443"
protocol: "https"
auth:
username: "<your broker username>"
password: "<your broker password>"
```
Then you can use the defaults on the `@PactBroker` annotation.
```java
@RunWith(SpringRestPactRunner.class)
@Provider("My Service")
@PactBroker(
authentication = @PactBrokerAuth(username = "${pactbroker.auth.username}", password = "${pactbroker.auth.password}")
)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PactVerificationTest {
```
### Using a random port with a Springboot test (version 3.5.14+)
If you use a random port in a springboot test (by setting `SpringBootTest.WebEnvironment.RANDOM_PORT`), you can use the
`SpringBootHttpTarget` which will get the application port from the spring application context.
For example:
```java
@RunWith(SpringRestPactRunner.class)
@Provider("My Service")
@PactBroker
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PactVerificationTest {
@TestTarget
public final Target target = new SpringBootHttpTarget();
}
```
Group: au.com.dius Artifact: pact-jvm-provider-spring_2.11
Show all versions Show documentation Show source
Show all versions Show documentation Show source
2 downloads
Artifact pact-jvm-provider-spring_2.11
Group au.com.dius
Version 3.5.24
Last update 04. November 2018
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 13
Dependencies kotlin-stdlib-jdk8, kotlin-reflect, slf4j-api, groovy-all, kotlin-logging, scala-library, scala-logging_2.11, pact-jvm-provider-junit_2.11, spring-boot-starter-test, spring-web, spring-webmvc, javax.servlet-api, jackson-datatype-joda,
There are maybe transitive dependencies!
Group au.com.dius
Version 3.5.24
Last update 04. November 2018
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 13
Dependencies kotlin-stdlib-jdk8, kotlin-reflect, slf4j-api, groovy-all, kotlin-logging, scala-library, scala-logging_2.11, pact-jvm-provider-junit_2.11, spring-boot-starter-test, spring-web, spring-webmvc, javax.servlet-api, jackson-datatype-joda,
There are maybe transitive dependencies!
pact-jvm-server_2.11 from group au.com.dius (version 3.5.17)
Pact server
===========
The pact server is a stand-alone interactions recorder and verifier, aimed at clients that are non-JVM or non-Ruby based.
The pact client for that platform will need to be implemented, but it only be responsible for generating the `JSON`
interactions, running the tests and communicating with the server.
The server implements a `JSON` `REST` Admin API with the following endpoints.
/ -> For diagnostics, currently returns a list of ports of the running mock servers.
/create -> For initialising a test server and submitting the JSON interactions. It returns a port
/complete -> For finalising and verifying the interactions with the server. It writes the `JSON` pact file to disk.
## Running the server
### Versions 2.2.6+
Pact server takes the following parameters:
```
Usage: pact-jvm-server [options] [port]
port
port to run on (defaults to 29999)
--help
prints this usage text
-h <value> | --host <value>
host to bind to (defaults to localhost)
-l <value> | --mock-port-lower <value>
lower bound to allocate mock ports (defaults to 20000)
-u <value> | --mock-port-upper <value>
upper bound to allocate mock ports (defaults to 40000)
-d | --daemon
run as a daemon process
-v <value> | --pact-version <value>
pact version to generate for (2 or 3)
-k <value> | --keystore-path <value>
Path to keystore
-p <value> | --keystore-password <value>
Keystore password
-s <value> | --ssl-port <value>
Ssl port the mock server should run on. lower and upper bounds are ignored
--debug
run with debug logging
```
### Using trust store 3.4.0+
Trust store can be used. However, it is limited to a single port for the time being.
### Prior to version 2.2.6
Pact server takes one optional parameter, the port number to listen on. If not provided, it will listen on 29999.
It requires an active console to run.
### Using a distribution archive
You can download a [distribution from maven central](http://search.maven.org/remotecontent?filepath=au/com/dius/pact-jvm-server_2.11/2.2.4/).
There is both a ZIP and TAR archive. Unpack it to a directory of choice and then run the script in the bin directory.
### Building a distribution bundle
You can build an application bundle with gradle by running (for 2.11 version):
$ ./gradlew :pact-jvm-server_2.11:installdist
This will create an app bundle in `build/2.11/install/pact-jvm-server_2.11`. You can then execute it with:
$ java -jar pact-jvm-server/build/2.10/install/pact-jvm-server_2.11/lib/pact-jvm-server_2.11-3.2.11.jar
or with the generated bundle script file:
$ pact-jvm-server/build/2.11/install/pact-jvm-server_2.11/bin/pact-jvm-server_2.11
By default will run on port `29999` but a port number can be optionally supplied.
### Running it with docker
You can use a docker image to execute the mock server as a docker container.
$ docker run -d -p 8080:8080 -p 20000-20010:20000-20010 uglyog/pact-jvm-server
This will run the main server on port 8080, and each created mock server on ports 20000-20010. You can map the ports to
any you require.
## Life cycle
The following actions are expected to occur
* The client calls `/create` to initialise a server with the expected `JSON` interactions and state
* The admin server will start a mock server on a random port and return the port number in the response
* The client will execute its interaction tests against the mock server with the supplied port
* Once finished, the client will call `/complete' on the Admin API, posting the port number
* The pact server will verify the interactions and write the `JSON` `pact` file to disk under `/target`
* The mock server running on the supplied port will be shutdown.
## Endpoints
### /create
The client will need `POST` to `/create` the generated `JSON` interactions, also providing a state as a query parameter
and a path.
For example:
POST http://localhost:29999/create?state=NoUsers&path=/sub/ref/path '{ "provider": { "name": "Animal_Service"}, ... }'
This will create a new running mock service provider on a randomly generated port. The port will be returned in the
`201` response:
{ "port" : 34423 }
But you can also reference the path from `/sub/ref/path` using the server port. The service will not strip
the prefix path, but instead will use it as a differentiator. If your services do not have differences
in the prefix of their path, then you will have to use the port method.
### /complete
Once the client has finished running its tests against the mock server on the supplied port (in this example port
`34423`) the client will need to `POST` to `/complete` the port number of the mock server that was used.
For example:
POST http://localhost:29999/complete '{ "port" : 34423 }'
This will cause the Pact server to verify the interactions, shutdown the mock server running on that port and writing
the pact `JSON` file to disk under the `target` directory.
### /
The `/` endpoint is for diagnostics and to check that the pact server is running. It will return all the currently
running mock servers port numbers.
For example:
GET http://localhost:29999/
'{ "ports": [23443,43232] }'
1 downloads
Artifact pact-jvm-server_2.11
Group au.com.dius
Version 3.5.17
Last update 03. June 2018
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 11
Dependencies kotlin-stdlib-jre8, kotlin-reflect, slf4j-api, groovy-all, kotlin-logging, scala-library, scala-logging_2.11, pact-jvm-consumer_2.11, logback-core, logback-classic, scopt_2.11,
There are maybe transitive dependencies!
Group au.com.dius
Version 3.5.17
Last update 03. June 2018
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 11
Dependencies kotlin-stdlib-jre8, kotlin-reflect, slf4j-api, groovy-all, kotlin-logging, scala-library, scala-logging_2.11, pact-jvm-consumer_2.11, logback-core, logback-classic, scopt_2.11,
There are maybe transitive dependencies!
pact-jvm-server_2.10 from group au.com.dius (version 2.4.20)
Pact server
===========
The pact server is a stand-alone interactions recorder and verifier, aimed at clients that are non-JVM or non-Ruby based.
The pact client for that platform will need to be implemented, but it only be responsible for generating the `JSON`
interactions, running the tests and communicating with the server.
The server implements a `JSON` `REST` Admin API with the following endpoints.
/ -> For diagnostics, currently returns a list of ports of the running mock servers.
/create -> For initialising a test server and submitting the JSON interactions. It returns a port
/complete -> For finalising and verifying the interactions with the server. It writes the `JSON` pact file to disk.
## Running the server
### Versions 2.2.6+
Pact server takes the following parameters:
```
Usage: pact-jvm-server [options] [port]
port
port to run on (defaults to 29999)
--help
prints this usage text
-h <value> | --host <value>
host to bind to (defaults to localhost)
-l <value> | --mock-port-lower <value>
lower bound to allocate mock ports (defaults to 20000)
-u <value> | --mock-port-upper <value>
upper bound to allocate mock ports (defaults to 40000)
-d | --daemon
run as a daemon process
--debug
run with debug logging
```
### Prior to version 2.2.6
Pact server takes one optional parameter, the port number to listen on. If not provided, it will listen on 29999.
It requires an active console to run.
### Using a distribution archive
You can download a [distribution from maven central](http://search.maven.org/remotecontent?filepath=au/com/dius/pact-jvm-server_2.11/2.2.4/).
There is both a ZIP and TAR archive. Unpack it to a directory of choice and then run the script in the bin directory.
### Building a distribution bundle
You can build an application bundle with gradle by running (for 2.11 version):
$ ./gradlew :pact-jvm-server_2.11:installdist
This will create an app bundle in `build/2.11/install/pact-jvm-server_2.11`. You can then execute it with:
$ java -jar pact-jvm-server/build/2.10/install/pact-jvm-server_2.11/lib/pact-jvm-server_2.11-2.2.4.jar
or with the generated bundle script file:
$ pact-jvm-server/build/2.11/install/pact-jvm-server_2.11/bin/pact-jvm-server_2.11
By default will run on port `29999` but a port number can be optionally supplied.
### Running it with docker
You can use a docker image to execute the mock server as a docker container.
$ docker run -d -p 8080:8080 -p 20000-20010:20000-20010 uglyog/pact-jvm-server
This will run the main server on port 8080, and each created mock server on ports 20000-20010. You can map the ports to
any you require.
## Life cycle
The following actions are expected to occur
* The client calls `/create` to initialise a server with the expected `JSON` interactions and state
* The admin server will start a mock server on a random port and return the port number in the response
* The client will execute its interaction tests against the mock server with the supplied port
* Once finished, the client will call `/complete' on the Admin API, posting the port number
* The pact server will verify the interactions and write the `JSON` `pact` file to disk under `/target`
* The mock server running on the supplied port will be shutdown.
## Endpoints
### /create
The client will need `POST` to `/create` the generated `JSON` interactions, also providing a state as a query parameter.
For example:
POST http://localhost:29999/create?state=NoUsers '{ "provider": { "name": "Animal_Service"}, ... }'
This will create a new running mock service provider on a randomly generated port. The port will be returned in the
`201` response:
{ "port" : 34423 }
### /complete
Once the client has finished running its tests against the mock server on the supplied port (in this example port
`34423`) the client will need to `POST` to `/complete` the port number of the mock server that was used.
For example:
POST http://localhost:29999/complete '{ "port" : 34423 }'
This will cause the Pact server to verify the interactions, shutdown the mock server running on that port and writing
the pact `JSON` file to disk under the `target` directory.
### /
The `/` endpoint is for diagnostics and to check that the pact server is running. It will return all the currently
running mock servers port numbers.
For example:
GET http://localhost:29999/
'{ "ports": [23443,43232] }'
0 downloads
Artifact pact-jvm-server_2.10
Group au.com.dius
Version 2.4.20
Last update 14. April 2018
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 6
Dependencies slf4j-api, scala-library, pact-jvm-consumer_2.10, logback-core, logback-classic, scopt_2.10,
There are maybe transitive dependencies!
Group au.com.dius
Version 2.4.20
Last update 14. April 2018
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 6
Dependencies slf4j-api, scala-library, pact-jvm-consumer_2.10, logback-core, logback-classic, scopt_2.10,
There are maybe transitive dependencies!
pact-jvm-provider-lein_2.12 from group au.com.dius (version 3.6.15)
# Leiningen plugin to verify a provider [version 2.2.14+, 3.0.3+]
Leiningen plugin for verifying pacts against a provider. The plugin provides a `pact-verify` task which will verify all
configured pacts against your provider.
## To Use It
### 1. Add the plugin to your project plugins, preferably in it's own profile.
```clojure
:profiles {
:pact {
:plugins [[au.com.dius/pact-jvm-provider-lein_2.11 "3.2.11" :exclusions [commons-logging]]]
:dependencies [[ch.qos.logback/logback-core "1.1.3"]
[ch.qos.logback/logback-classic "1.1.3"]
[org.apache.httpcomponents/httpclient "4.4.1"]]
}}}
```
### 2. Define the pacts between your consumers and providers
You define all the providers and consumers within the `:pact` configuration element of your project.
```clojure
:pact {
:service-providers {
; You can define as many as you need, but each must have a unique name
:provider1 {
; All the provider properties are optional, and have sensible defaults (shown below)
:protocol "http"
:host "localhost"
:port 8080
:path "/"
:has-pact-with {
; Again, you can define as many consumers for each provider as you need, but each must have a unique name
:consumer1 {
; pact file can be either a path or an URL
:pact-file "path/to/provider1-consumer1-pact.json"
}
}
}
}
}
```
### 3. Execute `lein with-profile pact pact-verify`
You will have to have your provider running for this to pass.
## Enabling insecure SSL
For providers that are running on SSL with self-signed certificates, you need to enable insecure SSL mode by setting
`:insecure true` on the provider.
```clojure
:pact {
:service-providers {
:provider1 {
:protocol "https"
:host "localhost"
:port 8443
:insecure true
:has-pact-with {
:consumer1 {
:pact-file "path/to/provider1-consumer1-pact.json"
}
}
}
}
}
```
## Specifying a custom trust store
For environments that are running their own certificate chains:
```clojure
:pact {
:service-providers {
:provider1 {
:protocol "https"
:host "localhost"
:port 8443
:trust-store "relative/path/to/trustStore.jks"
:trust-store-password "changeme"
:has-pact-with {
:consumer1 {
:pact-file "path/to/provider1-consumer1-pact.json"
}
}
}
}
}
```
`:trust-store` is relative to the current working (build) directory. `:trust-store-password` defaults to `changeit`.
NOTE: The hostname will still be verified against the certificate.
## Modifying the requests before they are sent
Sometimes you may need to add things to the requests that can't be persisted in a pact file. Examples of these would
be authentication tokens, which have a small life span. The Leiningen plugin provides a request filter that can be
set to an anonymous function on the provider that will be called before the request is made. This function will receive the HttpRequest
object as a parameter.
```clojure
:pact {
:service-providers {
:provider1 {
; function that adds an Authorization header to each request
:request-filter #(.addHeader % "Authorization" "oauth-token eyJhbGciOiJSUzI1NiIsIm...")
:has-pact-with {
:consumer1 {
:pact-file "path/to/provider1-consumer1-pact.json"
}
}
}
}
}
```
__*Important Note:*__ You should only use this feature for things that can not be persisted in the pact file. By modifying
the request, you are potentially modifying the contract from the consumer tests!
## Modifying the HTTP Client Used
The default HTTP client is used for all requests to providers (created with a call to `HttpClients.createDefault()`).
This can be changed by specifying a function assigned to `:create-client` on the provider that returns a `CloseableHttpClient`.
The function will receive the provider info as a parameter.
## Turning off URL decoding of the paths in the pact file [version 3.3.3+]
By default the paths loaded from the pact file will be decoded before the request is sent to the provider. To turn this
behaviour off, set the system property `pact.verifier.disableUrlPathDecoding` to `true`.
__*Important Note:*__ If you turn off the url path decoding, you need to ensure that the paths in the pact files are
correctly encoded. The verifier will not be able to make a request with an invalid encoded path.
## Plugin Properties
The following plugin options can be specified on the command line:
|Property|Description|
|--------|-----------|
|:pact.showStacktrace|This turns on stacktrace printing for each request. It can help with diagnosing network errors|
|:pact.showFullDiff|This turns on displaying the full diff of the expected versus actual bodies [version 3.3.6+]|
|:pact.filter.consumers|Comma seperated list of consumer names to verify|
|:pact.filter.description|Only verify interactions whose description match the provided regular expression|
|:pact.filter.providerState|Only verify interactions whose provider state match the provided regular expression. An empty string matches interactions that have no state|
|:pact.verifier.publishResults|Publishing of verification results will be skipped unless this property is set to 'true' [version 3.5.18+]|
|:pact.matching.wildcard|Enables matching of map values ignoring the keys when this property is set to 'true'|
Example, to run verification only for a particular consumer:
```
$ lein with-profile pact pact-verify :pact.filter.consumers=:consumer2
```
## Provider States
For each provider you can specify a state change URL to use to switch the state of the provider. This URL will
receive the `providerState` description from the pact file before each interaction via a POST. The `:state-change-uses-body`
controls if the state is passed in the request body or as a query parameter.
These values can be set at the provider level, or for a specific consumer. Consumer values take precedent if both are given.
```clojure
:pact {
:service-providers {
:provider1 {
:state-change-url "http://localhost:8080/tasks/pactStateChange"
:state-change-uses-body false ; defaults to true
:has-pact-with {
:consumer1 {
:pact-file "path/to/provider1-consumer1-pact.json"
}
}
}
}
}
```
If the `:state-change-uses-body` is not specified, or is set to true, then the provider state description will be sent as
JSON in the body of the request. If it is set to false, it will passed as a query parameter.
As for normal requests (see Modifying the requests before they are sent), a state change request can be modified before
it is sent. Set `:state-change-request-filter` to an anonymous function on the provider that will be called before the request is made.
#### Returning values that can be injected (3.6.11+)
You can have values from the provider state callbacks be injected into most places (paths, query parameters, headers,
bodies, etc.). This works by using the V3 spec generators with provider state callbacks that return values. One example
of where this would be useful is API calls that require an ID which would be auto-generated by the database on the
provider side, so there is no way to know what the ID would be beforehand.
There are methods on the consumer DSLs that can provider an expression that contains variables (like '/api/user/${id}'
for the path). The provider state callback can then return a map for values, and the `id` attribute from the map will
be expanded in the expression. For URL callbacks, the values need to be returned as JSON in the response body.
## Filtering the interactions that are verified
You can filter the interactions that are run using three properties: `:pact.filter.consumers`, `:pact.filter.description` and `:pact.filter.providerState`.
Adding `:pact.filter.consumers=:consumer1,:consumer2` to the command line will only run the pact files for those
consumers (consumer1 and consumer2). Adding `:pact.filter.description=a request for payment.*` will only run those interactions
whose descriptions start with 'a request for payment'. `:pact.filter.providerState=.*payment` will match any interaction that
has a provider state that ends with payment, and `:pact.filter.providerState=` will match any interaction that does not have a
provider state.
## Starting and shutting down your provider
For the pact verification to run, the provider needs to be running. Leiningen provides a `do` task that can chain tasks
together. So, by creating a `start-app` and `terminate-app` alias, you could so something like:
$ lein with-profile pact do start-app, pact-verify, terminate-app
However, if the pact verification fails the build will abort without running the `terminate-app` task. To have the
start and terminate tasks always run regardless of the state of the verification, you can assign them to `:start-provider-task`
and `:terminate-provider-task` on the provider.
```clojure
:aliases {"start-app" ^{:doc "Starts the app"}
["tasks to start app ..."] ; insert tasks to start the app here
"terminate-app" ^{:doc "Kills the app"}
["tasks to terminate app ..."] ; insert tasks to stop the app here
}
:pact {
:service-providers {
:provider1 {
:start-provider-task "start-app"
:terminate-provider-task "terminate-app"
:has-pact-with {
:consumer1 {
:pact-file "path/to/provider1-consumer1-pact.json"
}
}
}
}
}
```
Then you can just run:
$ lein with-profile pact pact-verify
and the `start-app` and `terminate-app` tasks will run before and after the provider verification.
## Specifying the provider hostname at runtime [3.0.4+]
If you need to calculate the provider hostname at runtime (for instance it is run as a new docker container or
AWS instance), you can give an anonymous function as the provider host that returns the host name. The function
will receive the provider information as a parameter.
```clojure
:pact {
:service-providers {
:provider1 {
:host #(calculate-host-name %)
:has-pact-with {
:consumer1 {
:pact-file "path/to/provider1-consumer1-pact.json"
}
}
}
}
}
```
Group: au.com.dius Artifact: pact-jvm-provider-lein_2.12
Show all versions Show documentation Show source
Show all versions Show documentation Show source
0 downloads
Artifact pact-jvm-provider-lein_2.12
Group au.com.dius
Version 3.6.15
Last update 29. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 8
Dependencies pact-jvm-provider_2.12, clojure, core.match, leiningen-core, logback-core, logback-classic, httpclient, jansi,
There are maybe transitive dependencies!
Group au.com.dius
Version 3.6.15
Last update 29. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 8
Dependencies pact-jvm-provider_2.12, clojure, core.match, leiningen-core, logback-core, logback-classic, httpclient, jansi,
There are maybe transitive dependencies!
pact-jvm-provider-spring from group au.com.dius (version 4.0.10)
# Pact Spring/JUnit runner
## Overview
Library provides ability to play contract tests against a provider using Spring & JUnit.
This library is based on and references the JUnit package, so see the [Pact JUnit 4](../pact-jvm-provider-junit) or [Pact JUnit 5](../pact-jvm-provider-junit5) providers for more details regarding configuration using JUnit.
Supports:
- Standard ways to load pacts from folders and broker
- Easy way to change assertion strategy
- Spring Test MockMVC Controllers and ControllerAdvice using MockMvc standalone setup.
- MockMvc debugger output
- Multiple @State runs to test a particular Provider State multiple times
- **au.com.dius.pact.provider.junit.State** custom annotation - before each interaction that requires a state change,
all methods annotated by `@State` with appropriate the state listed will be invoked.
**NOTE:** For publishing provider verification results to a pact broker, make sure the Java system property `pact.provider.version`
is set with the version of your provider.
## Example of MockMvc test
```java
@RunWith(RestPactRunner.class) // Custom pact runner, child of PactRunner which runs only REST tests
@Provider("myAwesomeService") // Set up name of tested provider
@PactFolder("pacts") // Point where to find pacts (See also section Pacts source in documentation)
public class ContractTest {
//Create an instance of your controller. We cannot autowire this as we're not using (and don't want to use) a Spring test runner.
@InjectMocks
private AwesomeController awesomeController = new AwesomeController();
//Mock your service logic class. We'll use this to create scenarios for respective provider states.
@Mock
private AwesomeBusinessLogic awesomeBusinessLogic;
//Create an instance of your controller advice (if you have one). This will be passed to the MockMvcTarget constructor to be wired up with MockMvc.
@InjectMocks
private AwesomeControllerAdvice awesomeControllerAdvice = new AwesomeControllerAdvice();
//Create a new instance of the MockMvcTarget and annotate it as the TestTarget for PactRunner
@TestTarget
public final MockMvcTarget target = new MockMvcTarget();
@Before //Method will be run before each test of interaction
public void before() {
//initialize your mocks using your mocking framework
MockitoAnnotations.initMocks(this);
//configure the MockMvcTarget with your controller and controller advice
target.setControllers(awesomeController);
target.setControllerAdvice(awesomeControllerAdvice);
}
@State("default", "no-data") // Method will be run before testing interactions that require "default" or "no-data" state
public void toDefaultState() {
target.setRunTimes(3); //let's loop through this state a few times for a 3 data variants
when(awesomeBusinessLogic.getById(any(UUID.class)))
.thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.ONE))
.thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.TWO))
.thenReturn(myTestHelper.generateRandomReturnData(UUID.randomUUID(), ExampleEnum.THREE));
}
@State("error-case")
public void SingleUploadExistsState_Success() {
target.setRunTimes(1); //tell the runner to only loop one time for this state
//you might want to throw exceptions to be picked off by your controller advice
when(awesomeBusinessLogic.getById(any(UUID.class)))
.then(i -> { throw new NotCoolException(i.getArgumentAt(0, UUID.class).toString()); });
}
}
```
## Using Spring runners
You can use `SpringRestPactRunner` or `SpringMessagePactRunner` instead of the default Pact runner to use the Spring test annotations. This will
allow you to inject or mock spring beans. `SpringRestPactRunner` is for restful webapps and `SpringMessagePactRunner` is
for async message tests.
For example:
```java
@RunWith(SpringRestPactRunner.class)
@Provider("pricing")
@PactBroker(protocol = "https", host = "${pactBrokerHost}", port = "443",
authentication = @PactBrokerAuth(username = "${pactBrokerUser}", password = "${pactBrokerPassword}"))
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class PricingServiceProviderPactTest {
@MockBean
private ProductClient productClient; // This will replace the bean with a mock in the application context
@TestTarget
@SuppressWarnings(value = "VisibilityModifier")
public final Target target = new HttpTarget(8091);
@State("Product X010000021 exists")
public void setupProductX010000021() throws IOException {
reset(productClient);
ProductBuilder product = new ProductBuilder()
.withProductCode("X010000021");
when(productClient.fetch((Set<String>) argThat(contains("X010000021")), any())).thenReturn(product);
}
@State("the product code X00001 can be priced")
public void theProductCodeX00001CanBePriced() throws IOException {
reset(productClient);
ProductBuilder product = new ProductBuilder()
.withProductCode("X00001");
when(productClient.find((Set<String>) argThat(contains("X00001")), any())).thenReturn(product);
}
}
```
### Using Spring Context Properties
The SpringRestPactRunner will look up any annotation expressions (like `${pactBrokerHost}`)
above) from the Spring context. For Springboot, this will allow you to define the properties in the application test properties.
For instance, if you create the following `application.yml` in the test resources:
```yaml
pactbroker:
host: "your.broker.local"
port: "443"
protocol: "https"
auth:
username: "<your broker username>"
password: "<your broker password>"
```
Then you can use the defaults on the `@PactBroker` annotation.
```java
@RunWith(SpringRestPactRunner.class)
@Provider("My Service")
@PactBroker(
authentication = @PactBrokerAuth(username = "${pactbroker.auth.username}", password = "${pactbroker.auth.password}")
)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PactVerificationTest {
```
### Using a random port with a Springboot test
If you use a random port in a springboot test (by setting `SpringBootTest.WebEnvironment.RANDOM_PORT`), you need to set it to the `TestTarget`. How this works is different for JUnit4 and JUnit5.
#### JUnit4
You can use the
`SpringBootHttpTarget` which will get the application port from the spring application context.
For example:
```java
@RunWith(SpringRestPactRunner.class)
@Provider("My Service")
@PactBroker
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PactVerificationTest {
@TestTarget
public final Target target = new SpringBootHttpTarget();
}
```
#### JUnit5
You actually don't need to dependend on `pact-jvm-provider-spring` for this. It's sufficient to depend on `pact-jvm-provider-junit5`.
You can set the port to the `HttpTestTarget` object in the before method.
```java
@Provider("My Service")
@PactBroker
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class PactVerificationTest {
@LocalServerPort
private int port;
@BeforeEach
void before(PactVerificationContext context) {
context.setTarget(new HttpTestTarget("localhost", port));
}
}
```
Group: au.com.dius Artifact: pact-jvm-provider-spring
Show all versions Show documentation Show source
Show all versions Show documentation Show source
0 downloads
Artifact pact-jvm-provider-spring
Group au.com.dius
Version 4.0.10
Last update 18. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 5
Dependencies spring-boot-starter-test, spring-webmvc, javax.servlet-api, jackson-datatype-joda, pact-jvm-provider-junit,
There are maybe transitive dependencies!
Group au.com.dius
Version 4.0.10
Last update 18. April 2020
Organization not specified
URL https://github.com/DiUS/pact-jvm
License Apache 2
Dependencies amount 5
Dependencies spring-boot-starter-test, spring-webmvc, javax.servlet-api, jackson-datatype-joda, pact-jvm-provider-junit,
There are maybe transitive dependencies!
Page 14 from 3 (items total 159)