All Downloads are FREE. Search and download functionalities are using the official Maven repository.

au.com.dius.pact.provider.scalatest.ProviderDsl.scala Maven / Gradle / Ivy

Go to download

pact-jvm-provider-scalatest ======================== Provides an extension to scalatest to validate pact files against a running provider. See [examples](src/test/scala/au/com/dius/pact/provider/scalatest) for details. *Note:* The Pact ProviderSpec requires scalatest 2.2.x

There is a newer version: 3.5.24
Show newest version
package au.com.dius.pact.provider.scalatest

import java.net.URI

import au.com.dius.pact.provider.ConsumerInfo

/**
  * DSL extension on top of the default verify method
  */
trait ProviderDsl {

  case class Provider(provider: String) {
    def complying(consumer: Consumer): PactBetween = PactBetween(provider, consumer)
  }

  case class PactBetween(provider: String, consumer: Consumer) {
    def pacts(from: from): LocationHandler = LocationHandler(this, from.uri)
  }

  case class LocationHandler(pactBetween: PactBetween, uri: URI) {
    def testing(serverStarter: ServerStarter): ServerHandler = ServerHandler(pactBetween, uri, serverStarter)
  }

  case class ServerHandler(pactBetween: PactBetween, uri: URI, serverStarter: ServerStarter) {
    def withoutRestart() = VerificationConfig(Pact(pactBetween.provider, pactBetween.consumer, uri), ServerConfig(serverStarter))

    def withRestart() = VerificationConfig(Pact(pactBetween.provider, pactBetween.consumer, uri), ServerConfig(serverStarter, true))
  }

  /**
    * Support string provider in the DSL
    *
    * @param provider
    * @return
    */
  implicit def strToProvider(provider: String) = Provider(provider)

  /**
    * Allows every pacts to be run against the provider
    */
  case object all extends Consumer {
    override val filter = (consumerInfo: ConsumerInfo) => true
  }

  /**
    * Defines the resource uri where the pacts can be found
    *
    * @param uri
    */
  case class from(uri: URI)

  implicit def defaultPactDirectoryToUri(default: defaultPactDirectory.type): URI = stringToUri(default.directory)

  implicit def stringToUri(default: String): URI = this.getClass.getClassLoader.getResource(default).toURI

  /**
    * pacts-dependents is the default directory for pacts
    */
  object defaultPactDirectory {
    val directory = "pacts-dependents"
  }

}

object ProviderDsl extends ProviderDsl




© 2015 - 2024 Weber Informatics LLC | Privacy Policy