|
| 1 | +package au.com.dius.pact.consumer.junit5; |
| 2 | + |
| 3 | +import au.com.dius.pact.consumer.MockServer; |
| 4 | +import au.com.dius.pact.consumer.dsl.PactBuilder; |
| 5 | +import au.com.dius.pact.core.model.V4Pact; |
| 6 | +import au.com.dius.pact.core.model.annotations.Pact; |
| 7 | +import org.apache.hc.client5.http.fluent.Request; |
| 8 | +import org.apache.hc.core5.http.ClassicHttpResponse; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 11 | + |
| 12 | +import java.io.IOException; |
| 13 | + |
| 14 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 15 | +import static org.hamcrest.Matchers.equalTo; |
| 16 | +import static org.hamcrest.Matchers.is; |
| 17 | + |
| 18 | +@ExtendWith(PactConsumerTestExt.class) |
| 19 | +@PactTestFor(providerName = "HeadMethodProvider") |
| 20 | +public class HeadMethodTest { |
| 21 | + @Pact(consumer = "HeadMethodConsumer") |
| 22 | + public V4Pact pact(PactBuilder builder) { |
| 23 | + return builder |
| 24 | + .expectsToReceiveHttpInteraction("HEAD request", |
| 25 | + interaction -> interaction |
| 26 | + .withRequest(request -> request.path("/v1/my/path").method("HEAD")) |
| 27 | + .willRespondWith(response -> response.status(200))) |
| 28 | + .toPact(); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + void testPact(MockServer mockServer) throws IOException { |
| 33 | + ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.head(mockServer.getUrl() + "/v1/my/path") |
| 34 | + .execute() |
| 35 | + .returnResponse(); |
| 36 | + assertThat(httpResponse.getCode(), is(equalTo(200))); |
| 37 | + } |
| 38 | +} |
0 commit comments