Versions of artifact au.com.dius:pact-jvm-provider-spring_2.11

pact-jvm-provider-spring_2.11

# 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. ## 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 =

Artifact Version Name Latest uploaded at
3.5.7-jre7.0 pact-jvm-provider-spring_2.11 2017-10-03 05:55:24 UTC
3.5.7 pact-jvm-provider-spring_2.11 2017-10-03 00:51:50 UTC
3.5.6-jre7.0 pact-jvm-provider-spring_2.11 2017-09-28 05:20:30 UTC
3.5.6 pact-jvm-provider-spring_2.11 2017-09-27 02:19:29 UTC
3.5.5-jre7.0 pact-jvm-provider-spring_2.11 2017-09-14 02:41:18 UTC
3.5.5 pact-jvm-provider-spring_2.11 2017-09-11 23:16:08 UTC
3.5.4-jre7.0 pact-jvm-provider-spring_2.11 2017-08-19 08:02:44 UTC
3.5.4 pact-jvm-provider-spring_2.11 2017-08-18 05:41:14 UTC
3.5.3-jre7.0 pact-jvm-provider-spring_2.11 2017-08-10 00:34:07 UTC
3.5.3 pact-jvm-provider-spring_2.11 2017-08-06 08:02:48 UTC
3.5.2 pact-jvm-provider-spring_2.11 2017-07-12 01:15:04 UTC
3.5.2-jre7.0 pact-jvm-provider-spring_2.11 2017-07-12 00:40:52 UTC
3.5.1 pact-jvm-provider-spring_2.11 2017-07-09 08:21:07 UTC
3.5.1-jre7.1 pact-jvm-provider-spring_2.11 2017-07-09 06:59:59 UTC
3.5.0-jre7.1 pact-jvm-provider-spring_2.11 2017-06-24 13:20:19 UTC
3.5.0-jre7 pact-jvm-provider-spring_2.11 2017-06-24 11:30:31 UTC
3.5.0 pact-jvm-provider-spring_2.11 2017-06-24 08:15:12 UTC
3.5.0-rc.3 pact-jvm-provider-spring_2.11 2017-06-20 23:44:03 UTC
3.5.0-rc.2 pact-jvm-provider-spring_2.11 2017-06-11 07:17:05 UTC
3.4.1 pact-jvm-provider-spring_2.11 2017-06-11 02:06:57 UTC
3.5.0-rc.1 pact-jvm-provider-spring_2.11 2017-05-25 03:47:53 UTC
3.4.0 pact-jvm-provider-spring_2.11 2017-05-18 05:42:09 UTC