Skip to content

Commit

Permalink
task-consumer-pact-messaging-provider-done
Browse files Browse the repository at this point in the history
  • Loading branch information
yacekmm committed Dec 6, 2024
1 parent 06688be commit 8dd9df3
Showing 1 changed file with 47 additions and 2 deletions.
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"));
}

}

0 comments on commit 8dd9df3

Please sign in to comment.