Added a contract-test, that is implemented as a Spring intetration-test
authorKai Moritz <kai@juplo.de>
Sun, 22 May 2022 06:37:04 +0000 (08:37 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 3 Jun 2022 11:49:25 +0000 (13:49 +0200)
provider/build.gradle
provider/src/test/java/io/pactflow/example/sirenprovider/SirenProviderApplicationTests.java

index 7229334..b5e461b 100644 (file)
@@ -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 {
index b47da1d..1f5e96a 100644 (file)
@@ -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();
+  }
 }