-
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.
Pact Live: consumer test implemented
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...romoter/src/test/java/com/bottega/promoter/fixtures/PactFrameworkTestBase_liveCoding.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,21 @@ | ||
package com.bottega.promoter.fixtures; | ||
|
||
import au.com.dius.pact.consumer.junit5.PactConsumerTestExt; | ||
import au.com.dius.pact.consumer.junit5.PactTestFor; | ||
import au.com.dius.pact.core.model.PactSpecVersion; | ||
import com.bottega.promoter.concert.fixtures.PricingPactFixtures; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
@ExtendWith(PactConsumerTestExt.class) | ||
@PactTestFor(providerName = PactFrameworkTestBase_liveCoding.PACT_PRICING_LIVE_CODING, port = "8181", pactVersion = PactSpecVersion.V3) | ||
@SuppressWarnings("deprecation") | ||
public class PactFrameworkTestBase_liveCoding extends FrameworkTestBase { | ||
|
||
public static final String PACT_PROMOTER_LIVE_CODING = "LiveCoding.Tickets.Promoter"; | ||
public static final String PACT_PRICING_LIVE_CODING = "LiveCoding.Tickets.Pricing"; | ||
|
||
@Autowired | ||
protected PricingPactFixtures pricingPactFixtures; | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...ega/promoter/infra/client/pricing/PricingClient_applyDiscount_liveCoding_pactDepTest.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,42 @@ | ||
package com.bottega.promoter.infra.client.pricing; | ||
|
||
import au.com.dius.pact.consumer.dsl.PactDslWithProvider; | ||
import au.com.dius.pact.core.model.RequestResponsePact; | ||
import au.com.dius.pact.core.model.annotations.Pact; | ||
import com.bottega.promoter.concert.domain.ConcertId; | ||
import com.bottega.promoter.fixtures.FakePricingClient; | ||
import com.bottega.promoter.fixtures.PactFrameworkTestBase_liveCoding; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class PricingClient_applyDiscount_liveCoding_pactDepTest extends PactFrameworkTestBase_liveCoding { | ||
|
||
FakePricingClient fakePricingClient; | ||
PricingClient httpPricingClient; | ||
|
||
|
||
@BeforeEach | ||
void setUp() { | ||
fakePricingClient = new FakePricingClient(); | ||
httpPricingClient = concertFixtures.pricingClient; | ||
} | ||
|
||
@Pact(consumer = PACT_PROMOTER_LIVE_CODING) | ||
@SuppressWarnings("unused") | ||
public RequestResponsePact applyPercentageDiscount(PactDslWithProvider builder) { | ||
return pricingPactFixtures.applyPercentageDiscount(builder); | ||
} | ||
|
||
@Test | ||
public void applyDiscount_isValid() { | ||
|
||
//when | ||
var result = httpPricingClient.applyPercentageDiscount(new ConcertId("123"), 10); | ||
|
||
//then | ||
assertThat(result.get().getFirst().getPrice().toInt()).isEqualTo(90_00); | ||
} | ||
|
||
} |