-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/p-pact-contract-test' into p-pac…
…t-contract-test # Conflicts: # services/Promoter/src/test/java/com/bottega/promoter/concert/api/rest/ConcertRestController_discountConcert_restApiTest.java
- Loading branch information
Showing
24 changed files
with
742 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
name: LiveCoding Pricing CI | ||
run-name: LiveCoding Pricing CI | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'services/Pricing/**' | ||
- 'libs/SharedLib/**' | ||
- '.github/workflows/ci-pricing-liveCoding.yml' | ||
- '.github/workflows/ci-shared-lib.yml' | ||
workflow_dispatch: | ||
repository_dispatch: | ||
types: [pricing-ci-webhook] | ||
|
||
env: | ||
PACT_BROKER_BASE_URL: ${{ vars.PACT_BROKER_BASE_URL }} | ||
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} | ||
PACTICIPANT: "LiveCoding.Tickets.Pricing" | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
|
||
# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies. | ||
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md | ||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 | ||
|
||
- name: Publish Promoter Spring Cloud Contract to local maven repo | ||
run: >- | ||
cd services/Promoter && | ||
./gradlew publishToMavenLocal | ||
- name: Test | ||
run: >- | ||
cd services/Pricing && | ||
./gradlew | ||
-Dpact.verifier.publishResults=true | ||
-Dpact.provider.version=$PACTICIPANT-${{ github.sha }} | ||
-Dpact.provider.branchName=${{ github.ref_name }} | ||
-Dpact.provider.tag=${{ github.ref_name }} | ||
-Dpact.rootDir=build/pacts | ||
test publishToMavenLocal | ||
dev-deployment: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
environment: dev | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Can I deploy to dev? | ||
run: >- | ||
docker run --rm \ | ||
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \ | ||
pactfoundation/pact-cli:1.1.0.0 \ | ||
broker can-i-deploy --pacticipant=$PACTICIPANT --to-environment=dev-liveCoding --version=$PACTICIPANT-${{ github.sha }} | ||
- name: Deploy to Dev | ||
run: echo "Deploying to dev" | ||
|
||
- name: Record Pact deployment to dev | ||
run: >- | ||
docker run --rm \ | ||
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \ | ||
pactfoundation/pact-cli:1.1.0.0 \ | ||
broker record-deployment --pacticipant=$PACTICIPANT --environment=dev-liveCoding --version=$PACTICIPANT-${{ github.sha }} | ||
prod-deployment: | ||
needs: dev-deployment | ||
runs-on: ubuntu-latest | ||
environment: prod | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Can I deploy to prod? | ||
run: >- | ||
docker run --rm \ | ||
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \ | ||
pactfoundation/pact-cli:1.1.0.0 \ | ||
broker can-i-deploy --pacticipant=$PACTICIPANT --to-environment=prod-liveCoding --version=$PACTICIPANT-${{ github.sha }} --ignore="Tickets.Promoter" | ||
- name: Deploy to prod | ||
run: echo "Deploying to prod" | ||
|
||
- name: Record Pact deployment to prod | ||
run: >- | ||
docker run --rm \ | ||
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \ | ||
pactfoundation/pact-cli:1.1.0.0 \ | ||
broker record-deployment --pacticipant=$PACTICIPANT --environment=prod-liveCoding --version=$PACTICIPANT-${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
name: LiveCoding Promoter CI | ||
run-name: LiveCoding Promoter CI | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'services/Promoter/**' | ||
- 'libs/SharedLib/**' | ||
- '.github/workflows/ci-promoter.yml' | ||
- '.github/workflows/ci-promoter-liveCoding.yml' | ||
- '.github/workflows/ci-shared-lib.yml' | ||
workflow_dispatch: | ||
repository_dispatch: | ||
types: [promoter-ci-webhook] | ||
|
||
env: | ||
PACT_BROKER_BASE_URL: ${{ vars.PACT_BROKER_BASE_URL }} | ||
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }} | ||
PACTICIPANT: "LiveCoding.Tickets.Promoter" | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
|
||
# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies. | ||
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md | ||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 | ||
|
||
- name: Publish Pricing Spring Cloud Contract to local maven repo | ||
run: >- | ||
cd services/Pricing && | ||
./gradlew publishToMavenLocal | ||
- name: Test | ||
run: >- | ||
cd services/Promoter && | ||
./gradlew | ||
-Dpact.rootDir=build/pacts | ||
test publishToMavenLocal | ||
- name: Publish Promoter Consumer Pacts | ||
run: >- | ||
docker run --rm \ | ||
-w ${PWD} \ | ||
-v ${PWD}:${PWD} \ | ||
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \ | ||
pactfoundation/pact-cli:1.1.0.0 \ | ||
broker publish ${PWD}/services/Promoter/build/pacts --consumer-app-version=$PACTICIPANT-${{ github.sha }} --branch=${{github.ref_name}} --tag-with-git-branch | ||
dev-deployment: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
environment: dev | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Can I deploy to dev? | ||
run: >- | ||
docker run --rm \ | ||
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \ | ||
pactfoundation/pact-cli:1.1.0.0 \ | ||
broker can-i-deploy --pacticipant=$PACTICIPANT --to-environment=dev-liveCoding --version=$PACTICIPANT-${{ github.sha }} | ||
- name: Deploy to Dev | ||
run: echo "Deploying to dev" | ||
|
||
- name: Record Pact deployment to dev | ||
run: >- | ||
docker run --rm \ | ||
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \ | ||
pactfoundation/pact-cli:1.1.0.0 \ | ||
broker record-deployment --pacticipant=$PACTICIPANT --environment=dev-liveCoding --version=$PACTICIPANT-${{ github.sha }} | ||
prod-deployment: | ||
needs: dev-deployment | ||
runs-on: ubuntu-latest | ||
environment: prod | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Can I deploy to prod? | ||
run: >- | ||
docker run --rm \ | ||
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \ | ||
pactfoundation/pact-cli:1.1.0.0 \ | ||
broker can-i-deploy --pacticipant=$PACTICIPANT --to-environment=prod-liveCoding --version=$PACTICIPANT-${{ github.sha }} | ||
- name: Deploy to prod | ||
run: echo "Deploying to prod" | ||
|
||
- name: Record Pact deployment to prod | ||
run: >- | ||
docker run --rm \ | ||
-e PACT_BROKER_BASE_URL=$PACT_BROKER_BASE_URL \ | ||
-e PACT_BROKER_TOKEN=$PACT_BROKER_TOKEN \ | ||
pactfoundation/pact-cli:1.1.0.0 \ | ||
broker record-deployment --pacticipant=$PACTICIPANT --environment=prod-liveCoding --version=$PACTICIPANT-${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...om/bottega/pricing/price/api/rest/Pricing_providesApiContract_liveCoding_pactApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.bottega.pricing.price.api.rest; | ||
|
||
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.PactBroker; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactBrokerAuth; | ||
import com.bottega.pricing.fixtures.FrameworkTestBase; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
@Provider("LiveCoding.Tickets.Pricing") | ||
@PactBroker(url = "https://jacek.pactflow.io", authentication = @PactBrokerAuth(token = "${PACT_BROKER_TOKEN}")) | ||
@IgnoreNoPactsToVerify | ||
public class Pricing_providesApiContract_liveCoding_pactApiTest extends FrameworkTestBase { | ||
|
||
@Value("${server.port}") | ||
int port; | ||
|
||
@BeforeEach | ||
public void setupTestTarget(PactVerificationContext context) { | ||
super.beforeEach(); | ||
if (context != null) { | ||
context.setTarget(new HttpTestTarget("localhost", port)); | ||
} | ||
System.setProperty("pact.verifier.publishResults", "true"); | ||
} | ||
|
||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider.class) | ||
public void pricingPactProviderVerification(PactVerificationContext context) { | ||
if (context != null) { | ||
context.verifyInteraction(); | ||
} | ||
} | ||
|
||
@State("price for item exists") | ||
public void priceForItemDiscount() { | ||
builders.aPrice().priceForItem(100_00, "123").inDb(); | ||
} | ||
|
||
|
||
} |
18 changes: 15 additions & 3 deletions
18
services/Promoter/src/main/java/com/bottega/promoter/concert/Price.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
package com.bottega.promoter.concert; | ||
|
||
import java.util.List; | ||
|
||
import com.bottega.sharedlib.vo.Money; | ||
import lombok.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
|
||
@EqualsAndHashCode | ||
@AllArgsConstructor | ||
@ToString | ||
@Getter | ||
public class Price { | ||
|
||
private String id; | ||
private String itemId; | ||
private Money price; | ||
private List<PriceFactor> factors; | ||
|
||
public Price applyFactor(PriceFactor factor) { | ||
this.price = price.subtract(price.percentage(factor.value())); | ||
this.factors.add(factor); | ||
return this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.