本文整理汇总了Scala中com.github.tomakehurst.wiremock.WireMockServer类的典型用法代码示例。如果您正苦于以下问题:Scala WireMockServer类的具体用法?Scala WireMockServer怎么用?Scala WireMockServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WireMockServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: regPayloadStringFor
//设置package包名称以及导入依赖的类
package it.utils
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock._
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import play.api.libs.json.Json
import uk.gov.hmrc.api.domain.Registration
trait WiremockServiceLocatorSugar {
lazy val wireMockUrl = s"http://$stubHost:$stubPort"
lazy val wireMockServer = new WireMockServer(wireMockConfig().port(stubPort))
val stubPort = sys.env.getOrElse("WIREMOCK_SERVICE_LOCATOR_PORT", "11112").toInt
val stubHost = "localhost"
def regPayloadStringFor(serviceName: String, serviceUrl: String): String =
Json.toJson(Registration(serviceName, serviceUrl, Some(Map("third-party-api" -> "true")))).toString
def startMockServer() = {
wireMockServer.start()
WireMock.configureFor(stubHost, stubPort)
}
def stopMockServer() = {
wireMockServer.stop()
// A cleaner solution to reset the mappings, but only works with wiremock "1.57" (at the moment version 1.48 is pulled)
//wireMockServer.resetMappings()
}
def stubRegisterEndpoint(status: Int) = stubFor(post(urlMatching("/registration")).willReturn(aResponse().withStatus(status)))
}
示例2: WireMockBaseUrl
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentmapping.support
import java.net.URL
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock.{configureFor, reset}
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
import uk.gov.hmrc.play.it.Port.randomAvailable
case class WireMockBaseUrl(value: URL)
object WireMockSupport {
// We have to make the wireMockPort constant per-JVM instead of constant
// per-WireMockSupport-instance because config values containing it are
// cached in the GGConfig object
private lazy val wireMockPort = randomAvailable
}
trait WireMockSupport extends BeforeAndAfterAll with BeforeAndAfterEach{
me: Suite =>
val wireMockPort: Int = WireMockSupport.wireMockPort
val wireMockHost = "localhost"
val wireMockBaseUrlAsString = s"http://$wireMockHost:$wireMockPort"
val wireMockBaseUrl = new URL(wireMockBaseUrlAsString)
protected implicit val implicitWireMockBaseUrl = WireMockBaseUrl(wireMockBaseUrl)
protected def basicWireMockConfig(): WireMockConfiguration = wireMockConfig()
private val wireMockServer = new WireMockServer(basicWireMockConfig().port(wireMockPort))
override protected def beforeAll(): Unit = {
super.beforeAll()
configureFor(wireMockHost, wireMockPort)
wireMockServer.start()
}
override protected def afterAll(): Unit = {
wireMockServer.stop()
super.afterAll()
}
override protected def beforeEach(): Unit = {
super.beforeEach()
reset()
}
}
示例3: WireMockBaseUrl
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentmappingfrontend.support
import java.net.URL
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock.{configureFor, reset}
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
import uk.gov.hmrc.play.it.Port
case class WireMockBaseUrl(value: URL)
object WireMockSupport {
// We have to make the wireMockPort constant per-JVM instead of constant
// per-WireMockSupport-instance because config values containing it are
// cached in the GGConfig object
private lazy val wireMockPort = Port.randomAvailable
}
trait WireMockSupport extends BeforeAndAfterAll with BeforeAndAfterEach {
me: Suite =>
val wireMockPort: Int = WireMockSupport.wireMockPort
val wireMockHost = "localhost"
val wireMockBaseUrlAsString = s"http://$wireMockHost:$wireMockPort"
val wireMockBaseUrl = new URL(wireMockBaseUrlAsString)
protected implicit val implicitWireMockBaseUrl = WireMockBaseUrl(wireMockBaseUrl)
protected def basicWireMockConfig(): WireMockConfiguration = wireMockConfig()
private val wireMockServer = new WireMockServer(basicWireMockConfig().port(wireMockPort))
override protected def beforeAll(): Unit = {
super.beforeAll()
configureFor(wireMockHost, wireMockPort)
wireMockServer.start()
}
override protected def afterAll(): Unit = {
wireMockServer.stop()
super.afterAll()
}
override protected def beforeEach(): Unit = {
super.beforeEach()
reset()
}
}
示例4: WiremockHelper
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.emailverification
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
import org.scalatest._
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatestplus.play.OneServerPerSuite
object WiremockHelper {
val wiremockPort = 11111
val wiremockHost = "localhost"
val url = s"http://$wiremockHost:$wiremockPort"
}
trait WiremockHelper {
import uk.gov.hmrc.emailverification.WiremockHelper._
val wmConfig = wireMockConfig().port(wiremockPort)
val wireMockServer = new WireMockServer(wmConfig)
def startWiremock() = {
wireMockServer.start()
WireMock.configureFor(wiremockHost, wiremockPort)
}
def stopWiremock() = wireMockServer.stop()
def resetWiremock() = WireMock.reset()
}
trait IntegrationSpecBase extends FeatureSpec with GivenWhenThen with OneServerPerSuite with ScalaFutures with IntegrationPatience with Matchers with WiremockHelper with BeforeAndAfterEach with BeforeAndAfterAll {
override def beforeEach() = {
resetWiremock()
}
override def beforeAll() = {
super.beforeAll()
startWiremock()
}
override def afterAll() = {
stopWiremock()
super.afterAll()
}
}
示例5: WireMockHelper
//设置package包名称以及导入依赖的类
package integration.helper
import java.net.ServerSocket
import java.util.UUID
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.matching.RequestPattern._
import com.github.tomakehurst.wiremock.verification.LoggedRequest
import integration.helper.FakeApplicationHelper.withApplication
import play.api.test.FakeApplication
object WireMockHelper {
def findCapturedRequest(server: WireMockServer): LoggedRequest = {
server.findRequestsMatching(everything()).getRequests.get(0)
}
def withAppAndMock(app: FakeApplication, server: WireMockServer, call: () => Unit): Unit = {
withApplication(app) {
() => withWireMock(server) {
() => {
call()
}
}
}
}
def randomUri: String = {
"/" + UUID.randomUUID()
}
def withWireMock(server: WireMockServer)(call: () => Unit): Unit = {
server.start()
try {
call()
} finally {
server.shutdownServer()
}
}
def freePort(): Int = {
val socket = new ServerSocket(0)
val port = socket.getLocalPort
socket.close()
port
}
}
示例6: beforeAll
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentinvitations.support
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock.{configureFor, reset}
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
import uk.gov.hmrc.play.it.Port.randomAvailable
trait StartAndStopWireMock extends BeforeAndAfterEach with BeforeAndAfterAll {
self: Suite =>
protected val wiremockPort = randomAvailable
protected val wiremockHost = "localhost"
protected val wiremockBaseUrl: String = s"http://$wiremockHost:$wiremockPort"
val wireMockServer = new WireMockServer(wireMockConfig().port(wiremockPort))
override def beforeAll() = {
wireMockServer.stop()
wireMockServer.start()
configureFor(wiremockHost, wiremockPort)
}
override def beforeEach() = {
reset()
}
override protected def afterAll(): Unit = {
wireMockServer.stop()
}
}
示例7: willReturnTheIndividual
//设置package包名称以及导入依赖的类
package stubs
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock._
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import play.api.http.Status._
import uk.gov.hmrc.domain.Nino
trait ApiPlatformTestUserStub {
val mock: WireMock
def willReturnTheIndividual(nino: Nino) = {
mock.register(get(urlPathEqualTo(s"/individuals/nino/$nino"))
.willReturn(aResponse().withStatus(OK).withBody(
s"""
|{
| "individualDetails": {
| "firstName": "Heather",
| "lastName": "Ling",
| "dateOfBirth": "1983-09-18"
| },
| "nino": "WC885133C"
|}
""".stripMargin)))
}
def willNotFindTheIndividual() = {
mock.register(get(urlPathMatching("/individuals/nino/([A-Z0-9]+)"))
.willReturn(aResponse().withStatus(NOT_FOUND)))
}
def willReturnAnError() = {
mock.register(get(urlPathMatching("/individuals/nino/([A-Z0-9]+)"))
.willReturn(aResponse().withStatus(INTERNAL_SERVER_ERROR)))
}
}
object ApiPlatformTestUserStub extends ApiPlatformTestUserStub {
val port = 11112
val server = new WireMockServer(WireMockConfiguration.wireMockConfig().port(port))
val mock = new WireMock("localhost", port)
val url = s"http://localhost:$port"
}
示例8: beforeAll
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.fileupload.support
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import org.scalatest.{BeforeAndAfterAll, Suite}
trait FakeFrontendService extends BeforeAndAfterAll {
this: Suite =>
lazy val mockFEServicePort = 8017
lazy val mockFEServer = new WireMockServer(wireMockConfig().port(mockFEServicePort))
override def beforeAll() = {
super.beforeAll()
mockFEServer.start()
}
override def afterAll() = {
super.afterAll()
mockFEServer.stop()
}
}
示例9: beforeAll
//设置package包名称以及导入依赖的类
package uk.gov.hmrc
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock._
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{BeforeAndAfterAll, Suite}
trait FakeAuthService extends BeforeAndAfterAll with ScalaFutures {
this: Suite =>
lazy val authServiceHost = "localhost"
lazy val authServicePort = 18500
lazy val authServer = new WireMockServer(wireMockConfig().port(authServicePort))
final lazy val authServiceBaseUrl = s"http://$authServiceHost:$authServicePort"
override def beforeAll() = {
super.beforeAll()
authServer.start()
}
override def afterAll() = {
super.afterAll()
authServer.stop()
}
authServer.stubFor(WireMock.get(urlMatching("/.*")).willReturn(WireMock.aResponse().withStatus(200)))
}
trait FakeErsStubService extends BeforeAndAfterAll with ScalaFutures {
this: Suite =>
lazy val stubServiceHost = "localhost"
lazy val stubServicePort = 19339
lazy val stubServer = new WireMockServer(wireMockConfig().port(stubServicePort))
final lazy val stubServiceBaseUrl = s"http://$stubServiceHost:$stubServicePort"
override def beforeAll() = {
super.beforeAll()
stubServer.start()
}
override def afterAll() = {
super.afterAll()
stubServer.stop()
}
stubServer.stubFor(WireMock.post(urlMatching("/.*")).willReturn(WireMock.aResponse().withStatus(202)))
}
示例10: WireMockBaseUrl
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentrelationships.support
import java.net.URL
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock.{configureFor, reset}
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
import uk.gov.hmrc.play.it.Port.randomAvailable
case class WireMockBaseUrl(value: URL)
object WireMockSupport {
// We have to make the wireMockPort constant per-JVM instead of constant
// per-WireMockSupport-instance because config values containing it are
// cached in the GGConfig object
private lazy val wireMockPort = randomAvailable
}
trait WireMockSupport extends BeforeAndAfterAll with BeforeAndAfterEach {
me: Suite =>
val wireMockPort: Int = WireMockSupport.wireMockPort
val wireMockHost = "localhost"
val wireMockBaseUrlAsString = s"http://$wireMockHost:$wireMockPort"
val wireMockBaseUrl = new URL(wireMockBaseUrlAsString)
protected implicit val implicitWireMockBaseUrl = WireMockBaseUrl(wireMockBaseUrl)
protected def basicWireMockConfig(): WireMockConfiguration = wireMockConfig()
private val wireMockServer = new WireMockServer(basicWireMockConfig().port(wireMockPort))
override protected def beforeAll(): Unit = {
super.beforeAll()
configureFor(wireMockHost, wireMockPort)
wireMockServer.start()
}
override protected def afterAll(): Unit = {
wireMockServer.stop()
super.afterAll()
}
override protected def beforeEach(): Unit = {
super.beforeEach()
reset()
}
}
示例11: WireMockConfig
//设置package包名称以及导入依赖的类
package support
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
object WireMockConfig {
val stubPort = 11111
val stubHost = "localhost"
}
trait WireMockHelper extends BeforeAndAfterAll with BeforeAndAfterEach {
self: Suite =>
lazy val wireMockServer = new WireMockServer(wireMockConfig().port(stubPort))
val stubPort = WireMockConfig.stubPort
val stubHost = WireMockConfig.stubHost
private def startMockServer() = {
wireMockServer.start()
WireMock.configureFor(stubHost, stubPort)
}
private def stopMockServer() = {
wireMockServer.stop()
wireMockServer.resetMappings()
}
override def beforeAll() = {
super.beforeAll()
startMockServer()
}
override def afterAll() = {
stopMockServer()
super.afterAll()
}
override def beforeEach() = {
super.beforeEach()
WireMock.reset()
}
}
示例12: WireMockBaseUrl
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentsubscription.support
import java.net.URL
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
import uk.gov.hmrc.play.it.Port
case class WireMockBaseUrl(value: URL)
object WireMockSupport {
// We have to make the wireMockPort constant per-JVM instead of constant
// per-WireMockSupport-instance because config values containing it are
// cached in the GGConfig object
private lazy val wireMockPort = Port.randomAvailable
}
trait WireMockSupport extends BeforeAndAfterAll with BeforeAndAfterEach {
me: Suite =>
val wireMockPort: Int = WireMockSupport.wireMockPort
val wireMockHost = "localhost"
val wireMockBaseUrlAsString = s"http://$wireMockHost:$wireMockPort"
val wireMockBaseUrl = new URL(wireMockBaseUrlAsString)
protected implicit val implicitWireMockBaseUrl = WireMockBaseUrl(wireMockBaseUrl)
protected def basicWireMockConfig(): WireMockConfiguration = wireMockConfig()
private val wireMockServer = new WireMockServer(basicWireMockConfig().port(wireMockPort))
override protected def beforeAll(): Unit = {
super.beforeAll()
WireMock.configureFor(wireMockHost, wireMockPort)
wireMockServer.start()
}
override protected def afterAll(): Unit = {
wireMockServer.stop()
super.afterAll()
}
override protected def beforeEach(): Unit = {
super.beforeEach()
WireMock.reset()
}
}
示例13: beforeAll
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentfiinvitation.support
import org.scalatest.{BeforeAndAfterAll, Suite}
import org.scalatest.concurrent.ScalaFutures
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock._
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import play.api.http.Status
trait FakeRelationshipService extends BeforeAndAfterAll with ScalaFutures {
this: Suite =>
val Host = "http://localhost"
val Port = 9427
lazy val wireMockServer = new WireMockServer(wireMockConfig().port(Port))
override def beforeAll(): Unit = {
super.beforeAll()
wireMockServer.start()
WireMock.configureFor(Host, Port)
wireMockServer.addStubMapping(
put(urlPathMatching("/agent-fi-relationship/relationships"))
.willReturn(
aResponse()
.withStatus(Status.CREATED))
.build())
}
override def afterAll(): Unit = {
println("Stopping the mock backend server")
super.afterAll()
wireMockServer.stop()
}
}
示例14: start
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.apprenticeshiplevy.util
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock._
import com.github.tomakehurst.wiremock.core.WireMockConfiguration._
import org.scalatest.Informer
import com.github.tomakehurst.wiremock.common._
import uk.gov.hmrc.apprenticeshiplevy.config.IntegrationTestConfig
trait WiremockService extends IntegrationTestConfig with StandardOutInformer {
lazy val notifier = new WiremockTestInformerNotifier(info, verboseWiremockOutput)
info(s"Configuring wire mock server to listen on ${stubHost}:${stubPort} using responses configured in ${stubConfigPath}")
lazy val wireMockServer = new WireMockServer(wireMockConfig.notifier(notifier).usingFilesUnderDirectory(stubConfigPath).port(stubPort).bindAddress(stubHost))
def start() = {
wireMockServer.start()
}
def stop() = {
wireMockServer.stop()
}
}
object WiremockService extends WiremockService
示例15: wireMockPort
//设置package包名称以及导入依赖的类
package com.ovoenergy.kafka.serialization.testkit
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Suite}
trait WireMockFixture extends BeforeAndAfterAll with BeforeAndAfterEach { self: Suite =>
private lazy val wireMockServer: WireMockServer = new WireMockServer(WireMockConfiguration.options().dynamicPort())
val wireMockHost: String = "localhost"
def wireMockPort: Int = wireMockServer.port()
def wireMockEndpoint: String = s"http://$wireMockHost:$wireMockPort"
override protected def beforeAll(): Unit = {
super.beforeAll()
wireMockServer.start()
WireMock.configureFor(wireMockPort)
}
override protected def afterAll(): Unit = {
wireMockServer.shutdown()
super.afterAll()
}
override protected def afterEach(): Unit = {
resetWireMock()
super.afterEach()
}
override protected def beforeEach(): Unit = {
super.beforeEach()
resetWireMock()
}
def resetWireMock(): Unit = {
wireMockServer.resetMappings()
wireMockServer.resetRequests()
wireMockServer.resetScenarios()
}
}