--- /dev/null
+package de.juplo.kafka.chat.backend.api;
+
+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.Provider;
+import au.com.dius.pact.provider.junitsupport.State;
+import au.com.dius.pact.provider.junitsupport.loader.PactFolder;
+import de.juplo.kafka.chat.backend.domain.ChatHomeService;
+import lombok.extern.slf4j.Slf4j;
+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 org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import java.util.UUID;
+
+
+@Provider("ChatBackendController")
+@PactFolder("src/test/resources/pacts")
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(
+ webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
+ properties = {
+ "chat.backend.inmemory.storage-strategy=none",
+ "chat.backend.inmemory.sharding-strategy=kafkalike",
+ "chat.backend.inmemory.num-shards=10",
+ "chat.backend.inmemory.owned-shards=2" })
+@Slf4j
+public class PactProviderTest
+{
+
+ @Autowired
+ ChatHomeService chatHomeService;
+
+ @LocalServerPort
+ int port;
+
+ @BeforeEach
+ void setUp(PactVerificationContext context) {
+ context.setTarget(new HttpTestTarget("localhost", port));
+ }
+
+ @TestTemplate
+ @ExtendWith(PactVerificationInvocationContextProvider.class)
+ void verifyPact(PactVerificationContext context) {
+ context.verifyInteraction();
+ }
+
+ @State("there are 10 shards")
+ void stateThereAre10Shards() {}
+
+ @State("the server is responsible for shard 2")
+ void stateTheServerOwnsShard2() {}
+
+ @State("chatroom 5c73531c-6fc4-426c-adcb-afc5c140a0f7 exists in shard 2")
+ void stateChatroomExistsInOwnedShard() {
+ chatHomeService.createChatRoom(UUID.fromString("5c73531c-6fc4-426c-adcb-afc5c140a0f7"), "FOO");
+ }
+
+ @State("chatroom 7f59ec77-832e-4a17-8d22-55ef46242c17 does not exists in shard 2")
+ void stateChatroomDosNotExistsInOwnedShard() {}
+
+ @State("there are no chatrooms available at all in shard 2")
+ void stateNoChatroomsAvailableInOwnedShard() {
+ chatHomeService
+ .getChatRoomInfo()
+ .subscribe(chatRoomInfo ->
+ {
+ log.debug("Removing chatroom {}", chatRoomInfo);
+ chatHomeService.removeChatRoom(chatRoomInfo.getId());
+ });
+ }
+}