Skip to content

Instantly share code, notes, and snippets.

@artemptushkin
Last active December 8, 2020 16:52
Show Gist options
  • Save artemptushkin/21d5039b323b4b4ddca11c8dd6714b06 to your computer and use it in GitHub Desktop.
Save artemptushkin/21d5039b323b4b4ddca11c8dd6714b06 to your computer and use it in GitHub Desktop.
The basic setup of pact consumer using `au.com.dius.pact.consumer:junit`
public class TariffClientPactTest {
@Rule
public PactProviderRule pactProviderRule = new PactProviderRule("billing", "localhost", 8080, this);
@Pact(provider = "billing", consumer = "transactions")
public RequestResponsePact itProvidesTariffPact(PactDslWithProvider pactDsl) {
return pactDsl
.given("tariff-for-transactions")
.uponReceiving("get tariff")
.path("/billing/tariffs/04974939-2630-4cb3-b2d0-baac27842172")
.method("GET")
.willRespondWith()
.status(200)
.body(new PactDslJsonBody()
.uuid("subscriptionId", "04974939-2630-4cb3-b2d0-baac27842172")
.numberType("energyPrice", 5.5)
.numberType("connectionPrice", 6.6)
.numberType("timePrice", 7.7)
.close()
)
.toPact();
}
@Test
@PactVerification("billing")
public void itFetchesTariff() {
Tariff actual = new TariffClient().fetchTariff("04974939-2630-4cb3-b2d0-baac27842172");
assertThat(actual.getSubscriptionId()).isEqualTo(fromString("04974939-2630-4cb3-b2d0-baac27842172))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment