This file contains hidden or 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
    
  
  
    
  | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
| @Provider("UserServiceJUnit5") | |
| @PactBroker(url = "http://localhost:9292") | |
| @SetSystemProperty(key = "pact.verifier.publishResults", value = "true") | |
| public class PactProviderJUnit5WithBrokerTest { | |
| @LocalServerPort | |
| int port; | |
| @BeforeEach | 
  
    
      This file contains hidden or 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
    
  
  
    
  | version: "3" | |
| services: | |
| postgres: | |
| image: postgres | |
| healthcheck: | |
| test: psql postgres --command "select 1" -U postgres | |
| volumes: | |
| - postgres-volume:/var/lib/postgresql/data | |
| environment: | 
  
    
      This file contains hidden or 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
    
  
  
    
  | @Pact(provider = "UserServiceJUnit5", consumer = "UserConsumer") | |
| public V4Pact getAllUsers(PactBuilder builder) { | |
| return builder | |
| .usingLegacyDsl() | |
| .given("A running user service") | |
| .uponReceiving("A request for a user list") | |
| .path("/users") | |
| .method("GET") | |
| .willRespondWith() | 
  
    
      This file contains hidden or 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
    
  
  
    
  | @WebMvcTest | |
| @Provider("UserServiceJUnit5") | |
| @PactFolder("build/pacts") | |
| public class PactProviderSpringJUnit5Test { | |
| @TestConfiguration | |
| static class Config { | |
| @Bean | |
| public UserRepository userRepo() { | 
  
    
      This file contains hidden or 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
    
  
  
    
  | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
| @Provider("UserServiceJUnit5") | |
| @PactFolder("build/pacts") | |
| public class PactProviderJUnit5Test { | |
| @LocalServerPort | |
| int port; | |
| @BeforeEach | |
| public void setup(PactVerificationContext context) { | 
  
    
      This file contains hidden or 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
    
  
  
    
  | @ExtendWith(PactConsumerTestExt.class) | |
| public class PactConsumerJUnit5Test { | |
| @Pact(provider = "UserServiceJUnit5", consumer = "UserConsumer") | |
| public V4Pact getAllUsers(PactBuilder builder) { | |
| String expectedUsers = """ | |
| [ | |
| { | |
| "id": 1, | 
  
    
      This file contains hidden or 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
    
  
  
    
  | { | |
| "consumer": { | |
| "name": "UserConsumer" | |
| }, | |
| "interactions": [ | |
| { | |
| "description": "A request for a user list", | |
| "request": { | |
| "method": "GET", | |
| "path": "/users" | 
  
    
      This file contains hidden or 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
    
  
  
    
  | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
| public class PactProviderTest { | |
| ProviderInfo providerInfo; | |
| ConsumerInfo consumerInfo; | |
| static Pact consumerPact; | |
| @LocalServerPort | |
| int port; | 
  
    
      This file contains hidden or 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
    
  
  
    
  | public class PactConsumerTest { | |
| @Test | |
| public void getAllUsersPact() { | |
| String expectedUsers = """ | |
| [ | |
| { | |
| "id": 1, | |
| "name": "Jane Doe" | |
| }, | 
  
    
      This file contains hidden or 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
    
  
  
    
  | let jsonData = JSON.parse(responseBody) | |
| pm.test("Cars have been received", () => { | |
| pm.response.to.have.status(200) | |
| pm.expect(jsonData).to.not.be.undefined | |
| pm.expect(jsonData).to.be.an('array') | |
| pm.expect(jsonData).to.not.be.empty | |
| }); |