-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test to try replicate Github issue
- Loading branch information
Ronald Holshausen
committed
Apr 18, 2020
1 parent
053d896
commit 7d84f60
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...ct-jvm-consumer-junit5/src/test/java/au/com/dius/pact/consumer/junit5/Defect1070Test.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package au.com.dius.pact.consumer.junit5; | ||
|
||
import au.com.dius.pact.consumer.MockServer; | ||
import au.com.dius.pact.consumer.dsl.PactDslWithProvider; | ||
import au.com.dius.pact.core.model.RequestResponsePact; | ||
import au.com.dius.pact.core.model.annotations.Pact; | ||
import org.apache.commons.collections4.MapUtils; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.fluent.Request; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static io.pactfoundation.consumer.dsl.LambdaDsl.newJsonArrayMinLike; | ||
import static java.lang.String.format; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
@ExtendWith(PactConsumerTestExt.class) | ||
@PactTestFor(providerName = "ApiProvider", port = "1234") | ||
public class Defect1070Test { | ||
private Map<String, String> headers = MapUtils.putAll(new HashMap<>(), new String[] { | ||
"Content-Type", "application/json" | ||
}); | ||
|
||
@BeforeEach | ||
public void setUp(MockServer mockServer) { | ||
assertThat(mockServer, is(notNullValue())); | ||
} | ||
|
||
@Pact(consumer = "ApiConsumer") | ||
public RequestResponsePact articles(PactDslWithProvider builder) { | ||
return builder | ||
.given("This is a test") | ||
.uponReceiving("GET request to retrieve default values") | ||
.matchPath(format("/api/test/%s", "\\d{1,8}")) | ||
.method("GET") | ||
.willRespondWith() | ||
.status(200) | ||
.headers(headers) | ||
.body(newJsonArrayMinLike(1, values -> values.object(value -> { | ||
value.numberType("id", 32432); | ||
value.stringType("name", "testId254"); | ||
value.numberType("size", 1445211); | ||
} | ||
)).build()) | ||
.toPact(); | ||
} | ||
|
||
@Test | ||
@PactTestFor | ||
void testApi(MockServer mockServer) throws IOException { | ||
HttpResponse httpResponse = Request.Get(mockServer.getUrl() + "/api/test/1234").execute().returnResponse(); | ||
assertThat(httpResponse.getStatusLine().getStatusCode(), is(equalTo(200))); | ||
assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), | ||
is(equalTo("[{\"size\":1445211,\"name\":\"testId254\",\"id\":32432}]"))); | ||
} | ||
} |