diff --git a/build.gradle b/build.gradle index b5b3f77ba6..446326a26a 100644 --- a/build.gradle +++ b/build.gradle @@ -85,6 +85,8 @@ subprojects { } dependencies { + testCompile "org.junit.jupiter:junit-jupiter-api:${project.junit5Version}" + testRuntime "org.junit.jupiter:junit-jupiter-engine:${project.junit5Version}" testCompile('org.spockframework:spock-core:1.3-groovy-2.5') { exclude group: 'org.codehaus.groovy' } @@ -141,6 +143,15 @@ subprojects { from sourceSets.main.allSource } + test { + useJUnitPlatform() + + // Show test results. + testLogging { + events "passed", "skipped", "failed" + } + } + publishing { publications { mavenPublication(MavenPublication) { diff --git a/consumer/README.md b/consumer/README.md new file mode 100644 index 0000000000..ccb41b287c --- /dev/null +++ b/consumer/README.md @@ -0,0 +1,2 @@ +Consumer Pact-JVM Modules +========================= diff --git a/consumer/pact-jvm-consumer-scalasupport/README.md b/consumer/pact-jvm-consumer-scalasupport/README.md new file mode 100644 index 0000000000..b5673a1512 --- /dev/null +++ b/consumer/pact-jvm-consumer-scalasupport/README.md @@ -0,0 +1,3 @@ +Pact consumer Scala Support +=========================== + diff --git a/consumer/pact-jvm-consumer-scalasupport/build.gradle b/consumer/pact-jvm-consumer-scalasupport/build.gradle new file mode 100644 index 0000000000..59434abe32 --- /dev/null +++ b/consumer/pact-jvm-consumer-scalasupport/build.gradle @@ -0,0 +1,4 @@ + +dependencies { + +} diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/ConsumerPactRunner.scala b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/ConsumerPactRunner.scala similarity index 100% rename from consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/ConsumerPactRunner.scala rename to consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/ConsumerPactRunner.scala diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/MockProvider.scala b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/MockProvider.scala similarity index 92% rename from consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/MockProvider.scala rename to consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/MockProvider.scala index 1fc5edc0aa..0319ded48f 100644 --- a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/MockProvider.scala +++ b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/MockProvider.scala @@ -1,11 +1,10 @@ package au.com.dius.pact.consumer +import au.com.dius.pact.consumer.model.{MockHttpsKeystoreProviderConfig, MockHttpsProviderConfig, MockProviderConfig} import au.com.dius.pact.core.model.{Pact => PactModel, _} -import au.com.dius.pact.model.{MockHttpsKeystoreProviderConfig, MockHttpsProviderConfig, MockProviderConfig} +import au.com.dius.pact.model.{MockHttpsProviderConfig, MockProviderConfig} import com.typesafe.scalalogging.StrictLogging -import scala.util.Try - trait MockProvider[I <: Interaction] { def config: MockProviderConfig def session: PactSession diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/PactGenerator.scala b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/PactGenerator.scala similarity index 100% rename from consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/PactGenerator.scala rename to consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/PactGenerator.scala diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/PactSession.scala b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/PactSession.scala similarity index 100% rename from consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/PactSession.scala rename to consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/PactSession.scala diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/PrettyPrinter.scala b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/PrettyPrinter.scala similarity index 100% rename from consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/PrettyPrinter.scala rename to consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/PrettyPrinter.scala diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsKeystoreMockProvider.scala b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsKeystoreMockProvider.scala similarity index 95% rename from consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsKeystoreMockProvider.scala rename to consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsKeystoreMockProvider.scala index f2dde30c7e..139478443d 100644 --- a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsKeystoreMockProvider.scala +++ b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsKeystoreMockProvider.scala @@ -6,6 +6,7 @@ import io.netty.channel.ChannelHandler.Sharable import io.netty.handler.codec.{http => netty} import _root_.unfiltered.netty.{SslEngineProvider, cycle => unettyc} import _root_.unfiltered.{netty => unetty, request => ureq, response => uresp} +import au.com.dius.pact.consumer.model.MockHttpsKeystoreProviderConfig import au.com.dius.pact.core.model.{Request, RequestResponseInteraction, Response} class UnfilteredHttpsKeystoreMockProvider(val config: MockHttpsKeystoreProviderConfig) extends StatefulMockProvider[RequestResponseInteraction] { diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsMockProvider.scala b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsMockProvider.scala similarity index 96% rename from consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsMockProvider.scala rename to consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsMockProvider.scala index b5ac86623d..061dcef2a5 100644 --- a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsMockProvider.scala +++ b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/UnfilteredHttpsMockProvider.scala @@ -6,6 +6,7 @@ import io.netty.channel.ChannelHandler.Sharable import io.netty.handler.codec.{http => netty} import _root_.unfiltered.netty.{SslContextProvider, cycle => unettyc} import _root_.unfiltered.{netty => unetty, request => ureq, response => uresp} +import au.com.dius.pact.consumer.model.MockHttpsProviderConfig import au.com.dius.pact.core.model.{Request, RequestResponseInteraction, Response} class UnfilteredHttpsMockProvider(val config: MockHttpsProviderConfig) extends StatefulMockProvider[RequestResponseInteraction] { diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/UnfilteredMockProvider.scala b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/UnfilteredMockProvider.scala similarity index 96% rename from consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/UnfilteredMockProvider.scala rename to consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/UnfilteredMockProvider.scala index 8f3653c1c5..b8d8b55029 100644 --- a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/UnfilteredMockProvider.scala +++ b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/UnfilteredMockProvider.scala @@ -7,6 +7,7 @@ import _root_.unfiltered.{netty => unetty} import _root_.unfiltered.netty.{cycle => unettyc} import _root_.unfiltered.{request => ureq} import _root_.unfiltered.{response => uresp} +import au.com.dius.pact.consumer.model.MockProviderConfig import au.com.dius.pact.core.model.{Request, RequestResponseInteraction, Response} import io.netty.channel.ChannelHandler.Sharable diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/VerificationResult.scala b/consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/VerificationResult.scala similarity index 100% rename from consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/VerificationResult.scala rename to consumer/pact-jvm-consumer-scalasupport/src/main/scala/au/com/dius/pact/consumer/VerificationResult.scala diff --git a/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/consumer/PrettyPrinterSpec.groovy b/consumer/pact-jvm-consumer-scalasupport/src/test/groovy/au/com/dius/pact/consumer/PrettyPrinterSpec.groovy similarity index 100% rename from consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/consumer/PrettyPrinterSpec.groovy rename to consumer/pact-jvm-consumer-scalasupport/src/test/groovy/au/com/dius/pact/consumer/PrettyPrinterSpec.groovy diff --git a/consumer/pact-jvm-consumer/README.md b/consumer/pact-jvm-consumer/README.md index 8439cac88f..af25a77429 100644 --- a/consumer/pact-jvm-consumer/README.md +++ b/consumer/pact-jvm-consumer/README.md @@ -13,7 +13,7 @@ Provides a DSL for use with Java to build consumer pacts. The library is available on maven central using: * group-id = `au.com.dius` -* artifact-id = `pact-jvm-consumer_2.11` +* artifact-id = `pact-jvm-consumer` ## DSL Usage @@ -176,7 +176,7 @@ For example: This will ensure that the users list is never empty and that each user has an identifier that is a number and a name that is a string. -#### Matching JSON values at the root (Version 3.2.2/2.4.3+) +#### Matching JSON values at the root For cases where you are expecting basic JSON values (strings, numbers, booleans and null) at the root level of the body and need to use matchers, you can use the `PactDslJsonRootValue` class. It has all the DSL matching methods for basic @@ -194,7 +194,7 @@ For example: .body(PactDslJsonRootValue.integerType()) ``` -#### Root level arrays that match all items (version 2.2.11+) +#### Root level arrays that match all items If the root of the body is an array, you can create PactDslJsonArray classes with the following methods: @@ -233,7 +233,7 @@ This will then match a body like: } ] ``` -#### Matching arrays of arrays (version 3.2.12/2.4.14+) +#### Matching arrays of arrays For the case where you have arrays of arrays (GeoJSON is an example), the following methods have been provided: @@ -285,7 +285,7 @@ This generated the following JSON: and will be able to match all coordinates regardless of the number of coordinates. -#### Matching any key in a map (3.3.1/2.5.0+) +#### Matching any key in a map The DSL has been extended for cases where the keys in a map are IDs. For an example of this, see [#313](https://github.com/DiUS/pact-jvm/issues/313). In this case you can use the `eachKeyLike` method, which takes an @@ -321,7 +321,7 @@ For an example, have a look at [WildcardKeysTest](../pact-jvm-consumer-junit/src **Further Note: From version 3.5.22 onwards pacts with wildcards applied to map keys will require the Java system property "pact.matching.wildcard" set to value "true" when the pact file is verified.** -### Matching on paths (version 2.1.5+) +### Matching on paths You can use regular expressions to match incoming requests. The DSL has a `matchPath` method for this. You can provide a real path as a second value to use when generating requests, and if you leave it out it will generate a random one @@ -340,7 +340,7 @@ For example: .body("{\"hello\": \"harry\"}") ``` -### Matching on headers (version 2.2.2+) +### Matching on headers You can use regular expressions to match request and response headers. The DSL has a `matchHeader` method for this. You can provide an example header value to use when generating requests and responses, and if you leave it out it will generate a random one @@ -361,7 +361,7 @@ For example: .matchHeader("Location", ".*/hello/[0-9]+", "/hello/1234") ``` -### Matching on query parameters (version 3.3.7+) +### Matching on query parameters You can use regular expressions to match request query parameters. The DSL has a `matchQuery` method for this. You can provide an example value to use when generating requests, and if you leave it out it will generate a random one diff --git a/consumer/pact-jvm-consumer/build.gradle b/consumer/pact-jvm-consumer/build.gradle index da75408faa..6069ae0082 100644 --- a/consumer/pact-jvm-consumer/build.gradle +++ b/consumer/pact-jvm-consumer/build.gradle @@ -8,47 +8,14 @@ dependencies { compile "org.json:json:${project.jsonVersion}" compile "io.netty:netty-handler:${project.nettyVersion}" compile "org.apache.httpcomponents:httpmime:${project.httpClientVersion}" - compile "ws.unfiltered:unfiltered-netty-server_${project.scalaVersion}:0.9.1" compile "org.apache.httpcomponents:fluent-hc:${project.httpClientVersion}" - compile 'org.scala-lang.modules:scala-java8-compat_2.12:0.8.0' - compile "org.codehaus.groovy:groovy-json:${project.groovyVersion}:indy" - - compile "org.scala-lang:scala-library:${project.scalaFullVersion}" - compile("com.typesafe.scala-logging:scala-logging_${project.scalaVersion}:3.7.2") { - exclude group: 'org.scala-lang' - } - - testCompile "org.specs2:specs2-core_${project.scalaVersion}:${project.specs2Version}", - "org.specs2:specs2-junit_${project.scalaVersion}:${project.specs2Version}" + implementation 'org.slf4j:slf4j-api:1.7.26' testCompile "ch.qos.logback:logback-classic:${project.logbackVersion}" - testCompile "org.specs2:specs2-mock_${project.scalaVersion}:${project.specs2Version}" testCompile 'org.cthul:cthul-matchers:1.1.0' testCompile "org.junit.jupiter:junit-jupiter-api:${project.junit5Version}" testRuntime "org.junit.jupiter:junit-jupiter-engine:${project.junit5Version}" testRuntime "org.junit.vintage:junit-vintage-engine:${project.junit5Version}" testCompile "org.codehaus.groovy:groovy-dateutil:${project.groovyVersion}:indy" -} - -// The language compilers should execute in this order -// Java then Kotlin then Scala then Groovy -sourceSets.main.scala.srcDir "src/main/java" -sourceSets.main.java.srcDirs = [] - -compileKotlin { - dependsOn tasks.getByPath('compileGroovy'), tasks.getByPath('compileScala') - dependsOn.remove('compileJava') - classpath += files(compileGroovy.destinationDir) + files(compileScala.destinationDir) -} -compileGroovy.dependsOn.remove("compileJava") -compileScala.dependsOn = [] -compileTestGroovy.dependsOn compileTestScala - -test { - useJUnitPlatform() - - // Show test results. - testLogging { - events "passed", "skipped", "failed" - } + testCompile 'org.hamcrest:hamcrest:2.1' } diff --git a/consumer/pact-jvm-consumer/src/main/groovy/au/com/dius/pact/model/MockHttpsKeystoreProviderConfig.groovy b/consumer/pact-jvm-consumer/src/main/groovy/au/com/dius/pact/model/MockHttpsKeystoreProviderConfig.groovy deleted file mode 100644 index 26371b3d46..0000000000 --- a/consumer/pact-jvm-consumer/src/main/groovy/au/com/dius/pact/model/MockHttpsKeystoreProviderConfig.groovy +++ /dev/null @@ -1,63 +0,0 @@ -package au.com.dius.pact.model - -import au.com.dius.pact.core.model.PactSpecVersion -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString - -/** - * Mock Provider configuration for HTTPS using a keystore - */ -@EqualsAndHashCode(callSuper = true) -@ToString(includeSuper = true) -@CompileStatic -class MockHttpsKeystoreProviderConfig extends MockProviderConfig { - - private final String keystore - private final String password - - MockHttpsKeystoreProviderConfig(String hostname, int port, String keystore, String password, - PactSpecVersion pactVersion) { - super(hostname, port, pactVersion, 'https') - this.keystore = keystore - this.password = password - } - - /** - * Creates instance of config - * @param hostname Name of the host to mock - * @param port Port the mock service should listen on - * @param keystore Full path (including file name) of keystore to use. - * @param password Keystore password - * @param pactVersion Version of {@link PactSpecVersion} - * @return - */ - static MockProviderConfig httpsKeystoreConfig(String hostname = 'localhost', - int port = 0, - final String keystore, - final String password, - PactSpecVersion pactVersion = PactSpecVersion.V2) { - File keystoreFile = new File(keystore) - if (!keystoreFile.isFile()) { - throw new IllegalArgumentException( - "Keystore path/file '$keystore' is not valid! It should be formatted similar to `/path/to/keystore.jks'") - } - new MockHttpsKeystoreProviderConfig(hostname, port, keystore, password, pactVersion) - } - - /** - * @return The String value of the keystore path and file. - * Example: '/path/to/keystore.jks' - */ - String getKeystore() { - keystore - } - - /** - * @return The password for the keystore - */ - String getKeystorePassword() { - password - } - -} diff --git a/consumer/pact-jvm-consumer/src/main/groovy/au/com/dius/pact/model/MockHttpsProviderConfig.groovy b/consumer/pact-jvm-consumer/src/main/groovy/au/com/dius/pact/model/MockHttpsProviderConfig.groovy deleted file mode 100644 index 0b472bd2f1..0000000000 --- a/consumer/pact-jvm-consumer/src/main/groovy/au/com/dius/pact/model/MockHttpsProviderConfig.groovy +++ /dev/null @@ -1,36 +0,0 @@ -package au.com.dius.pact.model - -import au.com.dius.pact.core.model.PactSpecVersion -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString -import io.netty.handler.ssl.util.SelfSignedCertificate - -/** - * Mock Provider configuration for HTTPS - */ -@EqualsAndHashCode(callSuper = true) -@ToString(includeSuper = true) -@CompileStatic -class MockHttpsProviderConfig extends MockProviderConfig { - - SelfSignedCertificate httpsCertificate - - MockHttpsProviderConfig(SelfSignedCertificate httpsCertificate) { - super() - this.httpsCertificate = httpsCertificate - } - - MockHttpsProviderConfig(SelfSignedCertificate httpsCertificate, - String hostname, int port, PactSpecVersion pactVersion) { - super(hostname, port, pactVersion, 'https') - this.httpsCertificate = httpsCertificate - } - - static MockProviderConfig httpsConfig(String hostname = 'localhost', int port = 0, - PactSpecVersion pactVersion = PactSpecVersion.V2) { - SelfSignedCertificate httpsCertificate = new SelfSignedCertificate() - new MockHttpsProviderConfig(httpsCertificate, hostname, port, pactVersion) - } - -} diff --git a/consumer/pact-jvm-consumer/src/main/groovy/au/com/dius/pact/model/MockProviderConfig.groovy b/consumer/pact-jvm-consumer/src/main/groovy/au/com/dius/pact/model/MockProviderConfig.groovy deleted file mode 100644 index b849294e0b..0000000000 --- a/consumer/pact-jvm-consumer/src/main/groovy/au/com/dius/pact/model/MockProviderConfig.groovy +++ /dev/null @@ -1,115 +0,0 @@ -package au.com.dius.pact.model - -import au.com.dius.pact.core.model.PactSpecVersion -import groovy.transform.Canonical -import org.apache.commons.lang3.RandomUtils - -/** - * Configuration of the Pact Mock Server. - * - * By default this class will setup the configuration for a http mock server running on - * local host and a random port - */ -@Canonical -@SuppressWarnings('FactoryMethodName') -class MockProviderConfig { - public static final String LOCALHOST = '127.0.0.1' - private static final String HTTP = 'http' - - String hostname = LOCALHOST - int port = 0 - PactSpecVersion pactVersion = PactSpecVersion.V3 - String scheme = HTTP - - String url() { - "$scheme://$hostname:$port" - } - - static MockProviderConfig httpConfig(String hostname = LOCALHOST, int port = 0, - PactSpecVersion pactVersion = PactSpecVersion.V3) { - new MockProviderConfig(hostname, port, pactVersion, HTTP) - } - - static MockProviderConfig createDefault() { - createDefault(LOCALHOST, PactSpecVersion.V3) - } - - static MockProviderConfig createDefault(PactSpecVersion pactVersion) { - createDefault(LOCALHOST, pactVersion) - } - - /** - * @deprecated Set the port to zero to get the OS to assign a random port - */ - @Deprecated - @SuppressWarnings('FieldName') - public static final int portLowerBound = 20000 - /** - * @deprecated Set the port to zero to get the OS to assign a random port - */ - @Deprecated - @SuppressWarnings('FieldName') - public static final int portUpperBound = 40000 - - static MockProviderConfig createDefault(String host, PactSpecVersion pactVersion) { - new MockProviderConfig(host, randomPort(portLowerBound, portUpperBound), pactVersion) - } - - /** - * @deprecated Set the port to zero to get the OS to assign a random port - */ - @Deprecated - static MockProviderConfig create(int lower, int upper, PactSpecVersion pactVersion) { - new MockProviderConfig(LOCALHOST, randomPort(lower, upper), pactVersion) - } - - /** - * @deprecated Set the port to zero to get the OS to assign a random port - */ - @Deprecated - static MockProviderConfig create(String hostname, int lower, int upper, PactSpecVersion pactVersion) { - new MockProviderConfig(hostname, randomPort(lower, upper), pactVersion) - } - - /** - * @deprecated Set the port to zero to get the OS to assign a random port - */ - @Deprecated - static int randomPort(int lower, int upper) { - Integer port = null - int count = 0 - while (port == null && count < 20) { - int randomPort = RandomUtils.nextInt(lower, upper) - if (portAvailable(randomPort)) { - port = randomPort - } - count++ - } - - if (port == null) { - port = 0 - } - - port - } - - private static boolean portAvailable(int p) { - ServerSocket socket = null - try { - socket = new ServerSocket(p) - true - } catch (IOException ignored) { - false - } finally { - if (socket != null) { - try { - socket.close() - } catch (ignored) { } - } - } - } - - InetSocketAddress address() { - new InetSocketAddress(hostname, port) - } -} diff --git a/consumer/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/TestRun.java b/consumer/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/TestRun.java index 1d1d2951e4..619f70f79a 100644 --- a/consumer/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/TestRun.java +++ b/consumer/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/TestRun.java @@ -1,6 +1,6 @@ package au.com.dius.pact.consumer; -import au.com.dius.pact.model.MockProviderConfig; +import au.com.dius.pact.consumer.model.MockProviderConfig; public interface TestRun { void run(MockProviderConfig config) throws Throwable; diff --git a/consumer/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslResponse.java b/consumer/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslResponse.java index 5c66a0297b..169e6e3ddd 100644 --- a/consumer/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslResponse.java +++ b/consumer/pact-jvm-consumer/src/main/java/au/com/dius/pact/consumer/dsl/PactDslResponse.java @@ -2,7 +2,6 @@ import au.com.dius.pact.consumer.ConsumerPactBuilder; import au.com.dius.pact.core.model.OptionalBody; -import au.com.dius.pact.model.PactFragment; import au.com.dius.pact.core.model.ProviderState; import au.com.dius.pact.core.model.Request; import au.com.dius.pact.core.model.RequestResponseInteraction; @@ -18,7 +17,6 @@ import org.apache.http.entity.ContentType; import org.json.JSONObject; import org.w3c.dom.Document; -import scala.collection.JavaConversions$; import javax.xml.transform.TransformerException; import java.util.Collections; @@ -275,19 +273,6 @@ private void addInteraction() { )); } - /** - * Terminates the DSL and builds a pact fragment to represent the interactions - * - * @deprecated Use toPact instead - */ - public PactFragment toFragment() { - addInteraction(); - return new PactFragment( - request.consumer, - request.provider, - JavaConversions$.MODULE$.asScalaBuffer(consumerPactBuilder.getInteractions()).toSeq()); - } - /** * Terminates the DSL and builds a pact to represent the interactions */ diff --git a/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/ConsumerPactRunner.kt b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/ConsumerPactRunner.kt index c849ad8dee..61bac6b905 100644 --- a/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/ConsumerPactRunner.kt +++ b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/ConsumerPactRunner.kt @@ -1,6 +1,6 @@ package au.com.dius.pact.consumer -import au.com.dius.pact.model.MockProviderConfig +import au.com.dius.pact.consumer.model.MockProviderConfig import au.com.dius.pact.core.model.RequestResponsePact interface PactTestRun { diff --git a/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/MockHttpServer.kt b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/MockHttpServer.kt index 7796037d56..04c6dc3afb 100755 --- a/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/MockHttpServer.kt +++ b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/MockHttpServer.kt @@ -11,8 +11,8 @@ import au.com.dius.pact.core.model.RequestResponsePact import au.com.dius.pact.core.model.Response import au.com.dius.pact.core.model.generators.GeneratorTestMode import au.com.dius.pact.core.model.queryStringToMap -import au.com.dius.pact.model.MockHttpsProviderConfig -import au.com.dius.pact.model.MockProviderConfig +import au.com.dius.pact.consumer.model.MockHttpsProviderConfig +import au.com.dius.pact.consumer.model.MockProviderConfig import com.sun.net.httpserver.HttpExchange import com.sun.net.httpserver.HttpHandler import com.sun.net.httpserver.HttpServer diff --git a/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/ScalaCollectionUtils.kt b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/ScalaCollectionUtils.kt deleted file mode 100644 index e3b878fe9c..0000000000 --- a/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/ScalaCollectionUtils.kt +++ /dev/null @@ -1,16 +0,0 @@ -package au.com.dius.pact.consumer - -import au.com.dius.pact.core.matchers.Mismatch -import scala.Option -import scala.collection.JavaConversions -import scala.collection.Seq - -object ScalaCollectionUtils { - fun toList(mismatches: Option>?): List { - return if (mismatches != null && mismatches.isDefined) { - JavaConversions.seqAsJavaList(mismatches.get()) - } else { - listOf() - } - } -} diff --git a/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockHttpsKeystoreProviderConfig.kt b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockHttpsKeystoreProviderConfig.kt new file mode 100644 index 0000000000..d4cf0ed900 --- /dev/null +++ b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockHttpsKeystoreProviderConfig.kt @@ -0,0 +1,46 @@ +package au.com.dius.pact.consumer.model + +import au.com.dius.pact.core.model.PactSpecVersion +import java.io.File + +/** + * Mock Provider configuration for HTTPS using a keystore + */ +class MockHttpsKeystoreProviderConfig( + val keystore: String, + val password: String, + override val hostname: String = LOCALHOST, + override val port: Int = 0, + override val pactVersion: PactSpecVersion = PactSpecVersion.V3, + override val scheme: String = "https" +) : MockProviderConfig(hostname, port, pactVersion, scheme) { + + companion object { + + /** + * Creates instance of config + * @param hostname Name of the host to mock + * @param port Port the mock service should listen on + * @param keystore Full path (including file name) of keystore to use. + * @param password Keystore password + * @param pactVersion Version of {@link PactSpecVersion} + * @return + */ + @JvmOverloads + @JvmStatic + fun httpsKeystoreConfig( + hostname: String = LOCALHOST, + port: Int = 0, + keystore: String, + password: String, + pactVersion: PactSpecVersion = PactSpecVersion.V2 + ): MockProviderConfig { + val keystoreFile = File(keystore) + if (!keystoreFile.isFile) { + throw IllegalArgumentException( + "Keystore path/file '$keystore' is not valid! It should be formatted similar to `/path/to/keystore.jks'") + } + return MockHttpsKeystoreProviderConfig(keystore, password, hostname, port, pactVersion) + } + } +} diff --git a/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockHttpsProviderConfig.kt b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockHttpsProviderConfig.kt new file mode 100644 index 0000000000..e1f944c2d4 --- /dev/null +++ b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockHttpsProviderConfig.kt @@ -0,0 +1,23 @@ +package au.com.dius.pact.consumer.model + +import au.com.dius.pact.core.model.PactSpecVersion +import io.netty.handler.ssl.util.SelfSignedCertificate + +/** + * Mock Provider configuration for HTTPS + */ +class MockHttpsProviderConfig( + val httpsCertificate: SelfSignedCertificate, + override val hostname: String = LOCALHOST, + override val port: Int = 0, + override val pactVersion: PactSpecVersion = PactSpecVersion.V3, + override val scheme: String = HTTP +) : MockProviderConfig(hostname, port, pactVersion, scheme) { + + companion object { + @JvmStatic + @JvmOverloads + fun httpsConfig(hostname: String = LOCALHOST, port: Int = 0, pactVersion: PactSpecVersion = PactSpecVersion.V3) = + MockHttpsProviderConfig(SelfSignedCertificate(), hostname, port, pactVersion) + } +} diff --git a/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockProviderConfig.kt b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockProviderConfig.kt new file mode 100644 index 0000000000..336cedffb9 --- /dev/null +++ b/consumer/pact-jvm-consumer/src/main/kotlin/au/com/dius/pact/consumer/model/MockProviderConfig.kt @@ -0,0 +1,44 @@ +package au.com.dius.pact.consumer.model + +import au.com.dius.pact.core.model.PactSpecVersion +import java.net.InetSocketAddress + +/** + * Configuration of the Pact Mock Server. + * + * By default this class will setup the configuration for a http mock server running on + * local host and a random port + */ +open class MockProviderConfig @JvmOverloads constructor ( + open val hostname: String = LOCALHOST, + open val port: Int = 0, + open val pactVersion: PactSpecVersion = PactSpecVersion.V3, + open val scheme: String = HTTP +) { + + fun url() = "$scheme://$hostname:$port" + + fun address() = InetSocketAddress(hostname, port) + + companion object { + const val LOCALHOST = "127.0.0.1" + const val HTTP = "http" + + @JvmStatic + fun httpConfig( + hostname: String = LOCALHOST, + port: Int = 0, + pactVersion: PactSpecVersion = PactSpecVersion.V3 + ) = MockProviderConfig(hostname, port, pactVersion, HTTP) + + @JvmStatic + fun createDefault() = createDefault(LOCALHOST, PactSpecVersion.V3) + + @JvmStatic + fun createDefault(pactVersion: PactSpecVersion) = createDefault(LOCALHOST, pactVersion) + + @JvmStatic + fun createDefault(host: String, pactVersion: PactSpecVersion) = + MockProviderConfig(hostname = host, pactVersion = pactVersion) + } +} diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/package.scala b/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/package.scala deleted file mode 100644 index 70ee822c72..0000000000 --- a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/consumer/package.scala +++ /dev/null @@ -1,5 +0,0 @@ -package au.com.dius.pact - -package object consumer { - type ConsumerTestVerification[T] = T => Option[T] -} diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/CollectionUtils.scala b/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/CollectionUtils.scala deleted file mode 100644 index f68723d655..0000000000 --- a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/CollectionUtils.scala +++ /dev/null @@ -1,40 +0,0 @@ -package au.com.dius.pact.model - -import java.util - -import scala.collection.JavaConversions - -object CollectionUtils { - def javaMMapToScalaMMap(map: java.util.Map[String, java.util.Map[String, AnyRef]]) : Map[String, Map[String, Any]] = { - if (map != null) { - JavaConversions.mapAsScalaMap(map).mapValues { - case jmap: java.util.Map[String, _] => JavaConversions.mapAsScalaMap(jmap).toMap - }.toMap - } else { - Map() - } - } - - def javaLMapToScalaLMap(map: java.util.Map[String, java.util.List[String]]) : Map[String, List[String]] = { - if (map != null) { - JavaConversions.mapAsScalaMap(map).mapValues { - case jlist: java.util.List[String] => JavaConversions.collectionAsScalaIterable(jlist).toList - }.toMap - } else { - Map() - } - } - - def scalaMMapToJavaMMap(map: Map[String, Map[String, AnyRef]]) : java.util.Map[String, java.util.Map[String, AnyRef]] = { - JavaConversions.mapAsJavaMap(map.mapValues { - case jmap: Map[String, _] => JavaConversions.mapAsJavaMap(jmap) - }) - } - - def scalaLMaptoJavaLMap(map: Map[String, List[String]]): util.Map[String, util.List[String]] = { - JavaConversions.mapAsJavaMap(map.mapValues { - case jlist: List[String] => JavaConversions.seqAsJavaList(jlist.toSeq) - }) - } - -} diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/PactFragment.scala b/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/PactFragment.scala deleted file mode 100644 index da18a3206e..0000000000 --- a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/PactFragment.scala +++ /dev/null @@ -1,48 +0,0 @@ -package au.com.dius.pact.model - -import au.com.dius.pact.consumer._ -import au.com.dius.pact.core.model.{Consumer, Provider, RequestResponseInteraction, RequestResponsePact} - -/** - * @deprecated Moved to Kotlin implementation: Use Pact interface instead - */ -@Deprecated -case class PactFragment(consumer: Consumer, - provider: Provider, - interactions: Seq[RequestResponseInteraction]) { - import scala.collection.JavaConversions._ - @Deprecated - def toPact = new RequestResponsePact(provider, consumer, interactions) - - @Deprecated - def duringConsumerSpec[T](config: MockProviderConfig)(test: => T, verification: ConsumerTestVerification[T]): VerificationResult = { - val server = DefaultMockProvider(config) - new ConsumerPactRunner(server).runAndWritePact(toPact, config.getPactVersion)(test, verification) - } - - //TODO: it would be a good idea to ensure that all interactions in the fragment have the same state - // really? why? - @Deprecated - def defaultState: Option[String] = interactions.headOption.map(_.getProviderState) - - @Deprecated - def runConsumer(config: MockProviderConfig, test: TestRun): VerificationResult = { - duringConsumerSpec(config)(test.run(config), (u:Unit) => None) - } - - @Deprecated - def description = s"Consumer '${consumer.getName}' has a pact with Provider '${provider.getName}': " + - interactions.map { i => i.getDescription }.mkString(" and ") + sys.props("line.separator") - -} - -/** - * @deprecated Moved to Kotlin implementation - */ -@Deprecated -object PactFragment { - @Deprecated - def consumer(consumer: String) = { - PactFragmentBuilder.apply(new Consumer(consumer)) - } -} diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/PactFragmentBuilder.scala b/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/PactFragmentBuilder.scala deleted file mode 100644 index 1ea24715a9..0000000000 --- a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/PactFragmentBuilder.scala +++ /dev/null @@ -1,182 +0,0 @@ -package au.com.dius.pact.model - -import au.com.dius.pact.consumer.dsl.DslPart -import au.com.dius.pact.consumer.{ConsumerTestVerification, VerificationResult} -import au.com.dius.pact.core.model._ -import au.com.dius.pact.core.model.matchingrules.{MatchingRules, MatchingRulesImpl} -import org.json.JSONObject - -/** - * @deprecated Moved to Kotlin implementation - */ -@Deprecated -object PactFragmentBuilder { - @Deprecated - def apply(consumer: Consumer) = { - WithConsumer(consumer) - } - - @Deprecated - case class WithConsumer(consumer: Consumer) { - import scala.collection.JavaConversions._ - - @Deprecated - def hasPactWith(provider: String) = { - WithProvider(new Provider(provider)) - } - - @Deprecated - case class WithProvider(provider: Provider) { - @Deprecated - def given(state: String) = { - InState(List(new ProviderState(state))) - } - - @Deprecated - def given(state: String, params: Map[String, String]) = { - InState(List(new ProviderState(state))) - } - - @Deprecated - def uponReceiving(description: String) = { - InState(List()).uponReceiving(description) - } - - @Deprecated - case class InState(state: List[ProviderState]) { - - @Deprecated - def given(stateDesc: String, params: Map[String, String]) = { - InState(state.+:(new ProviderState(stateDesc, params))) - } - - @Deprecated - def uponReceiving(description: String) = { - DescribingRequest(consumer, provider, state, description) - } - } - } - } - - @Deprecated - case class DescribingRequest(consumer: Consumer, provider: Provider, state: List[ProviderState], description: String, - builder: CanBuildPactFragment.Builder = CanBuildPactFragment.firstBuild) { - import scala.collection.JavaConversions._ - import scala.collection.JavaConverters._ - - /** - * supports java DSL - */ - @Deprecated - def matching(path: String, method: String, query: String, headers: java.util.Map[String, String], body: String, - matchers: java.util.Map[String, Any]): DescribingResponse = { - import collection.JavaConversions._ - matching(path, method, query, headers.toMap, body, matchers.toMap.asInstanceOf[Map[String, Map[String, String]]]) - } - - @Deprecated - def matching(path: String, - method: String = "GET", - query: String = "", - headers: Map[String, List[String]] = Map(), - body: String = "", - matchers: MatchingRules = new MatchingRulesImpl()): DescribingResponse = { - DescribingResponse(new Request(method, path, PactReaderKt.queryStringToMap(query), headers.mapValues(f => f.asJava).asJava, OptionalBody.body(body.getBytes), - matchers)) - } - - @Deprecated - case class DescribingResponse(request: Request) { - /** - * supports java DSL - */ - @Deprecated - def willRespondWith(status: Int, headers: java.util.Map[String, String], maybeBody: Option[String], matchers: JSONObject): PactWithAtLeastOneRequest = { - import collection.JavaConversions._ - willRespondWith(status, headers.toMap, maybeBody, matchers) - } - - @Deprecated - def willRespondWith(status: Int = 200, - headers: Map[String, List[String]] = Map(), - maybeBody: Option[String] = None, - matchers: MatchingRules = new MatchingRulesImpl()): PactWithAtLeastOneRequest = { - val optionalBody = maybeBody match { - case Some(body) => OptionalBody.body(body.getBytes) - case None => OptionalBody.missing() - } - - builder( - consumer, - provider, - state, - Seq(new RequestResponseInteraction( - description, - state.asJava, - request, - new Response(status, headers.mapValues(f => f.asJava).asJava, optionalBody, matchers)))) - } - - @Deprecated - def willRespondWith(status: Int, - headers: Map[String, List[String]], - bodyAndMatchers: DslPart): PactWithAtLeastOneRequest = { - val rules = new MatchingRulesImpl() - rules.addCategory(bodyAndMatchers.getMatchers) - builder( - consumer, - provider, - state, - Seq(new RequestResponseInteraction( - description, - state.asJava, - request, - new Response(status, headers.mapValues(f => f.asJava).asJava, OptionalBody.body(bodyAndMatchers.toString.getBytes), rules)))) - } - } - } - - @Deprecated - case class PactWithAtLeastOneRequest(consumer: Consumer, provider:Provider, state: List[ProviderState], interactions: Seq[RequestResponseInteraction]) { - import scala.collection.JavaConversions._ - - def given() = { - InState(List(), this) - } - - def given(newState: String) = { - InState(List(new ProviderState(newState)), this) - } - - def given(state: String, params: Map[String, String]) = { - InState(List(new ProviderState(state, params)), this) - } - - def uponReceiving(description: String) = { - DescribingRequest(consumer, provider, state, description, CanBuildPactFragment.additionalBuild(this)) - } - - def duringConsumerSpec[T](config: MockProviderConfig)(test: => T, verification: ConsumerTestVerification[T]): VerificationResult = { - PactFragment(consumer, provider, interactions).duringConsumerSpec(config)(test, verification) - } - - def asPactFragment() = { - PactFragment(consumer, provider, interactions) - } - - case class InState(newState: List[ProviderState], pactWithAtLeastOneRequest: PactWithAtLeastOneRequest) { - def uponReceiving(description: String) = { - DescribingRequest(consumer, provider, newState, description, CanBuildPactFragment.additionalBuild(pactWithAtLeastOneRequest)) - } - } - } - - @Deprecated - object CanBuildPactFragment { - type Builder = (Consumer, Provider, List[ProviderState], Seq[RequestResponseInteraction]) => PactWithAtLeastOneRequest - - val firstBuild: Builder = PactWithAtLeastOneRequest.apply - - def additionalBuild(existing: PactWithAtLeastOneRequest): Builder = (_,_,_,i) => existing.copy(interactions = existing.interactions ++ i) - } -} diff --git a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/unfiltered/Conversions.scala b/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/unfiltered/Conversions.scala deleted file mode 100644 index 4818b1fe34..0000000000 --- a/consumer/pact-jvm-consumer/src/main/scala/au/com/dius/pact/model/unfiltered/Conversions.scala +++ /dev/null @@ -1,59 +0,0 @@ -package au.com.dius.pact.model.unfiltered - -import java.net.URI -import java.util.zip.GZIPInputStream - -import au.com.dius.pact.core.model.OptionalBody -import au.com.dius.pact.core.model.{Request, Response} -import com.typesafe.scalalogging.StrictLogging -import io.netty.handler.codec.http.{HttpResponse => NHttpResponse} -import unfiltered.netty.ReceivedMessage -import unfiltered.request.HttpRequest -import unfiltered.response._ - -import scala.collection.JavaConversions -import scala.collection.JavaConverters._ - -@Deprecated -object Conversions extends StrictLogging { - - case class Headers(headers: java.util.Map[String, java.util.List[String]]) extends unfiltered.response.Responder[Any] { - def respond(res: HttpResponse[Any]) { - if (headers != null) { - headers.asScala.foreach { case (key, value) => res.header(key, value.asScala.mkString(", ")) } - } - } - } - - implicit def pactToUnfilteredResponse(response: Response): ResponseFunction[NHttpResponse] = { - val headers = response.getHeaders - if (response.getBody.isPresent) { - Status(response.getStatus) ~> Headers(headers) ~> ResponseString(response.getBody.valueAsString) - } else Status(response.getStatus) ~> Headers(headers) - } - - def toHeaders(request: HttpRequest[ReceivedMessage]): java.util.Map[String, java.util.List[String]] = { - request.headerNames.map(name => name -> request.headers(name).toList.asJava).toMap.asJava - } - - def toQuery(request: HttpRequest[ReceivedMessage]): java.util.Map[String, java.util.List[String]] = { - JavaConversions.mapAsJavaMap(request.parameterNames.map(name => - name -> JavaConversions.seqAsJavaList(request.parameterValues(name))).toMap) - } - - def toPath(uri: String) = new URI(uri).getPath - - def toBody(request: HttpRequest[ReceivedMessage], charset: String = "UTF-8") = { - val is = if (request.headers(ContentEncoding.GZip.name).contains("gzip")) { - new GZIPInputStream(request.inputStream) - } else { - request.inputStream - } - if(is == null) "" else scala.io.Source.fromInputStream(is).mkString - } - - implicit def unfilteredRequestToPactRequest(request: HttpRequest[ReceivedMessage]): Request = { - new Request(request.method, toPath(request.uri), toQuery(request), toHeaders(request), - OptionalBody.body(toBody(request).getBytes)) - } -} diff --git a/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/consumer/MockHttpServerSpec.groovy b/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/consumer/MockHttpServerSpec.groovy index d47e32b155..7e36e96fd2 100644 --- a/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/consumer/MockHttpServerSpec.groovy +++ b/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/consumer/MockHttpServerSpec.groovy @@ -1,7 +1,7 @@ package au.com.dius.pact.consumer import au.com.dius.pact.core.model.Consumer -import au.com.dius.pact.model.MockProviderConfig +import au.com.dius.pact.consumer.model.MockProviderConfig import au.com.dius.pact.core.model.Provider import au.com.dius.pact.core.model.RequestResponsePact import spock.lang.IgnoreIf diff --git a/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/consumer/MockProviderConfigSpec.groovy b/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/consumer/MockProviderConfigSpec.groovy deleted file mode 100644 index 7891a9a6aa..0000000000 --- a/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/consumer/MockProviderConfigSpec.groovy +++ /dev/null @@ -1,13 +0,0 @@ -package au.com.dius.pact.consumer - -import au.com.dius.pact.model.MockProviderConfig -import au.com.dius.pact.core.model.PactSpecVersion -import spock.lang.Specification - -class MockProviderConfigSpec extends Specification { - def "port server config - select a random port"() { - expect: - MockProviderConfig.createDefault(PactSpecVersion.V3).port >= MockProviderConfig.portLowerBound - MockProviderConfig.createDefault(PactSpecVersion.V3).port <= MockProviderConfig.portUpperBound - } -} diff --git a/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/model/unfiltered/ConversionsSpec.groovy b/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/model/unfiltered/ConversionsSpec.groovy deleted file mode 100644 index 028f9a9c1e..0000000000 --- a/consumer/pact-jvm-consumer/src/test/groovy/au/com/dius/pact/model/unfiltered/ConversionsSpec.groovy +++ /dev/null @@ -1,86 +0,0 @@ -package au.com.dius.pact.model.unfiltered - -import scala.collection.JavaConverters -import spock.lang.Specification -import unfiltered.netty.ReceivedMessage -import unfiltered.request.HttpRequest - -@SuppressWarnings('LineLength') -class ConversionsSpec extends Specification { - - HttpRequest request - - def setup() { - request = Mock { - headerNames() >> JavaConverters.asScalaIterator(['Accept'].iterator()) - headers(_) >> { args -> - if (args[0] == 'Accept') { - JavaConverters.asScalaIterator(['application/json'].iterator()) - } else if (args[0] == 'Content-Encoding') { - JavaConverters.asScalaIterator([].iterator()) - } - } - reader() >> new StringReader('') - } - } - - def 'converting an unfiltered request to a pact request - construct the pact request correctly - with a query string'() { - given: - request.parameterNames() >> JavaConverters.asScalaIterator(['a', 'b'].iterator()) - request.parameterValues(_) >> { args -> - if (args[0] == 'a') { - JavaConverters.asScalaBuffer(['1']).toSeq() - } else if (args[0] == 'b') { - JavaConverters.asScalaBuffer(['2']).toSeq() - } - } - request.uri() >> '/path?a=1&b=2' - - when: - def pactRequest = Conversions.unfilteredRequestToPactRequest(request) - - then: - pactRequest.path == '/path' - pactRequest.query == [a: ['1'], b: ['2']] - } - - def 'converting an unfiltered request to a pact request - construct the pact request correctly - with no query string'() { - given: - request.parameterNames() >> JavaConverters.asScalaIterator([].iterator()) - request.uri() >> '/path' - - when: - def pactRequest = Conversions.unfilteredRequestToPactRequest(request) - - then: - pactRequest.path == '/path' - pactRequest.query.isEmpty() - } - - def 'converting an unfiltered request to a pact request - construct the pact request correctly - with a path ending with a question mark'() { - given: - request.parameterNames() >> JavaConverters.asScalaIterator([].iterator()) - request.uri() >> '/path?' - - when: - def pactRequest = Conversions.unfilteredRequestToPactRequest(request) - - then: - pactRequest.path == '/path' - pactRequest.query.isEmpty() - } - - def 'converting an unfiltered request to a pact request - construct the pact request correctly - with a path with strings in it'() { - given: - request.parameterNames() >> JavaConverters.asScalaIterator([].iterator()) - request.uri() >> '/some+path' - - when: - def pactRequest = Conversions.unfilteredRequestToPactRequest(request) - - then: - pactRequest.path == '/some+path' - pactRequest.query.isEmpty() - } - -} diff --git a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/MatchingTest.java b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/MatchingTest.java index 5766ea5399..98274b936d 100644 --- a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/MatchingTest.java +++ b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/MatchingTest.java @@ -2,12 +2,11 @@ import au.com.dius.pact.consumer.dsl.PactDslJsonBody; import au.com.dius.pact.consumer.dsl.PactDslResponse; -import au.com.dius.pact.model.MockProviderConfig; +import au.com.dius.pact.consumer.model.MockProviderConfig; import au.com.dius.pact.core.model.PactSpecVersion; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.http.entity.ContentType; -import org.jetbrains.annotations.NotNull; import org.json.JSONObject; import org.junit.Assert; import org.junit.Test; @@ -142,7 +141,7 @@ private void runTest(PactDslResponse pactFragment, final String body, final Map MockProviderConfig config = MockProviderConfig.createDefault(PactSpecVersion.V3); PactVerificationResult result = runConsumerTest(pactFragment.toPact(), config, (mockServer, context) -> { try { - Assert.assertEquals(expectedResponse, new ConsumerClient(config.url()).post(path, body, ContentType.APPLICATION_JSON)); + Assert.assertEquals(expectedResponse, new ConsumerClient(mockServer.getUrl()).post(path, body, ContentType.APPLICATION_JSON)); } catch (IOException e) { LOGGER.error(e.getMessage(), e); throw e; diff --git a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/MimeTypeTest.java b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/MimeTypeTest.java index bfe7d705f4..51004457b1 100644 --- a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/MimeTypeTest.java +++ b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/MimeTypeTest.java @@ -1,7 +1,7 @@ package au.com.dius.pact.consumer; import au.com.dius.pact.consumer.dsl.PactDslJsonBody; -import au.com.dius.pact.model.MockProviderConfig; +import au.com.dius.pact.consumer.model.MockProviderConfig; import au.com.dius.pact.core.model.PactSpecVersion; import au.com.dius.pact.core.model.RequestResponsePact; import org.apache.http.entity.ContentType; @@ -64,14 +64,11 @@ public void testMatchingXml() { private void runTest(RequestResponsePact pact, final String body, final String expectedResponse, final ContentType mimeType) { MockProviderConfig config = MockProviderConfig.createDefault(PactSpecVersion.V3); - PactVerificationResult result = runConsumerTest(pact, config, new PactTestRun() { - @Override - public void run(@NotNull MockServer mockServer, PactTestExecutionContext context) throws IOException { - try { - assertEquals(new ConsumerClient(config.url()).postBody("/hello", body, mimeType), expectedResponse); - } catch (IOException e) { - LOGGER.error(e.getMessage(), e); - } + PactVerificationResult result = runConsumerTest(pact, config, (mockServer, context) -> { + try { + assertEquals(new ConsumerClient(mockServer.getUrl()).postBody("/hello", body, mimeType), expectedResponse); + } catch (IOException e) { + LOGGER.error(e.getMessage(), e); } }); diff --git a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactDefectTest.java b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactDefectTest.java index ec0e520c8b..7b1b4ab563 100644 --- a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactDefectTest.java +++ b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactDefectTest.java @@ -1,6 +1,6 @@ package au.com.dius.pact.consumer; -import au.com.dius.pact.model.MockProviderConfig; +import au.com.dius.pact.consumer.model.MockProviderConfig; import au.com.dius.pact.core.model.PactSpecVersion; import au.com.dius.pact.core.model.RequestResponsePact; import org.jetbrains.annotations.NotNull; diff --git a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactQueryParameterTest.java b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactQueryParameterTest.java index 5fdad2d06f..b43225fc3c 100644 --- a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactQueryParameterTest.java +++ b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactQueryParameterTest.java @@ -1,7 +1,7 @@ package au.com.dius.pact.consumer; import au.com.dius.pact.core.model.RequestResponsePact; -import au.com.dius.pact.model.MockProviderConfig; +import au.com.dius.pact.consumer.model.MockProviderConfig; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.client.fluent.Request; import org.apache.http.util.EntityUtils; diff --git a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactTest.java b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactTest.java index 74398aaf1f..d70cf7dd2d 100644 --- a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactTest.java +++ b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PactTest.java @@ -1,7 +1,7 @@ package au.com.dius.pact.consumer; import au.com.dius.pact.core.model.RequestResponsePact; -import au.com.dius.pact.model.MockProviderConfig; +import au.com.dius.pact.consumer.model.MockProviderConfig; import org.apache.http.entity.ContentType; import org.jetbrains.annotations.NotNull; import org.junit.Test; diff --git a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PerfTest.java b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PerfTest.java index 3ecd51158d..6c720a9c93 100644 --- a/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PerfTest.java +++ b/consumer/pact-jvm-consumer/src/test/java/au/com/dius/pact/consumer/PerfTest.java @@ -1,7 +1,7 @@ package au.com.dius.pact.consumer; -import au.com.dius.pact.model.MockProviderConfig; -import au.com.dius.pact.model.PactFragment; +import au.com.dius.pact.consumer.model.MockProviderConfig; +import au.com.dius.pact.core.model.RequestResponsePact; import org.apache.commons.lang3.time.StopWatch; import org.jetbrains.annotations.NotNull; import org.json.JSONObject; @@ -34,7 +34,7 @@ public void test() { stopWatch.split(); System.out.println("Setup: " + stopWatch.getSplitTime()); - PactFragment pactFragment = ConsumerPactBuilder + RequestResponsePact pact = ConsumerPactBuilder .consumer("perf_test_consumer") .hasPactWith("perf_test_provider") .uponReceiving("a request to get values") @@ -44,24 +44,21 @@ public void test() { .status(200) .headers(headerData) .body(bodyExpected) - .toFragment(); + .toPact(); stopWatch.split(); System.out.println("Setup Fragment: " + stopWatch.getSplitTime()); MockProviderConfig config = MockProviderConfig.createDefault(); - PactVerificationResult result = runConsumerTest(pactFragment.toPact(), config, new PactTestRun() { - @Override - public void run(@NotNull MockServer mockServer, PactTestExecutionContext context) throws IOException { - try { - stopWatch.split(); - System.out.println("In Test: " + stopWatch.getSplitTime()); - new ConsumerClient(config.url()).getAsList(path); - } catch (IOException e) { - } + runConsumerTest(pact, config, (mockServer, context) -> { + try { stopWatch.split(); - System.out.println("After Test: " + stopWatch.getSplitTime()); + System.out.println("In Test: " + stopWatch.getSplitTime()); + new ConsumerClient(config.url()).getAsList(path); + } catch (IOException e) { } + stopWatch.split(); + System.out.println("After Test: " + stopWatch.getSplitTime()); }); stopWatch.split(); diff --git a/core/matchers/build.gradle b/core/matchers/build.gradle index 80970c5a11..f0016f0197 100755 --- a/core/matchers/build.gradle +++ b/core/matchers/build.gradle @@ -11,12 +11,3 @@ dependencies { testRuntime "org.junit.jupiter:junit-jupiter-engine:${project.junit5Version}" testRuntime "org.junit.vintage:junit-vintage-engine:${project.junit5Version}" } - -test { - useJUnitPlatform() - - // Show test results. - testLogging { - events "passed", "skipped", "failed" - } -} diff --git a/settings.gradle b/settings.gradle index b050306c29..ceec73525f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,8 +13,6 @@ project(':core:pact-jvm-core-matchers').projectDir = file('core/matchers') include 'consumer:pact-jvm-consumer' -project(':consumer:pact-jvm-consumer').projectDir = file('consumer') - //include 'pact-jvm-consumer-junit' //include 'pact-jvm-consumer-junit5' //include 'pact-jvm-consumer-java8'