Skip to content

Commit 7f5164a

Browse files
committed
Update to use pact-broker
1 parent f0e701c commit 7f5164a

11 files changed

Lines changed: 42 additions & 22 deletions

File tree

.github/workflows/build.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ jobs:
1616
distribution: 'temurin'
1717
cache: maven
1818

19+
- name: Build with Docker
20+
run: docker compose build
21+
22+
- name: Start with Docker
23+
run: docker compose up -d
24+
1925
- name: Build customer-service
20-
run: mvn clean package -f customer-service/pom.xml -Dservice.name=customer-service
26+
run: mvn clean package -f customer-service/pom.xml -Dservice.name=customer-service pact:publish
2127

2228
- name: Build billing-service
2329
run: mvn clean package -f billing-service/pom.xml -Dservice.name=billing-service
@@ -28,11 +34,5 @@ jobs:
2834
- name: Build address-validation-service
2935
run: mvn clean package -f address-validation-service/pom.xml -Dservice.name=address-validation-service
3036

31-
- name: Build with Docker
32-
run: docker compose build
33-
34-
- name: Start with Docker
35-
run: docker compose up -d
36-
3737
- name: Stop Docker Containers
3838
run: docker compose down

address-validation-service/Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pipeline {
4848
}
4949
}
5050
steps {
51-
sh "mvn test -B"
51+
sh "mvn test -DpactBroker.url=http://pact:9090 -Dpact.verifier.publishResults=true -B"
5252
}
5353
}
5454
stage ('Package') {

address-validation-service/src/test/java/de/openknowledge/sample/address/AddressValidationServiceTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package de.openknowledge.sample.address;
1717

18+
import static java.util.Optional.ofNullable;
19+
1820
import org.apache.meecrowave.Meecrowave;
1921
import org.apache.meecrowave.junit5.MonoMeecrowaveConfig;
2022
import org.apache.meecrowave.testing.ConfigurationInject;
@@ -25,27 +27,30 @@
2527
import au.com.dius.pact.provider.junit5.HttpTestTarget;
2628
import au.com.dius.pact.provider.junit5.PactVerificationContext;
2729
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
30+
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
2831
import au.com.dius.pact.provider.junitsupport.Provider;
2932
import au.com.dius.pact.provider.junitsupport.State;
30-
import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
33+
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;
3134

35+
@IgnoreNoPactsToVerify
3236
@Provider("address-validation-service")
33-
@PactFolder("src/test/pacts")
37+
@PactBroker(url = "${pactBroker.url:http://localhost:5000}")
3438
@MonoMeecrowaveConfig
3539
public class AddressValidationServiceTest {
3640

3741
@ConfigurationInject
3842
private Meecrowave.Builder config;
3943

4044
@BeforeEach
41-
public void setUp(PactVerificationContext context) {
42-
context.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/"));
45+
public void setUp(PactVerificationContext verificationContext) {
46+
ofNullable(verificationContext)
47+
.ifPresent(context -> context.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/")));
4348
}
4449

4550
@TestTemplate
4651
@ExtendWith(PactVerificationInvocationContextProvider.class)
4752
void pactVerificationTestTemplate(PactVerificationContext context) {
48-
context.verifyInteraction();
53+
ofNullable(context).ifPresent(PactVerificationContext::verifyInteraction);
4954
}
5055

5156
@State("Three customers")

billing-service/Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pipeline {
4848
}
4949
}
5050
steps {
51-
sh "mvn test -B"
51+
sh "mvn test -DpactBroker.url=http://pact:9090 -Dpact.verifier.publishResults=true -B"
5252
}
5353
}
5454
stage ('Package') {

billing-service/src/test/java/de/openknowledge/sample/address/BillingAddressServiceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
import au.com.dius.pact.provider.junit5.HttpTestTarget;
2626
import au.com.dius.pact.provider.junit5.PactVerificationContext;
2727
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
28+
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
2829
import au.com.dius.pact.provider.junitsupport.Provider;
2930
import au.com.dius.pact.provider.junitsupport.State;
30-
import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
31+
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;
3132

33+
@IgnoreNoPactsToVerify
3234
@Provider("billing-service")
33-
@PactFolder("src/test/pacts")
35+
@PactBroker(url = "${pactBroker.url:http://localhost:5000}")
3436
@MonoMeecrowaveConfig
3537
public class BillingAddressServiceTest {
3638

customer-service/Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pipeline {
4848
}
4949
}
5050
steps {
51-
sh "mvn test -B"
51+
sh 'mvn test pact:publish -DpactBroker.url=http://pact:9090 -B'
5252
}
5353
}
5454
stage ('Package') {

customer-service/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<maven.compiler.target>11</maven.compiler.target>
2727
<failOnMissingWebXml>false</failOnMissingWebXml>
2828
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29+
<pactBroker.url>http://localhost:5000</pactBroker.url>
2930
<meecrowave.version>1.2.15</meecrowave.version>
3031
<deltaspike.version>1.9.6</deltaspike.version>
3132
<junit.version>5.8.2</junit.version>
@@ -179,6 +180,14 @@
179180
</execution>
180181
</executions>
181182
</plugin>
183+
<plugin>
184+
<groupId>au.com.dius.pact.provider</groupId>
185+
<artifactId>maven</artifactId>
186+
<version>4.3.5</version>
187+
<configuration>
188+
<pactBrokerUrl>${pactBroker.url}</pactBrokerUrl>
189+
</configuration>
190+
</plugin>
182191
</plugins>
183192
</build>
184193
</project>

customer-service/src/test/java/de/openknowledge/sample/address/domain/BillingAddressRepositoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void initializeRepository(MockServer mockServer) {
103103

104104
@PactTestFor(pactMethod = "getMax")
105105
@Test
106-
public void findDeliveryAddressForExistingCustomer() {
106+
public void findBillingAddressForExistingCustomer() {
107107
Optional<Address> address = repository.find(new CustomerNumber("0815"));
108108
assertThat(address).isPresent().contains(
109109
new Address(

delivery-service/Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pipeline {
4848
}
4949
}
5050
steps {
51-
sh "mvn test -B"
51+
sh "mvn test pact:publish -DpactBroker.url=http://pact:9090 -Dpact.verifier.publishResults=true -B"
5252
}
5353
}
5454
stage ('Package') {

delivery-service/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<maven.compiler.target>11</maven.compiler.target>
2727
<failOnMissingWebXml>false</failOnMissingWebXml>
2828
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29+
<pactBroker.url>http://localhost:5000</pactBroker.url>
2930
<meecrowave.version>1.2.15</meecrowave.version>
3031
<deltaspike.version>1.9.6</deltaspike.version>
3132
<hibernate.version>5.4.21.Final</hibernate.version>
@@ -182,6 +183,7 @@
182183
<configuration>
183184
<systemPropertyVariables>
184185
<pact.provider.version>${project.version}</pact.provider.version>
186+
<pactBroker.url>${pactBroker.url}</pactBroker.url>
185187
<javax.persistence.jdbc.url>jdbc:h2:mem:delivery</javax.persistence.jdbc.url>
186188
<javax.persistence.jdbc.driver>org.h2.Driver</javax.persistence.jdbc.driver>
187189
<javax.persistence.jdbc.user>sa</javax.persistence.jdbc.user>
@@ -222,7 +224,7 @@
222224
<artifactId>maven</artifactId>
223225
<version>4.3.5</version>
224226
<configuration>
225-
<pactBrokerUrl>http://localhost</pactBrokerUrl>
227+
<pactBrokerUrl>${pactBroker.url}</pactBrokerUrl>
226228
</configuration>
227229
</plugin>
228230
</plugins>

0 commit comments

Comments
 (0)