-
-
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 with headers with params with no values #1727
- Loading branch information
1 parent
c4d291d
commit e7d501d
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...umer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/HeadersWithParametersTest.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,51 @@ | ||
package au.com.dius.pact.consumer.junit5; | ||
|
||
import au.com.dius.pact.consumer.MockServer; | ||
import au.com.dius.pact.consumer.dsl.PactBuilder; | ||
import au.com.dius.pact.consumer.dsl.PactDslWithProvider; | ||
import au.com.dius.pact.core.model.PactSpecVersion; | ||
import au.com.dius.pact.core.model.RequestResponsePact; | ||
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.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
// Issue #1727 | ||
@ExtendWith(PactConsumerTestExt.class) | ||
@PactTestFor(providerName = "HeadersWithParametersProvider", pactVersion = PactSpecVersion.V3) | ||
public class HeadersWithParametersTest { | ||
Map<String, String> headers = Map.of( | ||
"strict-transport-security", "max-age=3600; includeSubDomains; reload", | ||
"Content-Security-Policy", "default-src: 'none'; frame-ancestors 'none'; base-uri 'self'" | ||
); | ||
@Pact(consumer = "HeadersWithParametersConsumer") | ||
public RequestResponsePact pact(PactDslWithProvider builder) { | ||
return builder | ||
.uponReceiving("retrieving header data") | ||
.path("/path") | ||
.method("POST") | ||
.headers(headers) | ||
.willRespondWith() | ||
.headers(headers) | ||
.status(200) | ||
.toPact(); | ||
} | ||
|
||
@Test | ||
void testHeaders(MockServer mockServer) throws IOException { | ||
ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.post(mockServer.getUrl() + "/path") | ||
.addHeader("strict-transport-security", "max-age=3600; includeSubDomains; reload") | ||
.addHeader("Content-Security-Policy", "default-src: 'none'; frame-ancestors 'none'; base-uri 'self'") | ||
.execute().returnResponse(); | ||
assertThat(httpResponse.getCode(), is(equalTo(200))); | ||
} | ||
} |