-
-
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.
feat: Update mock server to handle compressed bodies #556
- Loading branch information
Ronald Holshausen
committed
Jun 12, 2020
1 parent
05dddad
commit 5bf94d7
Showing
10 changed files
with
182 additions
and
27 deletions.
There are no files selected for viewing
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
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
48 changes: 48 additions & 0 deletions
48
consumer/junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/GZippedBodyTest.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,48 @@ | ||
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.client.HttpClient | ||
import org.apache.http.client.entity.EntityBuilder | ||
import org.apache.http.client.methods.HttpPost | ||
import org.apache.http.entity.ContentType | ||
import org.apache.http.impl.client.HttpClients | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(PactConsumerTestExt) | ||
@PactTestFor(providerName = 'ProviderThatAcceptsGZippedBodies') | ||
class GZippedBodyTest { | ||
@Pact(consumer = 'Consumer') | ||
RequestResponsePact pact(PactDslWithProvider builder) { | ||
builder | ||
.uponReceiving('a request with a zipped body') | ||
.method('POST') | ||
.path('/values') | ||
.body(new PactDslJsonBody().integerType('id')) | ||
.willRespondWith() | ||
.status(200) | ||
.body(new PactDslJsonBody().integerType('id')) | ||
.toPact() | ||
} | ||
|
||
@Test | ||
void testFiles(MockServer mockServer) { | ||
def entity = EntityBuilder.create() | ||
.setText('{"id": 1}') | ||
.setContentType(ContentType.APPLICATION_JSON) | ||
.gzipCompress() | ||
.build() | ||
HttpClient httpClient = HttpClients.createDefault() | ||
def post = new HttpPost("${mockServer.url}/values") | ||
post.setEntity(entity) | ||
post.setHeader('Content-Type', ContentType.APPLICATION_JSON.toString()) | ||
post.setHeader('Content-Encoding', 'gzip') | ||
post.setHeader('Accept-Encoding', 'gzip, deflate') | ||
def response = httpClient.execute(post) | ||
assert response.statusLine.statusCode == 200 | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
consumer/junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/KTorGZippedBodyTest.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,50 @@ | ||
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.consumer.model.MockServerImplementation | ||
import au.com.dius.pact.core.model.RequestResponsePact | ||
import au.com.dius.pact.core.model.annotations.Pact | ||
import org.apache.http.client.HttpClient | ||
import org.apache.http.client.entity.EntityBuilder | ||
import org.apache.http.client.methods.HttpPost | ||
import org.apache.http.entity.ContentType | ||
import org.apache.http.impl.client.HttpClients | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(PactConsumerTestExt) | ||
@PactTestFor(providerName = 'ProviderThatAcceptsGZippedBodies', port = '42567', | ||
mockServerImplementation = MockServerImplementation.KTorServer) | ||
class KTorGZippedBodyTest { | ||
@Pact(consumer = 'KTorGZippedBodyTestConsumer') | ||
RequestResponsePact pact(PactDslWithProvider builder) { | ||
builder | ||
.uponReceiving('a request with a zipped body') | ||
.method('POST') | ||
.path('/values') | ||
.body(new PactDslJsonBody().integerType('id')) | ||
.willRespondWith() | ||
.status(200) | ||
.body(new PactDslJsonBody().integerType('id')) | ||
.toPact() | ||
} | ||
|
||
@Test | ||
void testFiles(MockServer mockServer) { | ||
def entity = EntityBuilder.create() | ||
.setText('{"id": 1}') | ||
.setContentType(ContentType.APPLICATION_JSON) | ||
.gzipCompress() | ||
.build() | ||
HttpClient httpClient = HttpClients.createDefault() | ||
def post = new HttpPost("${mockServer.url}/values") | ||
post.setEntity(entity) | ||
post.setHeader('Content-Type', ContentType.APPLICATION_JSON.toString()) | ||
post.setHeader('Content-Encoding', 'gzip') | ||
post.setHeader('Accept-Encoding', 'gzip, deflate') | ||
def response = httpClient.execute(post) | ||
assert response.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
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
Oops, something went wrong.