Skip to content

Commit

Permalink
Single import test module (#182)
Browse files Browse the repository at this point in the history
* new module added scalapact-scalatest-suite
  • Loading branch information
jbwheatley authored Oct 19, 2020
1 parent d02df52 commit cbdbb74
Show file tree
Hide file tree
Showing 26 changed files with 378 additions and 296 deletions.
16 changes: 15 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,20 @@ lazy val framework =
)
.dependsOn(core)

lazy val frameworkWithDeps =
(project in file("scalapact-scalatest-suite"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "scalapact-scalatest-suite",
mappings in (Compile, packageBin) ~= {
_.filterNot { case (_, fileName) => fileName == "logback.xml" || fileName == "log4j.properties" }
}
)
.dependsOn(framework)
.dependsOn(circe13)
.dependsOn(http4s021)

lazy val standalone =
(project in file("scalapact-standalone-stubber"))
.settings(commonSettings: _*)
Expand Down Expand Up @@ -480,7 +494,7 @@ lazy val scalaPactProject =
.aggregate(shared, core, pluginShared, plugin, pluginNoDeps, framework, testShared)
.aggregate(http4s016a, http4s017, http4s018, http4s020, http4s021)
.aggregate(argonaut62, circe08, circe09, circe10, circe11, circe12, circe13)
.aggregate(standalone)
.aggregate(standalone, frameworkWithDeps)
.aggregate(docs)
.aggregate(pactSpec, testsWithDeps)

Expand Down
1 change: 1 addition & 0 deletions example/consumer/pact.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//For publishing to pact-broker test server (these credentials are public knowledge)
import scala.concurrent.duration._

import scala.concurrent.duration._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,6 @@
"name" : "scala-pact-consumer"
},
"interactions" : [
{
"providerState" : "Results: Bob, Fred, Harry",
"description" : "Fetching results",
"request" : {
"method" : "GET",
"path" : "/results"
},
"response" : {
"status" : 200,
"headers" : {
"Pact" : "modifiedRequest"
},
"body" : {
"count" : 3,
"results" : [
"Bob",
"Fred",
"Harry"
]
}
}
},
{
"description" : "Fetching least secure auth token ever",
"request" : {
Expand Down Expand Up @@ -59,6 +37,28 @@
}
}
}
},
{
"providerState" : "Results: Bob, Fred, Harry",
"description" : "Fetching results",
"request" : {
"method" : "GET",
"path" : "/results"
},
"response" : {
"status" : 200,
"headers" : {
"Pact" : "modifiedRequest"
},
"body" : {
"count" : 3,
"results" : [
"Bob",
"Fred",
"Harry"
]
}
}
}
],
"metadata" : {
Expand Down
14 changes: 6 additions & 8 deletions example/provider_pact-for-verification/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ libraryDependencies ++= {
//A hack so we don't have to manually update the scala-pact version for the examples
lazy val pactVersion = IO.read(pactVersionFile.value).split('"')(1)
Seq(
"org.http4s" %% "http4s-blaze-server" % "0.21.7",
"org.http4s" %% "http4s-dsl" % "0.21.7",
"org.http4s" %% "http4s-circe" % "0.21.7",
"org.slf4j" % "slf4j-simple" % "1.6.4",
"org.scalatest" %% "scalatest" % "3.0.8" % "test",
"com.itv" %% "scalapact-circe-0-13" % pactVersion % "test",
"com.itv" %% "scalapact-http4s-0-21" % pactVersion % "test",
"com.itv" %% "scalapact-scalatest" % pactVersion % "test",
"org.http4s" %% "http4s-blaze-server" % "0.21.7",
"org.http4s" %% "http4s-dsl" % "0.21.7",
"org.http4s" %% "http4s-circe" % "0.21.7",
"org.slf4j" % "slf4j-simple" % "1.6.4",
"org.scalatest" %% "scalatest" % "3.0.8" % "test",
"com.itv" %% "scalapact-scalatest-suite" % pactVersion % "test",
// Optional for auto-derivation of JSON codecs
"io.circe" %% "circe-generic" % "0.13.0",
// Optional for string interpolation to JSON model
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.example.provider

import org.scalatest.{BeforeAndAfterAll, FunSpec, Matchers}
import com.itv.scalapact.ScalaPactVerify._
import com.itv.scalapact.PactVerifySuite
import com.itv.scalapact.shared.{ConsumerVersionSelector, PactBrokerAuthorization, ProviderStateResult}

import scala.concurrent.duration._

class VerifyContractsSpec extends FunSpec with Matchers with BeforeAndAfterAll {

import com.itv.scalapact.circe13._
import com.itv.scalapact.http4s21._

class VerifyContractsSpec extends FunSpec with Matchers with BeforeAndAfterAll with PactVerifySuite {
val serverAllocated =
AlternateStartupApproach.serverResource(_ => List("Bob", "Fred", "Harry"), _ => "abcABC123").allocated.unsafeRunSync()

Expand All @@ -37,7 +33,7 @@ class VerifyContractsSpec extends FunSpec with Matchers with BeforeAndAfterAll {
None,
//again, these are publicly known creds for a test pact-broker
PactBrokerAuthorization(pactBrokerCredentials = ("dXfltyFMgNOFZAxr8io9wJ37iUpY42M", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"), ""),
None
Some(5.seconds)
)
)
.setupProviderState("given") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,6 @@
"name" : "scala-pact-consumer"
},
"interactions" : [
{
"providerState" : "Results: Bob, Fred, Harry",
"description" : "Fetching results",
"request" : {
"method" : "GET",
"path" : "/results"
},
"response" : {
"status" : 200,
"headers" : {
"Pact" : "modifiedRequest"
},
"body" : {
"count" : 3,
"results" : [
"Bob",
"Fred",
"Harry"
]
}
}
},
{
"description" : "Fetching least secure auth token ever",
"request" : {
Expand Down Expand Up @@ -59,6 +37,28 @@
}
}
}
},
{
"providerState" : "Results: Bob, Fred, Harry",
"description" : "Fetching results",
"request" : {
"method" : "GET",
"path" : "/results"
},
"response" : {
"status" : 200,
"headers" : {
"Pact" : "modifiedRequest"
},
"body" : {
"count" : 3,
"results" : [
"Bob",
"Fred",
"Harry"
]
}
}
}
],
"metadata" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.itv.scalapact.circe13

import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter}

trait JsonInstances {
implicit val pactReaderInstance: IPactReader = new PactReader

implicit val pactWriterInstance: IPactWriter = new PactWriter
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
package com.itv.scalapact

import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter}

package object circe13 {

implicit val pactReaderInstance: IPactReader =
new PactReader

implicit val pactWriterInstance: IPactWriter =
new PactWriter

}
package object circe13 extends JsonInstances
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.itv.scalapact

import com.itv.scalapact.circe13.{PactReader, PactWriter}
import com.itv.scalapact.shared.typeclasses.{IPactReader, IPactWriter}

package object json {
implicit val pactReaderInstance: IPactReader = new PactReader

implicit val pactWriterInstance: IPactWriter = new PactWriter
import com.itv.scalapact.circe13.JsonInstances

package object json extends JsonInstances {
val JsonConversionFunctions: circe13.JsonConversionFunctions.type = circe13.JsonConversionFunctions
}
12 changes: 12 additions & 0 deletions scalapact-scalatest-suite/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Root logger option
log4j.rootLogger=INFO, stdout

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n


log4j.logger.com.github.tomakehurst=ERROR
log4j.logger.org.mortbay.log=ERROR
20 changes: 20 additions & 0 deletions scalapact-scalatest-suite/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<configuration>

<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>

<logger name="com.github.tomakehurst" level="ERROR" />
<logger name="org.mortbay" level="ERROR" />
<logger name="org.apache" level="ERROR" />

<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.itv.scalapact

import com.itv.scalapact.circe13.JsonInstances
import com.itv.scalapact.http4s21.impl.HttpInstances

trait PactForgerSuite extends ScalaPactForgerDsl with HttpInstances with JsonInstances
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.itv.scalapact

import com.itv.scalapact.circe13.JsonInstances
import com.itv.scalapact.http4s21.impl.HttpInstances

trait PactVerifySuite extends ScalaPactVerifyDsl with HttpInstances with JsonInstances
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.itv.scalapact

//should compile
class PactForgerSuiteSpec extends PactForgerSuite {
val pact =
forgePact
.between("consumer")
.and("provider")
.addInteraction(
interaction
.description("")
.uponReceiving(GET, "")
.willRespondWith(200)
).runConsumerTest(_ => ())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.itv.scalapact

//Should compile
class PactVerifySuiteSpec extends PactVerifySuite {
val verify = verifyPact
.withPactSource(loadFromLocal(""))
.noSetupRequired
.runVerificationAgainst(80)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ package com.itv.scalapact
import java.io.{File, PrintWriter}
import java.nio.charset.StandardCharsets

import com.itv.scalapact.ScalaPactForger.{
ScalaPactDescriptionFinal,
ScalaPactInteractionFinal,
ScalaPactMatchingRule,
ScalaPactMatchingRuleArrayMinLength,
ScalaPactMatchingRuleRegex,
ScalaPactMatchingRuleType
}
import com.itv.scalapact.model.ScalaPactMatchingRule.{ScalaPactMatchingRuleArrayMinLength, ScalaPactMatchingRuleRegex, ScalaPactMatchingRuleType}
import com.itv.scalapact.model.{ScalaPactDescriptionFinal, ScalaPactInteractionFinal, ScalaPactMatchingRule}
import com.itv.scalapact.shared._
import com.itv.scalapact.shared.typeclasses.IPactWriter

object ScalaPactContractWriter {
private[scalapact] object ScalaPactContractWriter {
def writePactContracts(outputPath: String)(implicit pactWriter: IPactWriter): ScalaPactDescriptionFinal => Unit =
pactDescription => {
val dirFile = new File(outputPath)
Expand Down Expand Up @@ -74,7 +68,7 @@ object ScalaPactContractWriter {
BuildInfo.version
)

private[scalapact] def producePactFromDescription: ScalaPactDescriptionFinal => Pact =
def producePactFromDescription: ScalaPactDescriptionFinal => Pact =
pactDescription =>
Pact(
provider = PactActor(pactDescription.provider),
Expand Down
Loading

0 comments on commit cbdbb74

Please sign in to comment.