-
-
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: just use the DateTimeFormatter to parse any datetime value
- Loading branch information
Ronald Holshausen
committed
Jun 12, 2020
1 parent
174acc0
commit 05dddad
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...r/junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/DateTimeWithTimezoneTest.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,42 @@ | ||
package au.com.dius.pact.consumer.junit5 | ||
|
||
import au.com.dius.pact.consumer.MockServer | ||
import au.com.dius.pact.consumer.dsl.PactDslJsonBody | ||
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.http.HttpResponse | ||
import org.apache.http.client.fluent.Request | ||
import org.apache.http.entity.StringEntity | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
import java.time.ZonedDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
@ExtendWith(PactConsumerTestExt) | ||
@PactTestFor(providerName = 'ProviderWithDateTime') | ||
class DateTimeWithTimezoneTest { | ||
@Pact(consumer = 'Consumer') | ||
RequestResponsePact pactWithTimezone(PactDslWithProvider builder) { | ||
builder | ||
.uponReceiving('a request with some datetime info') | ||
.method('POST') | ||
.path('/values') | ||
.body(new PactDslJsonBody().datetime('datetime', "YYYY-MM-dd'T'HH:mm:ss.SSSxxx")) | ||
.willRespondWith() | ||
.status(200) | ||
.body(new PactDslJsonBody().datetime('datetime', "YYYY-MM-dd'T'HH:mm:ss.SSSxxx")) | ||
.toPact() | ||
} | ||
|
||
@Test | ||
void testFiles(MockServer mockServer) { | ||
HttpResponse httpResponse = Request.Post("${mockServer.url}/values") | ||
.body(new StringEntity('{"datetime": "' + | ||
DateTimeFormatter.ofPattern("YYYY-MM-dd'T'HH:mm:ss.SSSxxx").format(ZonedDateTime.now()) | ||
+ '"}', 'application/json', 'UTF-8')) | ||
.execute().returnResponse() | ||
assert httpResponse.statusLine.statusCode == 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