Hi Team, I Need your inputs what i am doing wrong ...
# pact-jvm
h
Hi Team, I Need your inputs what i am doing wrong here on Consumer Contracts. When i run the Test it says no one is called but when i run with debugger i notice MockServer and the healthcheck end point have same host and port number and the end point as well. Please guide me what i am missing here
Copy code
@ExtendWith(PactConsumerTestExt.class)
@ExtendWith(MockitoExtension.class)
@PactTestFor(providerName = "ProviderService")
public class HealthCheckTest {
    
    @Pact(consumer = "Consumer")
    public RequestResponsePact getHealthCheck(PactDslWithProvider builder) {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Content-Type", "text/plain");
        headers.put("callchainid", "a4275861-f60a-44ab-85a6-c0c2c9df5e27");

        return builder
                .given("get health check")
                .uponReceiving("get health data")
                .path("/health")
                .method("GET")
                .headers(headers )
                .willRespondWith()
                .status(200)
                .body("{\"status\":\"UP\",\"components\":{\"db\":{\"status\":\"UP\",\"details\":{\"database\":\"PostgreSQL\",\"validationQuery\":\"isValid()\"}}}}")
                .toPact();
    }

    @Test
    @PactTestFor(pactMethod = "getHealthCheck")
    void getHealthData(MockServer mockServer) {

        WebClient webClient=WebClient.builder().baseUrl(mockServer.getUrl()).build();
        final String callChainId="a4275861-f60a-44ab-85a6-c0c2c9df5e27";
        ThreadContext.put(CallChainIdService.HEADER_NAME, callChainId);
        AsyncClient asyncClient=new AsyncClient(webClient);
        Mono<ClientResponse> responseMono=asyncClient.getHealthCheck();
        System.out.println(responseMono);


    }
Client Class
Copy code
@Log4j2
@Service
public class AsyncClient implements CMClient {
  
  private final WebClient CLIENT;
  
  public AsyncClient(
    @Qualifier("cm-api") WebClient cm
  ) {
    CLIENT = cm;
  }
  
  @Override
  public Mono<ClientResponse> getHealthCheck() {
    return get(MediaType.TEXT_PLAIN, "/health");
  }
  

  
  private Mono<ClientResponse> get(MediaType contentType, String uri, Object... params) {
    return CLIENT
      .mutate()
      .defaultHeader(CallChainIdService.HEADER_NAME, ThreadContext.get(CallChainIdService.HEADER_NAME))
      .build()
      .get()
      .uri(uri, params)
      .accept(contentType)
      .exchange();
  }
  
}
When i run the test
Copy code
au.com.dius.pact.consumer.PactMismatchesException: The following requests were not received:
	method: GET
	path: /health
	query: {}
	headers: {callchainid=[a4275861-f60a-44ab-85a6-c0c2c9df5e27], Content-Type=[text/plain]}
	matchers: MatchingRules(rules={})
	generators: Generators(categories={})
	body: MISSING
Please guide me what i am missing here