-
-
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.
fix: Deprecate eachKeyLike methods as they actually act on the values #…
- Loading branch information
1 parent
877f21b
commit ae06079
Showing
3 changed files
with
106 additions
and
7 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/EachKeyLikeTest.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,61 @@ | ||
package au.com.dius.pact.consumer.junit5; | ||
|
||
import au.com.dius.pact.consumer.MockServer; | ||
import au.com.dius.pact.consumer.dsl.PactDslJsonRootValue; | ||
import au.com.dius.pact.consumer.dsl.PactDslWithProvider; | ||
import au.com.dius.pact.core.model.PactSpecVersion; | ||
import au.com.dius.pact.core.model.V4Pact; | ||
import au.com.dius.pact.core.model.annotations.Pact; | ||
import org.apache.hc.client5.http.fluent.Request; | ||
import org.apache.hc.core5.http.ClassicHttpResponse; | ||
import org.apache.hc.core5.http.ContentType; | ||
import org.apache.hc.core5.http.io.entity.StringEntity; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.io.IOException; | ||
|
||
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonBody; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
// Issue #1813 | ||
@ExtendWith(PactConsumerTestExt.class) | ||
@PactTestFor(providerName = "eachkeylike_provider", pactVersion = PactSpecVersion.V4) | ||
public class EachKeyLikeTest { | ||
|
||
@Pact(consumer="eachkeylike__consumer") | ||
public V4Pact createFragment(PactDslWithProvider builder) { | ||
return builder | ||
.uponReceiving("A request") | ||
.path("/") | ||
.method("POST") | ||
.body(newJsonBody(body -> | ||
body.object("a", aObj -> { | ||
aObj.eachKeyLike("prop1", PactDslJsonRootValue.stringMatcher("prop\\d+", "prop1")); | ||
aObj.eachKeyLike("prop1", propObj -> propObj.stringType("value", "x")); | ||
})).build()) | ||
.willRespondWith() | ||
.status(200) | ||
.toPact(V4Pact.class); | ||
} | ||
|
||
@Test | ||
void runTest(MockServer mockServer) throws IOException { | ||
String json = "{\n" + | ||
" \"a\": {\n" + | ||
" \"prop1\": {\n" + | ||
" \"value\": \"x\"\n" + | ||
" },\n" + | ||
" \"prop\": {\n" + | ||
" \"value\": \"y\"\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}"; | ||
ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.post(mockServer.getUrl()) | ||
.body(new StringEntity(json, ContentType.APPLICATION_JSON)) | ||
.execute() | ||
.returnResponse(); | ||
assertThat(httpResponse.getCode(), is(200)); | ||
} | ||
} |
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
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