Skip to content

Commit

Permalink
Update to use pact-broker
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneLimburg committed Nov 8, 2024
1 parent 61d6fb7 commit 2d9c7b1
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 28 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ jobs:
distribution: 'temurin'
cache: maven

- name: Build with Docker
run: docker compose build

- name: Start with Docker
run: docker compose up -d

- name: Build customer-service
run: mvn clean package -f customer-service/pom.xml -Dservice.name=customer-service
run: mvn clean package -f customer-service/pom.xml -Dservice.name=customer-service pact:publish

- name: Build billing-service
run: mvn clean package -f billing-service/pom.xml -Dservice.name=billing-service
Expand All @@ -28,11 +34,5 @@ jobs:
- name: Build address-validation-service
run: mvn clean package -f address-validation-service/pom.xml -Dservice.name=address-validation-service

- name: Build with Docker
run: docker compose build

- name: Start with Docker
run: docker compose up -d

- name: Stop Docker Containers
run: docker compose down
2 changes: 1 addition & 1 deletion address-validation-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipeline {
}
}
steps {
sh "mvn test -B"
sh "mvn test -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B"
}
}
stage ('Package') {
Expand Down
4 changes: 2 additions & 2 deletions address-validation-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<version>1.0.0-SNAPSHOT</version>

<scm>
<connection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/address-validation-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/address-validation-service.git</developerConnection>
<connection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/address-validation-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/address-validation-service.git</developerConnection>
</scm>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package de.openknowledge.sample.address;

import static java.util.Optional.ofNullable;

import org.apache.meecrowave.Meecrowave;
import org.apache.meecrowave.junit5.MonoMeecrowaveConfig;
import org.apache.meecrowave.testing.ConfigurationInject;
Expand All @@ -25,27 +27,30 @@
import au.com.dius.pact.provider.junit5.HttpTestTarget;
import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.State;
import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;

@IgnoreNoPactsToVerify
@Provider("address-validation-service")
@PactFolder("src/test/pacts")
@PactBroker(url = "${pactBroker.url:http://localhost:5000}")
@MonoMeecrowaveConfig
public class AddressValidationServiceTest {

@ConfigurationInject
private Meecrowave.Builder config;

@BeforeEach
public void setUp(PactVerificationContext context) {
context.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/"));
public void setUp(PactVerificationContext verificationContext) {
ofNullable(verificationContext)
.ifPresent(context -> context.setTarget(new HttpTestTarget("localhost", config.getHttpPort(), "/")));
}

@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactVerificationTestTemplate(PactVerificationContext context) {
context.verifyInteraction();
ofNullable(context).ifPresent(PactVerificationContext::verifyInteraction);
}

@State("Three customers")
Expand Down
2 changes: 1 addition & 1 deletion billing-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipeline {
}
}
steps {
sh "mvn test -B"
sh "mvn test -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B"
}
}
stage ('Package') {
Expand Down
4 changes: 2 additions & 2 deletions billing-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<version>1.0.0-SNAPSHOT</version>

<scm>
<connection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/billing-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/billing-service.git</developerConnection>
<connection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/billing-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/billing-service.git</developerConnection>
</scm>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import au.com.dius.pact.provider.junit5.HttpTestTarget;
import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.State;
import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;

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

Expand Down
2 changes: 1 addition & 1 deletion customer-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipeline {
}
}
steps {
sh "mvn test -B"
sh 'mvn test pact:publish -DpactBroker.url=http://pact-service:8080 -B'
}
}
stage ('Package') {
Expand Down
13 changes: 11 additions & 2 deletions customer-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<version>1.0.0-SNAPSHOT</version>

<scm>
<connection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/customer-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs-service:3000/openknowledge/customer-service.git</developerConnection>
<connection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/customer-service.git</connection>
<developerConnection>scm:git:http://openknowledge:workshop@gogs:3000/openknowledge/customer-service.git</developerConnection>
</scm>

<properties>
Expand All @@ -26,6 +26,7 @@
<maven.compiler.target>11</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pactBroker.url>http://localhost:5000</pactBroker.url>
<meecrowave.version>1.2.15</meecrowave.version>
<deltaspike.version>1.9.6</deltaspike.version>
<junit.version>5.8.2</junit.version>
Expand Down Expand Up @@ -179,6 +180,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>au.com.dius.pact.provider</groupId>
<artifactId>maven</artifactId>
<version>4.3.5</version>
<configuration>
<pactBrokerUrl>${pactBroker.url}</pactBrokerUrl>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void initializeRepository(MockServer mockServer) {

@PactTestFor(pactMethod = "getMax")
@Test
public void findDeliveryAddressForExistingCustomer() {
public void findBillingAddressForExistingCustomer() {
Optional<Address> address = repository.find(new CustomerNumber("0815"));
assertThat(address).isPresent().contains(
new Address(
Expand Down
2 changes: 1 addition & 1 deletion delivery-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pipeline {
}
}
steps {
sh "mvn test -B"
sh "mvn test pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -B"
}
}
stage ('Package') {
Expand Down
4 changes: 3 additions & 1 deletion delivery-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<maven.compiler.target>11</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pactBroker.url>http://localhost:5000</pactBroker.url>
<meecrowave.version>1.2.15</meecrowave.version>
<deltaspike.version>1.9.6</deltaspike.version>
<hibernate.version>5.4.21.Final</hibernate.version>
Expand Down Expand Up @@ -182,6 +183,7 @@
<configuration>
<systemPropertyVariables>
<pact.provider.version>${project.version}</pact.provider.version>
<pactBroker.url>${pactBroker.url}</pactBroker.url>
<javax.persistence.jdbc.url>jdbc:h2:mem:delivery</javax.persistence.jdbc.url>
<javax.persistence.jdbc.driver>org.h2.Driver</javax.persistence.jdbc.driver>
<javax.persistence.jdbc.user>sa</javax.persistence.jdbc.user>
Expand Down Expand Up @@ -222,7 +224,7 @@
<artifactId>maven</artifactId>
<version>4.3.5</version>
<configuration>
<pactBrokerUrl>http://localhost</pactBrokerUrl>
<pactBrokerUrl>${pactBroker.url}</pactBrokerUrl>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@
import au.com.dius.pact.provider.junit5.HttpTestTarget;
import au.com.dius.pact.provider.junit5.PactVerificationContext;
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider;
import au.com.dius.pact.provider.junitsupport.IgnoreNoPactsToVerify;
import au.com.dius.pact.provider.junitsupport.Provider;
import au.com.dius.pact.provider.junitsupport.State;
import au.com.dius.pact.provider.junitsupport.StateChangeAction;
import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
import au.com.dius.pact.provider.junitsupport.loader.PactBroker;
import de.openknowledge.sample.address.domain.AddressValidationService;
import rocks.limburg.cdimock.MockitoBeans;

@IgnoreNoPactsToVerify
@MockitoBeans(types = {AddressValidationService.class})
@Provider("delivery-service")
@PactFolder("src/test/pacts")
@PactBroker(url = "${pactBroker.url:http://localhost:5000}")
@MonoMeecrowaveConfig
public class DeliveryAddressServiceTest {

Expand Down

0 comments on commit 2d9c7b1

Please sign in to comment.