From 22ec4700f6d4519c71ab115e2d33fb053d00940f Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 22 May 2022 08:37:04 +0200 Subject: [PATCH] Added a contract-test, that is implemented as a Spring intetration-test --- provider/build.gradle | 5 ++-- .../SirenProviderApplicationTests.java | 24 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/provider/build.gradle b/provider/build.gradle index 7229334..b5e461b 100644 --- a/provider/build.gradle +++ b/provider/build.gradle @@ -3,7 +3,7 @@ plugins { id 'io.spring.dependency-management' version '1.0.10.RELEASE' id 'java' id "io.freefair.lombok" version "5.2.1" - id "au.com.dius.pact" version "4.2.0-beta.1" + id "au.com.dius.pact" version "4.2.2" id "com.wiredforcode.spawn" version "0.8.2" } @@ -19,11 +19,12 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-hateoas' implementation 'com.jayway.jsonpath:json-path' - implementation 'de.ingogriebsch.hateoas:spring-hateoas-siren:1.0.0-M2' + implementation 'de.ingogriebsch.hateoas:spring-hateoas-siren:1.0.0' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } + testImplementation 'au.com.dius.pact.provider:junit5spring:4.2.2' } test { diff --git a/provider/src/test/java/io/pactflow/example/sirenprovider/SirenProviderApplicationTests.java b/provider/src/test/java/io/pactflow/example/sirenprovider/SirenProviderApplicationTests.java index b47da1d..1f5e96a 100644 --- a/provider/src/test/java/io/pactflow/example/sirenprovider/SirenProviderApplicationTests.java +++ b/provider/src/test/java/io/pactflow/example/sirenprovider/SirenProviderApplicationTests.java @@ -1,13 +1,25 @@ package io.pactflow.example.sirenprovider; -import org.junit.jupiter.api.Test; +import au.com.dius.pact.provider.junit5.PactVerificationContext; +import au.com.dius.pact.provider.junitsupport.Provider; +import au.com.dius.pact.provider.junitsupport.loader.PactFolder; +import au.com.dius.pact.provider.spring.junit5.PactVerificationSpringProvider; +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest -class SirenProviderApplicationTests { +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; - @Test - void contextLoads() { - } +@SpringBootTest(webEnvironment = DEFINED_PORT) +@Provider("SirenOrderProvider") +@PactFolder("../spring-consumer/target/pacts") +class SirenProviderApplicationTests +{ + @TestTemplate + @ExtendWith(PactVerificationSpringProvider.class) + public void pactVerificationTestTemplate(PactVerificationContext context) + { + context.verifyInteraction(); + } } -- 2.20.1