-
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.
task-consumer-pact-messaging-provider-done
- Loading branch information
Showing
1 changed file
with
47 additions
and
2 deletions.
There are no files selected for viewing
49 changes: 47 additions & 2 deletions
49
...i/event/InitialPriceEventListener_emitsPriceChangeEvent_pactMessagingProviderApiTest.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,11 +1,56 @@ | ||
package com.bottega.pricing.initialPrice.api.event; | ||
|
||
import au.com.dius.pact.provider.MessageAndMetadata; | ||
import au.com.dius.pact.provider.PactVerifyProvider; | ||
import au.com.dius.pact.provider.junit5.MessageTestTarget; | ||
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.loader.PactBroker; | ||
import au.com.dius.pact.provider.junitsupport.loader.PactBrokerAuth; | ||
import com.bottega.pricing.fixtures.FrameworkTestBase; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.SneakyThrows; | ||
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.Autowired; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Provider("Tickets.Pricing.Messaging") | ||
@PactBroker(url = "${PACT_BROKER_BASE_URL}", authentication = @PactBrokerAuth(token = "${PACT_BROKER_TOKEN}")) | ||
@IgnoreNoPactsToVerify | ||
public class InitialPriceEventListener_emitsPriceChangeEvent_pactMessagingProviderApiTest extends FrameworkTestBase { | ||
|
||
//TODO: append suffix `.Messaging` Provider and Consumer names to distinguish it from previous assignments | ||
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
@TestTemplate | ||
@ExtendWith(PactVerificationInvocationContextProvider.class) | ||
void testTemplate(PactVerificationContext context) { | ||
context.verifyInteraction(); | ||
} | ||
|
||
@BeforeEach | ||
void before(PactVerificationContext context) { | ||
super.beforeEach(); | ||
context.setTarget(new MessageTestTarget(List.of("com.bottega"))); | ||
// System.setProperty("pact.verifier.publishResults", "true"); // Should only be enabled in CI. | ||
System.setProperty("pact.rootDir", "build/pacts"); | ||
} | ||
|
||
@SneakyThrows | ||
@PactVerifyProvider("PRICE_CHANGE event") | ||
MessageAndMetadata createConcert_emitsPriceChangePactEvent() { | ||
//when | ||
initPriceFixtures.initPriceChangeEventPublisher.publishConcertCreatedEvent(); | ||
|
||
//TODO: use initPriceFixtures.initPriceChangeEventPublisher.publishConcertCreatedEvent(); method to trigger Pricing service to emit PRICE_CHANGE event | ||
return new MessageAndMetadata( | ||
objectMapper.writeValueAsBytes(sharedFixtures.testEventListener.singleEvent()), | ||
Map.of("contentType", "application/json")); | ||
} | ||
|
||
} |