本文整理汇总了Scala中org.specs2.specification.Scope类的典型用法代码示例。如果您正苦于以下问题:Scala Scope类的具体用法?Scala Scope怎么用?Scala Scope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: JsonLeumiCardMerchantParserTest
//设置package包名称以及导入依赖的类
package com.wix.pay.leumicard
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class JsonLeumiCardMerchantParserTest extends SpecWithJUnit {
"stringify and then parse" should {
"yield a merchant similar to the original one" in new Context {
val someMerchant = LeumiCardMerchant(masof = "012345678")
val merchantKey = merchantParser.stringify(someMerchant)
merchantParser.parse(merchantKey) must beEqualTo(someMerchant)
}
}
trait Context extends Scope {
val merchantParser: LeumiCardMerchantParser = new JsonLeumiCardMerchantParser
}
}
示例2: JsonLeumiCardAuthorizationParserTest
//设置package包名称以及导入依赖的类
package com.wix.pay.leumicard
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class JsonLeumiCardAuthorizationParserTest extends SpecWithJUnit {
trait Ctx extends Scope {
val authorizationParser: LeumiCardAuthorizationParser = new JsonLeumiCardAuthorizationParser
}
"stringify and then parse" should {
"yield an authorization similar to the original one" in new Ctx {
val someAuthorization = LeumiCardAuthorization(
transactionId = "0123456"
)
val authorizationKey = authorizationParser.stringify(someAuthorization)
authorizationParser.parse(authorizationKey) must beEqualTo(someAuthorization)
}
}
}
示例3: ResponseParserTest
//设置package包名称以及导入依赖的类
package com.wix.sms.nexmo.model
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class ResponseParserTest extends SpecWithJUnit {
trait Ctx extends Scope {
val someResponse = Response(
`message-count` = "1",
messages = Seq(Message(
status = Statuses.success,
to = Some("some to")
))
)
val parser = new ResponseParser
}
"stringify and then parse" should {
"yield an object similar to the original one" in new Ctx {
val json = parser.stringify(someResponse)
parser.parse(json) must beEqualTo(someResponse)
}
}
}
示例4: PaginatedResponseRetrieverSpec
//设置package包名称以及导入依赖的类
package com.dwolla.awssdk.utils
import com.amazonaws.services.ecs.AmazonECSAsync
import com.amazonaws.services.ecs.model.{ListClustersRequest, ListClustersResult, ListContainerInstancesRequest, ListContainerInstancesResult}
import com.dwolla.awssdk.AmazonAsyncMockingImplicits._
import com.dwolla.awssdk.utils.PaginatedResponseRetriever._
import org.specs2.concurrent.ExecutionEnv
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
import scala.collection.JavaConverters._
class PaginatedResponseRetrieverSpec(implicit ee: ExecutionEnv) extends Specification with Mockito {
trait Setup extends Scope {
val mockEcsClient = mock[AmazonECSAsync]
}
"PaginatedResponseRetriever" should {
"make all the requests necessary to fetch all paginated results" in new Setup {
def reqWithNextToken(x: Option[Int]) = new ListContainerInstancesRequest().withCluster("cluster1").withNextToken(x.map(i ? s"next-token-$i").orNull)
def res(x: Int, y: Option[Int] = None) = Right(new ListContainerInstancesResult().withContainerInstanceArns(s"arn$x").withNextToken(y.map(i ? s"next-token-$i").orNull))
val pages = 1 to 50
val pairs = pages.sliding(2).toSeq.map {
case Vector(1, y) ? reqWithNextToken(None) ? res(1, Option(y))
case Vector(x, y) if x > 1 && y < pages.last ? reqWithNextToken(Option(x)) ? res(x, Option(y))
case Vector(x, _) ? reqWithNextToken(Option(x)) ? res(x, None)
}
mockedMethod(mockEcsClient.listContainerInstancesAsync) answers (pairs: _*)
val output = fetchAll(() ? new ListContainerInstancesRequest().withCluster("cluster1"),mockEcsClient.listContainerInstancesAsync)
.map(_.flatMap(_.getContainerInstanceArns.asScala.toList))
output must containTheSameElementsAs(pages.dropRight(1).map(x ? s"arn$x")).await
}
"support default request factory" in new Setup {
new ListClustersResult() completes mockEcsClient.listClustersAsync
val output = fetchAllWithDefaultRequestsVia(mockEcsClient.listClustersAsync)
output must contain(new ListClustersResult()).await
}
"support builder syntax with factory as initial parameter" in new Setup {
new ListClustersResult() completes mockEcsClient.listClustersAsync
val output = fetchAllWithRequestsLike(() ? new ListClustersRequest).via(mockEcsClient.listClustersAsync)
output must contain(new ListClustersResult()).await
}
}
}
示例5: PaloParserTest
//设置package包名称以及导入依赖的类
package com.wix.sms.cellact.model
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
import scala.collection.JavaConversions._
class PaloParserTest extends SpecWithJUnit {
trait Ctx extends Scope {
val parser = new PaloParser
}
"stringify and then parse" should {
val palo = new Palo
palo.HEAD = new Head
palo.HEAD.FROM = "some from"
palo.HEAD.APP = new App
palo.HEAD.APP.USER = "some user"
palo.HEAD.APP.PASSWORD = "some password"
palo.HEAD.CMD = "some cmd"
palo.BODY = new Body
palo.BODY.CONTENT = "some content"
palo.BODY.DEST_LIST = new DestList
palo.BODY.DEST_LIST.TO = Seq("some to 1", "some to 2")
palo.OPTIONAL = new Optional
palo.OPTIONAL.CALLBACK = "some callback"
"yield an object similar to the original one" in new Ctx {
val xml = parser.stringify(palo)
parser.parse(xml) must beEqualTo(palo)
}
}
}
示例6: ResponseParserTest
//设置package包名称以及导入依赖的类
package com.wix.sms.cellact.model
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class ResponseParserTest extends SpecWithJUnit {
trait Ctx extends Scope {
val parser = new ResponseParser
}
"stringify and then parse" should {
val response = new Response
response.BLMJ = "some blmj"
response.RESULTCODE = "123"
response.RESULTMESSAGE = "some resultmessage"
"yield an object similar to the original one" in new Ctx {
val xml = parser.stringify(response)
parser.parse(xml) must beEqualTo(response)
}
}
}
示例7: RSAUtilsTest
//设置package包名称以及导入依赖的类
package com.wix.pay.twocheckout.tokenization
import java.security.spec.RSAPublicKeySpec
import java.security.{KeyFactory, KeyPairGenerator}
import javax.crypto.Cipher
import org.apache.commons.codec.binary.Base64
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class RSAUtilsTest extends SpecWithJUnit {
"RSAUtils" should {
"encrypt data with provided key in base64 format" in new Ctx {
val encrypted = RSAUtils.rsaEncrypt(publicKey, someMessage)
decryptBase64(encrypted) mustEqual someMessage
}
"encrypt empty string with provided key in base64 format" in new Ctx {
val encrypted = RSAUtils.rsaEncrypt(publicKey, emptyMessage)
decryptBase64(encrypted) mustEqual emptyMessage
}
}
trait Ctx extends Scope {
val factory = KeyPairGenerator.getInstance("RSA")
factory.initialize(2048)
val keys = factory.genKeyPair()
val publicKeySpec = KeyFactory.getInstance("RSA").getKeySpec(keys.getPublic, classOf[RSAPublicKeySpec])
val publicKey = RSAPublicKey(
Base64.encodeBase64String(publicKeySpec.getModulus.toByteArray),
Base64.encodeBase64String(publicKeySpec.getPublicExponent.toByteArray)
)
println(publicKey)
val someMessage = "some message hello"
val emptyMessage = ""
def decryptBase64(encrypted: String): String = {
val bytes = Base64.decodeBase64(encrypted)
val cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING")
cipher.init(Cipher.DECRYPT_MODE, keys.getPrivate)
new String(cipher.doFinal(bytes), "utf-8")
}
}
}
示例8: RealTwocheckoutTokenizerTest
//设置package包名称以及导入依赖的类
package com.wix.pay.twocheckout.tokenizer
import com.wix.pay.PaymentErrorException
import com.wix.pay.creditcard.{CreditCard, CreditCardOptionalFields, YearMonth}
import com.wix.pay.twocheckout.model.{TwocheckoutEnvironment, TwocheckoutSettings}
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class RealTwocheckoutTokenizerTest extends SpecWithJUnit {
skipAll
"HttpTwocheckoutTokenizer" should {
"obtain token on valid credentials" in new Ctx {
tokenizer.tokenize(sellerId, publishableKey, testCreditCard, true) must beSuccessfulTry[String]
}
"fail on invalid credentials" in new Ctx {
tokenizer.tokenize(wrongSellerId, publishableKey, testCreditCard, true) must beFailedTry(beAnInstanceOf[PaymentErrorException])
}
}
trait Ctx extends Scope {
val settings = TwocheckoutSettings(
production = TwocheckoutEnvironment("https://www.2checkout.com", "https://www.2checkout.com/checkout/api/2co.min.js"),
sandbox = TwocheckoutEnvironment("https://sandbox.2checkout.com", "https://sandbox.2checkout.com/checkout/api/2co.min.js")
)
val tokenizer = new HttpTwocheckoutTokenizer(settings)
val sellerId = "901338726"
val publishableKey = "19CFABDB-BA94-45B8-935A-E3A1B2469F1F"
val wrongSellerId = "11111111"
val testCreditCard = CreditCard("4000000000000002", YearMonth(2019, 1),
Some(CreditCardOptionalFields.withFields(csc = Some("471"), holderName = Some("John Doe"))))
}
}
示例9: JsonTwocheckoutMerchantParserTest
//设置package包名称以及导入依赖的类
package com.wix.pay.twocheckout
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class JsonTwocheckoutMerchantParserTest extends SpecWithJUnit {
trait Ctx extends Scope {
val parser: TwocheckoutMerchantParser = JsonTwocheckoutMerchantParser
}
"stringify and then parse" should {
"yield a merchant similar to the original one" in new Ctx {
val someMerchant = TwocheckoutMerchant(
sellerId = "some seller ID",
publishableKey = "some publishable key",
privateKey = "some private key",
sandboxMode = true
)
val merchantKey = parser.stringify(someMerchant)
parser.parse(merchantKey) must beEqualTo(someMerchant)
}
"parse credentials without explicit mode" in new Ctx {
val someMerchantStr = """{"sellerId":"sellerId","publishableKey":"publishableKey","privateKey":"privateKey"}"""
val someMerchant = TwocheckoutMerchant(
sellerId = "sellerId",
publishableKey = "publishableKey",
privateKey = "privateKey",
sandboxMode = false
)
parser.parse(someMerchantStr) must beEqualTo(someMerchant)
}
}
}
示例10: JsonTwocheckoutAuthorizationParserTest
//设置package包名称以及导入依赖的类
package com.wix.pay.twocheckout
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class JsonTwocheckoutAuthorizationParserTest extends SpecWithJUnit {
trait Ctx extends Scope {
val parser: TwocheckoutAuthorizationParser = JsonTwocheckoutAuthorizationParser
}
"stringify and then parse" should {
"yield a merchant similar to the original one" in new Ctx {
val someAuthorization = TwocheckoutAuthorization()
val authorizationKey = parser.stringify(someAuthorization)
parser.parse(authorizationKey) must beEqualTo(someAuthorization)
}
}
}
示例11: NetworkBrokerSpec
//设置package包名称以及导入依赖的类
package net.ruippeixotog.scalafbp.runtime
import akka.actor.Props
import akka.testkit.TestProbe
import org.specs2.specification.Scope
import spray.json.DefaultJsonProtocol._
import net.ruippeixotog.akka.testkit.specs2.mutable.AkkaSpecification
import net.ruippeixotog.scalafbp.component.PortDataMarshaller
import net.ruippeixotog.scalafbp.component.core.Repeat
abstract class NetworkBrokerSpec extends AkkaSpecification {
class SingleNodeGraph extends GraphTemplate {
val n1 = node[String](1, 1)
}
class TwoNodeGraph extends GraphTemplate {
val n1, n2 = node[String](1, 1)
}
class ThreeNodeGraph extends GraphTemplate {
val n1, n2, n3 = node[String](1, 1)
}
class ChainGraph[A: PortDataMarshaller] extends GraphTemplate {
val inNode = node(Repeat)
val outNode = node[A](1, 1)
initial("init") ~> (inNode, "in")
(inNode, "out") ~> (outNode, 1)
}
class TwoToTwoGraph extends GraphTemplate {
val inNode1, inNode2, outNode1, outNode2 = node[String](1, 1)
(inNode1, 1) ~> (outNode1, 1) <~ (inNode2, 1)
(inNode1, 1) ~> (outNode2, 1) <~ (inNode2, 1)
}
abstract class BrokerInstance(dynamic: Boolean = false) extends Scope {
def _graph: GraphTemplate
def externalProbe: TestProbe = null
val lifeProbe, outputProbe = TestProbe()
val broker = system.actorOf(Props(
new NetworkBroker(_graph, dynamic, outputProbe.ref, Option(externalProbe).map(_.ref))))
lifeProbe.watch(broker)
}
}
示例12: SmsResponseParserTest
//设置package包名称以及导入依赖的类
package com.wix.sms.twilio.model
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class SmsResponseParserTest extends SpecWithJUnit {
trait Ctx extends Scope {
val someSmsResponse = SmsResponse(
sid = Some("some sid")
)
}
"stringify and then parse" should {
"yield an object similar to the original one" in new Ctx {
val json = SmsResponseParser.stringify(someSmsResponse)
SmsResponseParser.parse(json) must beEqualTo(someSmsResponse)
}
}
}
示例13: HomeControllerSpec
//设置package包名称以及导入依赖的类
package controllers
import models.UsersRepository
import org.specs2.execute.{AsResult, Result}
import org.specs2.mutable.Around
import org.specs2.specification.Scope
import play.api.Application
import play.api.mvc._
import play.api.test.{FakeRequest, PlaySpecification}
class HomeControllerSpec extends PlaySpecification with Results {
abstract class WithTestApplication extends Around with Scope with TestEnvironment {
lazy val app: Application = fakeApp
lazy val controller = new HomeController(knolxControllerComponent)
override def around[T: AsResult](t: => T): Result = {
TestHelpers.running(app)(AsResult.effectively(t))
}
}
"HomeController" should {
"redirect index page to sessions page" in new WithTestApplication {
val result = controller.index(FakeRequest())
status(result) must be equalTo SEE_OTHER
}
}
}
示例14: CreditCardMapperTest
//设置package包名称以及导入依赖的类
package com.wix.pay.stripe
import com.wix.pay.creditcard.{CreditCard, CreditCardOptionalFields, PublicCreditCardOptionalFields, YearMonth}
import com.wix.pay.stripe.drivers.StripeMatchers
import org.specs2.mutable.SpecificationWithJUnit
import org.specs2.specification.Scope
class CreditCardMapperTest extends SpecificationWithJUnit with StripeMatchers {
"CreditCardMapper" should {
"create params with all relevant fields " in new ctx{
CreditCardMapper.cardToParams(someCreditCard) must haveFieldParams(expectedFields)
}
"return params without address and zip code as they are empty Strings " in new ctx {
CreditCardMapper.cardToParams(emptyFieldsCreditCard) must not(haveAnyEmptyFields)
}
}
trait ctx extends Scope {
val holderId: Some[String] = Some("some holder id")
val holderName: Some[String] = Some("some holder name")
val billingAddress: Some[String] = Some("some address")
val billingPostalCode: Some[String] = Some("some postal Code")
val someCreditCard = CreditCard(
"4012888818888",
YearMonth(2020, 12),
additionalFields = Some(CreditCardOptionalFields.withFields(
csc = Some("123"),
holderId = holderId,
holderName = holderName,
billingAddress = billingAddress,
billingPostalCode = billingPostalCode)))
val emptyFieldsCreditCard = CreditCard(
"4012888818888",
YearMonth(2020, 12),
additionalFields = Some(CreditCardOptionalFields.withFields(
csc = Some("123"),
holderId = holderId,
holderName = holderName,
billingAddress = Some(""),
billingPostalCode = Some(""))))
val expectedFields = PublicCreditCardOptionalFields(holderId, holderName, billingAddress, billingPostalCode)
}
}
示例15: StripeAdditionalInfoMapperTest
//设置package包名称以及导入依赖的类
package com.wix.pay.stripe
import com.wix.pay.stripe.drivers.{StripeAdditionalInfoDomain, StripeMatchers}
import org.specs2.matcher.Matchers
import org.specs2.mutable.SpecWithJUnit
import org.specs2.specification.Scope
class StripeAdditionalInfoMapperTest extends SpecWithJUnit with Matchers with StripeMatchers {
trait Ctx extends Scope with StripeAdditionalInfoDomain {
val mapper = new StripeAdditionalInfoMapper()
}
"Stripe additional info mapper" should {
"map additional Info into a map" in new Ctx {
val map: MappedParams = mapper.createMap(someCreditCard, someCustomer, someDeal)
map must {
containBillingAddress(billingAddress.get) and
containCustomer(someCustomer.get) and
containInvoiceId(someInvoiceId.get) and
containShippingAddress(someShippingAddress.get) and
containOrderItems(orderItems) and
containIncludedCharges(includedCharges.get)
}
}
}
}