• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala WireMock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中com.github.tomakehurst.wiremock.client.WireMock的典型用法代码示例。如果您正苦于以下问题:Scala WireMock类的具体用法?Scala WireMock怎么用?Scala WireMock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了WireMock类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)))
} 
开发者ID:edgarjimenez,项目名称:openid-connect-userinfo,代码行数:32,代码来源:WiremockServiceLocatorSugar.scala


示例2: 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()
  }
} 
开发者ID:hmrc,项目名称:email-verification-frontend,代码行数:50,代码来源:IntegrationSpecBase.scala


示例3: 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"
} 
开发者ID:hmrc,项目名称:marriage-allowance-des-stub,代码行数:45,代码来源:ApiPlatformTestUserStub.scala


示例4: UrlEncodingISpec

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.fileupload

import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock._
import play.api.libs.json._
import play.api.libs.ws.WSResponse
import play.utils.UriEncoding
import uk.gov.hmrc.fileupload.support._
import uk.gov.hmrc.fileupload.write.envelope.{MarkFileAsClean, QuarantineFile, StoreFile}

// supplementary suit
class UrlEncodingISpec extends IntegrationSpec with EnvelopeActions with FileActions with EventsActions with FakeFrontendService{

  val data = "{'name':'test'}"

  feature("Odd Url Encoding for FileId") {
    scenario("Get Envelope Details with a file and check if href encodes FileId") {

      Given("I have a valid envelope")
      val envelopeId = createEnvelope()
      val fileId = FileId(s"fileId-${nextUtf8String()+"%2C"}")
      val fileRefId = FileRefId(s"fileRefId-${nextId()}")

      And("File is In Quarantine Store")
      sendCommandQuarantineFile(QuarantineFile(envelopeId, fileId, fileRefId, 0, "test.pdf", "pdf", Some(data.getBytes().length), Json.obj()))

      And("File was scanned and no virus was found")
      sendCommandMarkFileAsClean(MarkFileAsClean(envelopeId, fileId, fileRefId))

      And("I have uploaded a file")
      sendCommandStoreFile(StoreFile(envelopeId, fileId, fileRefId, data.getBytes().length))

      eventually {
        val envelopeResponse = getEnvelopeFor(envelopeId)
        envelopeResponse.status shouldBe OK
      }

      When("I call GET /file-upload/envelopes/:envelope-id")
      val envelopeResponse = getEnvelopeFor(envelopeId)

      Then("I will receive a 200 Ok response")
      envelopeResponse.status shouldBe OK

      And("the response body should contain the envelope details")
      val body: String = envelopeResponse.body
      body shouldNot be(null)

      val parsedBody: JsValue = Json.parse(body)

      val href = (parsedBody \ "files" \\ "href").head.toString()

      val encodedFileId = urlEncode(fileId)
      encodedFileId.contains("%252C") shouldBe true

      val targetUrl = s"/file-upload/envelopes/$envelopeId/files/$encodedFileId/content"

      href shouldBe ("\""+targetUrl+"\"")
    }
  }

} 
开发者ID:hmrc,项目名称:file-upload,代码行数:62,代码来源:UrlEncodingISpec.scala


示例5: 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)))
} 
开发者ID:hmrc,项目名称:ers-submissions,代码行数:55,代码来源:WiremockHelper.scala


示例6: MicroserviceAuditFilterSpec

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.selfassessmentapi

import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock.{urlPathEqualTo, _}
import org.scalatest.time.{Millis, Seconds, Span}
import uk.gov.hmrc.selfassessmentapi.resources.Jsons
import uk.gov.hmrc.support.BaseFunctionalSpec

class MicroserviceAuditFilterSpec extends BaseFunctionalSpec {

  implicit override val patienceConfig = PatienceConfig(timeout = Span(5, Seconds), interval = Span(100, Millis))

  "Audit filter" should {
    "be applied when a POST request is made" in {
      given()
        .userIsSubscribedToMtdFor(nino)
        .userIsFullyAuthorisedForTheResource
        .des().selfEmployment.willBeCreatedFor(nino)
        .when()
        .post(Jsons.SelfEmployment()).to(s"/ni/$nino/self-employments")
        .thenAssertThat()
        .statusIs(201)

      eventually {
        WireMock.findAll(postRequestedFor(urlPathEqualTo("/write/audit"))
        ).size shouldBe 1
      }
    }
  }

} 
开发者ID:hmrc,项目名称:self-assessment-api,代码行数:32,代码来源:MicroserviceAuditFilterSpec.scala


示例7: 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()
  }
} 
开发者ID:hmrc,项目名称:email-verification,代码行数:44,代码来源:WiremockHelper.scala


示例8: 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()
  }
} 
开发者ID:hmrc,项目名称:agent-subscription,代码行数:50,代码来源:WireMockSupport.scala


示例9: 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()
  }

} 
开发者ID:hmrc,项目名称:agent-fi-invitation,代码行数:39,代码来源:FakeRelationshipService.scala


示例10: 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 
开发者ID:hmrc,项目名称:apprenticeship-levy,代码行数:27,代码来源:WiremockService.scala


示例11: 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()
  }
} 
开发者ID:ovotech,项目名称:kafka-serialization,代码行数:43,代码来源:WireMockFixture.scala



注:本文中的com.github.tomakehurst.wiremock.client.WireMock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Serialization类代码示例发布时间:2022-05-23
下一篇:
Scala CategoricalSplit类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap