-
-
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.
- Loading branch information
1 parent
51c89df
commit 21b06cf
Showing
8 changed files
with
211 additions
and
11 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...umer/groovy/src/test/groovy/au/com/dius/pact/consumer/model/MockProviderConfigSpec.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,19 @@ | ||
package au.com.dius.pact.consumer.model | ||
|
||
import spock.lang.Specification | ||
|
||
class MockProviderConfigSpec extends Specification { | ||
def 'url test'() { | ||
expect: | ||
new MockProviderConfig(hostname, port).url() == url | ||
|
||
where: | ||
|
||
hostname | port | url | ||
'127.0.0.1' | 0 | 'http://localhost:0' | ||
'localhost' | 1234 | 'http://localhost:1234' | ||
'[::1]' | 1234 | 'http://ip6-localhost:1234' | ||
'ip6-localhost' | 1234 | 'http://ip6-localhost:1234' | ||
'::1' | 0 | 'http://ip6-localhost:0' | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/IP6Test.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,38 @@ | ||
package au.com.dius.pact.consumer.junit; | ||
|
||
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.hc.client5.http.fluent.Request; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
public class IP6Test { | ||
|
||
@Rule | ||
public PactProviderRule provider = new PactProviderRule("ip6_provider", "::1", 0, this); | ||
|
||
@Pact(provider = "ip6_provider", consumer = "test_consumer") | ||
public RequestResponsePact getRequest(PactDslWithProvider builder) { | ||
return builder | ||
.uponReceiving("get request") | ||
.path("/path") | ||
.method("GET") | ||
.willRespondWith() | ||
.status(200) | ||
.body("{}", "application/json") | ||
.toPact(); | ||
} | ||
|
||
@Test | ||
@PactVerification("ip6_provider") | ||
public void runTest() throws IOException { | ||
assertThat(Request.get(provider.getUrl() + "/path").execute().returnContent().asString(), is(equalTo("{}"))); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/Ip6KTorTest.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,42 @@ | ||
package au.com.dius.pact.consumer.junit5; | ||
|
||
import au.com.dius.pact.consumer.MockServer; | ||
import au.com.dius.pact.consumer.dsl.PactDslWithProvider; | ||
import au.com.dius.pact.consumer.junit.MockServerConfig; | ||
import au.com.dius.pact.consumer.model.MockServerImplementation; | ||
import au.com.dius.pact.core.model.PactSpecVersion; | ||
import au.com.dius.pact.core.model.RequestResponsePact; | ||
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 static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@ExtendWith(PactConsumerTestExt.class) | ||
@PactTestFor(providerName = "ip6_provider", pactVersion = PactSpecVersion.V3) | ||
@MockServerConfig(hostInterface = "::1", port = "1234", implementation = MockServerImplementation.KTorServer) | ||
public class Ip6KTorTest { | ||
@Pact(consumer = "ApiConsumer") | ||
public RequestResponsePact articles(PactDslWithProvider builder) { | ||
return builder | ||
.uponReceiving("GET request") | ||
.path("/test") | ||
.method("GET") | ||
.willRespondWith() | ||
.status(200) | ||
.toPact(); | ||
} | ||
|
||
@Test | ||
@PactTestFor | ||
void testApi(MockServer mockServer) throws IOException { | ||
ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.get(mockServer.getUrl() + "/test").execute().returnResponse(); | ||
assertThat(httpResponse.getCode(), is(equalTo(200))); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/Ip6Test.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,47 @@ | ||
package au.com.dius.pact.consumer.junit5; | ||
|
||
import au.com.dius.pact.consumer.MockServer; | ||
import au.com.dius.pact.consumer.dsl.PactDslWithProvider; | ||
import au.com.dius.pact.consumer.junit.MockServerConfig; | ||
import au.com.dius.pact.core.model.PactSpecVersion; | ||
import au.com.dius.pact.core.model.RequestResponsePact; | ||
import au.com.dius.pact.core.model.annotations.Pact; | ||
import org.apache.commons.collections4.MapUtils; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.hc.client5.http.fluent.Request; | ||
import org.apache.hc.core5.http.ClassicHttpResponse; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonArrayMinLike; | ||
import static java.lang.String.format; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
@ExtendWith(PactConsumerTestExt.class) | ||
@PactTestFor(providerName = "ip6_provider", pactVersion = PactSpecVersion.V3) | ||
@MockServerConfig(hostInterface = "::1", port = "1234") | ||
public class Ip6Test { | ||
@Pact(consumer = "ApiConsumer") | ||
public RequestResponsePact articles(PactDslWithProvider builder) { | ||
return builder | ||
.uponReceiving("GET request") | ||
.path("/test") | ||
.method("GET") | ||
.willRespondWith() | ||
.status(200) | ||
.toPact(); | ||
} | ||
|
||
@Test | ||
@PactTestFor | ||
void testApi(MockServer mockServer) throws IOException { | ||
ClassicHttpResponse httpResponse = (ClassicHttpResponse) Request.get(mockServer.getUrl() + "/test").execute().returnResponse(); | ||
assertThat(httpResponse.getCode(), is(equalTo(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
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