Development Tools

pact-jvm-provider-junit5-spring

au.com.dius : pact-jvm-provider-junit5-spring

# Pact Spring/JUnit5 Support This module extends the base [Pact JUnit5 module](../pact-jvm-provider-junit5). See that for more details. For writing Spring Pact verification tests with JUnit 5, there is an JUnit 5 Invocation Context Provider that you can use with the `@TestTemplate` annotation. This will generate a test for each interaction found for the pact files for the provider. To use it, add the `@Provider` and `@ExtendWith(SpringExtension.class)` and one of the pact source annotations to your test class (as per a JUnit 5 test), then add a method annotated with `@TestTemplate` and `@ExtendWith(PactVerificationSpringProvider.class)` that takes a `PactVerificationContext` parameter. You will need to call `verifyInteraction()` on the context parameter in your test template method. For example: ```java @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @Provider("Animal Profile Service") @PactBroker public class ContractVerificationTest { @TestTemplate @ExtendWith(PactVerificationSpringProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } } ``` You will now be able to setup all the required properties using the Spring context, e.g. creating an application YAML file in the test resources: ```yaml pactbroker: host: your.broker.host auth: username: broker-user password: broker.password ``` You can also run pact tests against `MockMvc` without need to spin up the whole application context which takes time and often requires more additional setup (e.g. database). In order to run lightweight tests just use `@WebMvcTest` from Spring and `MockMvcTestTarget` as a test target before each test. For example: ```java @WebMvcTest @Provider("myAwesomeService") @PactBroker class ContractVerificationTest { @Autowired private MockMvc mockMvc; @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @BeforeEach void before(PactVerificationContext context) { context.setTarget(new MockMvcTestTarget(mockMvc)); } } ``` You can also use `MockMvcTestTarget` for tests without spring context by providing the controllers manually. For example: ```java @Provider("myAwesomeService") @PactFolder("pacts") class MockMvcTestTargetStandaloneMockMvcTestJava { @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); } @BeforeEach void before(PactVerificationContext context) { MockMvcTestTarget testTarget = new MockMvcTestTarget(); testTarget.setControllers(new DataResource()); context.setTarget(testTarget); } @RestController static class DataResource { @GetMapping("/data") @ResponseStatus(HttpStatus.NO_CONTENT) void getData(@RequestParam("ticketId") String ticketId) { } } } ``` **Important:** Since `@WebMvcTest` starts only Spring MVC components you can't use `PactVerificationSpringProvider` and need to fallback to `PactVerificationInvocationContextProvider`

Last Version: 4.0.10

Release Date:

Last Version: 1.0.0

Release Date:

WSO2 Carbon - Permission Provider - Feature Aggregator Module

org.wso2.carbon.analytics-common : permission-provider-feature

WSO2 is an open source application development software company focused on providing service-oriented architecture solutions for professional developers.

Last Version: 6.1.57

Release Date:

identity-api-client

com.sflpro.identity : identity-api-client

Identity is a micro-service designed to help you organize authentication and authorization in your application

Last Version: 0.4.5

Release Date:

pact-jvm-provider-spring

au.com.dius : pact-jvm-provider-spring

# 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)); } } ```

Last Version: 4.0.10

Release Date:

Last Version: 4.1.1

Release Date:

WSO2 Carbon - Facebook Application Autenticator Feature Aggregator Module

org.wso2.carbon.identity : facebook-application-authenticator-feature

WSO2 is an open source application development software company focused on providing service-oriented architecture solutions for professional developers.

Last Version: 4.5.2

Release Date:

WSO2 Carbon - Identity Authorization Feature Aggregator Module

org.wso2.carbon.identity : identity-authorization-feature

WSO2 is an open source application development software company focused on providing service-oriented architecture solutions for professional developers.

Last Version: 4.4.1

Release Date:

identifier-generators

tz.co.asoft : identifier-generators-watchosarm32

An multiplatform representation of a Live<T> object

Last Version: 0.2.42

Release Date:

Last Version: 0.1.8

Release Date:

Last Version: 1.5.0

Release Date:

Maven 1.0.2 library for Mevenide

mevenide : maven-nb-module

Library for project mevenide, contains most of the jars needed for maven to run.

Last Version: 1.0.2

Release Date:

Opencast :: videogrid-workflowoperation

org.opencastproject : opencast-videogrid-workflowoperation

Opencast is a media capture, processing, management and distribution system

Last Version: 12.0

Release Date:

tests

