-
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correct the PactDslJsonRootValue to generate correctly encoded JSON s…
…trings #369
- Loading branch information
Ronald Holshausen
committed
Jan 19, 2017
1 parent
1f9a90e
commit 17554aa
Showing
4 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
pact-jvm-consumer-junit/src/test/java/au/com/dius/pact/consumer/Defect369Test.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,45 @@ | ||
package au.com.dius.pact.consumer; | ||
|
||
import au.com.dius.pact.consumer.dsl.PactDslJsonRootValue; | ||
import au.com.dius.pact.consumer.dsl.PactDslWithProvider; | ||
import au.com.dius.pact.model.PactFragment; | ||
import org.apache.http.client.fluent.Request; | ||
import org.apache.http.entity.ContentType; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class Defect369Test { | ||
|
||
private static final String APPLICATION_JSON = "application/json"; | ||
@Rule | ||
public PactProviderRule provider = new PactProviderRule("369_provider", "localhost", 8081, this); | ||
|
||
@Pact(provider="369_provider", consumer="test_consumer") | ||
public PactFragment createFragment(PactDslWithProvider builder) { | ||
Map<String, String> headers = new HashMap<String, String>(); | ||
headers.put("Content-Type", "application/json"); | ||
return builder | ||
.uponReceiving("a request for a simple string") | ||
.path("/provider/uri") | ||
.method("GET") | ||
.willRespondWith() | ||
.status(200) | ||
.headers(headers) | ||
.body(PactDslJsonRootValue.stringType("Example")) | ||
.toFragment(); | ||
} | ||
|
||
@Test | ||
@PactVerification("369_provider") | ||
public void runTest() throws IOException { | ||
assertEquals("\"Example\"", Request.Get("http://localhost:8081/provider/uri") | ||
.addHeader("Accept", APPLICATION_JSON) | ||
.execute().returnContent().asString()); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...vm-consumer/src/test/groovy/au/com/dius/pact/consumer/dsl/PactDslJsonRootValueSpec.groovy
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,35 @@ | ||
package au.com.dius.pact.consumer.dsl | ||
|
||
import spock.lang.Shared | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class PactDslJsonRootValueSpec extends Specification { | ||
@SuppressWarnings('PrivateFieldCouldBeFinal') | ||
@Shared | ||
private Date date = new Date(100, 1, 1, 20, 0, 0) | ||
|
||
@Unroll | ||
def 'correctly converts the value #value to JSON'() { | ||
expect: | ||
value.body as String == json | ||
|
||
where: | ||
|
||
value | json | ||
PactDslJsonRootValue.stringType('TEST') | '"TEST"' | ||
PactDslJsonRootValue.numberType(100) | '100' | ||
PactDslJsonRootValue.integerType(100) | '100' | ||
PactDslJsonRootValue.decimalType(100) | '100.0' | ||
PactDslJsonRootValue.booleanType(true) | 'true' | ||
PactDslJsonRootValue.stringMatcher('\\w+', 'test') | '"test"' | ||
PactDslJsonRootValue.timestamp('yyyy-MM-dd HH:mm:ss', date) | '"2000-02-01 20:00:00"' | ||
PactDslJsonRootValue.time('HH:mm:ss', date) | '"20:00:00"' | ||
PactDslJsonRootValue.date('yyyy-MM-dd', date) | '"2000-02-01"' | ||
PactDslJsonRootValue.ipAddress() | '"127.0.0.1"' | ||
PactDslJsonRootValue.id(1000) | '1000' | ||
PactDslJsonRootValue.hexValue('1000') | '"1000"' | ||
PactDslJsonRootValue.uuid('e87f3c51-545c-4bc2-b1b5-284de67d627e') | '"e87f3c51-545c-4bc2-b1b5-284de67d627e"' | ||
} | ||
|
||
} |