org.hesperides : tests

Hesperides, templated files generator

Last Version: 4.1.6

Release Date:

Last Version: 0.4.0

Release Date:

org.integratedmodelling.kim.ide

org.integratedmodelling : org.integratedmodelling.kim.ide

The core component of the k.LAB semantic modeling platform: the Java API, a common package providing a client, and the reference implementation of the semantic modeling engine.

Last Version: 0.9.10

Release Date:

Last Version: 3.2.2

Release Date:

micrboot-parent

com.zhuanglide : micrboot-parent

http server not follow J2EE using Netty

Last Version: 1.0.1

Release Date:

Last Version: 0.6.1

Release Date:

Opencast :: statistics-provider-random

org.opencastproject : opencast-statistics-provider-random

Opencast is a media capture, processing, management and distribution system

Last Version: 12.0

Release Date:

WSO2 Carbon - Authenticator Feature Aggregator Module

org.wso2.carbon.identity : carbon-authenticator-features

WSO2 is an open source application development software company focused on providing service-oriented architecture solutions for professional developers.

Last Version: 5.5.0-m4

Release Date:

Last Version: 4.4.0

Release Date:

Last Version: 1.0.663

Release Date:

TeaVM HTML5 video web application

org.teavm : teavm-samples-video

A sample application that shows HTML5 video implementation for TeaVM

Last Version: 0.4.3

Release Date:

Last Version: 0.1

Release Date:

Identity4J AS400

com.nervepoint : identity4j-as400

A suite of Java Identity and Authentication Connectors.

Last Version: 1.2.2

Release Date:

EAP Base Module org.jboss.resteasy.resteasy-jaxb-provider:main

org.kie.modules : org-jboss-resteasy-resteasy-jaxb-provider-main

The parent with dependencies imports the KIE Platform BOM and adds the default test-scoped dependencies. All modules extend this parent, except for the user-facing BOMs (which are used here).

Last Version: 6.5.0.Final

Release Date:

Last Version: 1.1.1

Release Date:

VM Testing APIs

org.apidesign.bck2brwsr : vmtest

Java.net - The Source for Java Technology Collaboration

Last Version: 0.54

Release Date:

ODL :: netide :: netide-features4

org.opendaylight.netide : netide-features4

OpenDaylight is leading the transformation to Open Software Defined Networking (SDN). For more information, please see https://www.opendaylight.org

Last Version: 0.3.4-Carbon

Release Date:

identifier-generators

tz.co.asoft : identifier-generators-watchosx64

An multiplatform representation of a Live<T> object

Last Version: 0.2.42

Release Date:

Last Version: 4.17.104.1

Release Date:

Deckard

de.idealo.kafka : deckard

A declarative approach to defining Spring Kafka producers.

Last Version: 1.0.4-RELEASE

Release Date:

Last Version: 1.6.0

Release Date:

identity-api-client-lib

com.gu.identity.api : identity-api-client-lib_2.12

Scala library for Identity crypto operations.

Last Version: 3.141

Release Date:

WSO2 Carbon Extension - Basecamp Pom

org.wso2.carbon.extension.identity.authenticator : org.wso2.carbon.extension.identity.authenticator.inwebo

WSO2 is an open source application development software company focused on providing service-oriented architecture solutions for professional developers.

Last Version: 1.0.1

Release Date:

Last Version: 1.0.0

Release Date:

Spring Cloud Stream Binder for AWS SQS

de.idealo.spring : spring-cloud-stream-binder-sqs

Allows you to use Spring Cloud Stream together with AWS SQS

Last Version: 1.7.1

Release Date:

Last Version: 0.2.13

Release Date:

Apache Wink Providers

org.apache.wink : wink-providers

The Apache Software Foundation provides support for the Apache community of open-source software projects. The Apache projects are characterized by a collaborative, consensus based development process, an open and pragmatic software license, and a desire to create high quality software that leads the way in its field. We consider ourselves not simply a group of projects sharing a server, but rather a community of developers and users.

Last Version: 1.4

Release Date:

GridGain JTA Module

org.gridgain : gridgain-urideploy

Java-based middleware for in-memory processing of big data in a distributed environment.

Last Version: 6.6.9-p1

Release Date:

identity-play-auth

com.gu.identity : identity-play-auth_2.12

A small client library for Guardian Identity authentication with the Play framework

Last Version: 2.6

Release Date:

Last Version: 5.4.0

Release Date:

Last Version: 0.0.2

Release Date: