本文整理汇总了Scala中org.scalatest.EitherValues类的典型用法代码示例。如果您正苦于以下问题:Scala EitherValues类的具体用法?Scala EitherValues怎么用?Scala EitherValues使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EitherValues类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SalesforceCustomerRepoSpec
//设置package包名称以及导入依赖的类
package com.ovoenergy.comms.profiles.salesforce
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Paths}
import com.ovoenergy.comms.profiles.domain._
import okhttp3._
import org.scalatest.{EitherValues, FlatSpec, Matchers}
class SalesforceCustomerRepoSpec extends FlatSpec with Matchers with EitherValues {
behavior of "SalesforceCustomerRepo"
val request = new Request.Builder().url("http://google.com").get().build()
def buildResponse(code: Int, body: String): (String) => Either[SalesforceError, Response] =
(str: String) =>
Right(
new Response.Builder()
.protocol(Protocol.HTTP_1_1)
.code(code)
.request(request)
.body(ResponseBody.create(MediaType.parse("application/json"), body))
.build()
)
it should "Successfull deserialise a valid customer json body" in {
val json =
new String(Files.readAllBytes(Paths.get("src/test/resources/customer_profile.json")), StandardCharsets.UTF_8)
val makeAuthenticatedRequest = buildResponse(200, json)
val profile = SalesforceCustomerRepo.getCustomerProfile(makeAuthenticatedRequest)("customer123")
profile shouldBe Right(
Customer(
Name(Some("Mr"), "Gary", "Philpott", None),
EmailAddresses(Some("[email protected]"), None),
TelephoneNumbers(Some("+441285112233"), Some("+447834774651"), Some("+441285112233")),
Embedded(
List(
CommunicationPreference("SERVICE", List("Sms", "Email", "POST")),
CommunicationPreference("MARKETING", List.empty),
CommunicationPreference("THIRDPARTY", List.empty)
)
)
)
)
}
it should "display an appropriate message if invalid json is returned" in {
val makeAuthenticatedRequest = buildResponse(200, """{"some": "thing"}""")
val profile = SalesforceCustomerRepo.getCustomerProfile(makeAuthenticatedRequest)("customer123")
profile.left.value.message should startWith("Invalid JSON from salesforce api")
}
}
示例2: FieldMappingsSpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentmappingfrontend.controllers
import org.scalatest.EitherValues
import play.api.data.FormError
import uk.gov.hmrc.play.test.UnitSpec
class FieldMappingsSpec extends UnitSpec with EitherValues {
"utr bind" should {
val utrMapping = utr.withPrefix("testKey")
def bind(fieldValue: String) = utrMapping.bind(Map("testKey" -> fieldValue))
"accept valid UTRs" in {
bind("2000000000") shouldBe Right("2000000000")
}
"give \"error.required\" error when it is not supplied" in {
utrMapping.bind(Map.empty).left.value should contain only FormError("testKey", "error.required")
}
"give \"error.required\" error when it is empty" in {
bind("").left.value should contain only FormError("testKey", "error.required")
}
"give \"error.required\" error when it only contains a space" in {
bind(" ").left.value should contain only FormError("testKey", "error.required")
}
"give \"error.utr.invalid\" error when it is invalid" in {
bind("20000000000").left.value should contain only FormError("testKey", "error.utr.invalid")
}
}
"arn bind" should {
val arnMapping = arn.withPrefix("testKey")
def bind(fieldValue: String) = arnMapping.bind(Map("testKey" -> fieldValue))
"accept valid ARN" in {
bind("TARN0000001") shouldBe Right("TARN0000001")
}
"give \"error.required\" error when it is not supplied" in {
arnMapping.bind(Map.empty).left.value should contain only FormError("testKey", "error.required")
}
"give \"error.required\" error when it is empty" in {
bind("").left.value should contain only FormError("testKey", "error.required")
}
"give \"error.required\" error when it only contains a space" in {
bind(" ").left.value should contain only FormError("testKey", "error.required")
}
"give \"error.arn.invalid\" error when it is invalid" in {
bind("ARN0000001").left.value should contain only FormError("testKey", "error.arn.invalid")
}
}
}
示例3: PartialsS3RetrieverSpec
//设置package包名称以及导入依赖的类
package com.ovoenergy.comms.templates.retriever
import com.ovoenergy.comms.model._
import com.ovoenergy.comms.templates.model.FileFormat
import com.ovoenergy.comms.templates.model.template.files.TemplateFile
import com.ovoenergy.comms.templates.s3.S3Client
import org.scalatest.{EitherValues, FlatSpec, Matchers}
class PartialsS3RetrieverSpec extends FlatSpec with Matchers with EitherValues {
def s3(contents: Map[String, String], files: Map[String, Seq[String]] = Map.empty) = new S3Client {
override def listFiles(prefix: String): Seq[String] = files.getOrElse(prefix, Nil)
override def getUTF8TextFileContent(key: String): Option[String] = contents.get(key)
}
val s3client = s3(
contents = Map(
"service/fragments/email/html/header.html" -> "the HTML header",
"service/fragments/email/html/thing.html" -> "another HTML fragment",
"service/fragments/email/txt/header.txt" -> "the text header"
),
files = Map(
"service/fragments/email/html" -> Seq(
"service/fragments/email/html/header.html",
"service/fragments/email/html/thing.html"
),
"service/fragments/email/txt" -> Seq(
"service/fragments/email/txt/header.txt"
)
)
)
val testObj = new PartialsS3Retriever(s3client)
behavior of "Partials Repo for emails"
it should "get html partials" in {
testObj.getSharedPartial(TemplateFile(Service, Email, FileFormat.Html, ""), "header") shouldBe Right(
"the HTML header")
}
it should "get text partials" in {
testObj.getSharedPartial(TemplateFile(Service, Email, FileFormat.Text, ""), "header") shouldBe Right(
"the text header")
}
it should "fail if partial not present" in {
testObj
.getSharedPartial(TemplateFile(Service, Email, FileFormat.Text, ""), "whatevs")
.left
.value should include("Could not find shared partial")
}
}
示例4: ProfileValidationSpec
//设置package包名称以及导入依赖的类
package com.ovoenergy.orchestration.profile
import com.ovoenergy.comms.model.InvalidProfile
import com.ovoenergy.orchestration.domain.{ContactProfile, CustomerProfile, CustomerProfileName}
import com.ovoenergy.orchestration.processes.Orchestrator.ErrorDetails
import org.scalatest.{EitherValues, FlatSpec, Matchers}
class ProfileValidationSpec extends FlatSpec with Matchers with EitherValues {
behavior of "ProfileValidation"
it should "Validate a valid profile" in {
val goodCustomerProfile = CustomerProfile(
CustomerProfileName(Some("Mr"), "Stevie", "Wonder", Some("Esq")),
Seq.empty,
ContactProfile(
None,
None
)
)
ProfileValidation(goodCustomerProfile).right.value shouldBe goodCustomerProfile
}
it should "Fail on an Invalid profile, specifying the parts missing" in {
val badCustomerProfile = CustomerProfile(
CustomerProfileName(Some("Mr"), "", "", Some("Esq")),
Seq.empty,
ContactProfile(
None,
None
)
)
ProfileValidation(badCustomerProfile).left.value shouldBe ErrorDetails(
"Customer has no first name, Customer has no last name",
InvalidProfile)
}
}
示例5: HiveParsingErrorsSpec
//设置package包名称以及导入依赖的类
package com.criteo.vizatra.vizsql.hive
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.{EitherValues, Matchers, PropSpec}
class HiveParsingErrorsSpec extends PropSpec with Matchers with EitherValues {
val invalidSQL99SelectStatements = TableDrivenPropertyChecks.Table(
("SQL", "Expected error"),
(
"select bucket from t",
"""select bucket from t
| ^
|Error: *, table or expression expected
"""
),
(
"select foo from tbl limit 100 order by foo",
"""select foo from tbl limit 100 order by foo
| ^
|Error: ; expected
"""
),
(
"select foo from bar tablesample (bucket 2 out af 3)",
"""select foo from bar tablesample (bucket 2 out af 3)
| ^
|Error: of expected
""".stripMargin
)
)
// --
property("report parsing errors on invalid Hive statements") {
TableDrivenPropertyChecks.forAll(invalidSQL99SelectStatements) {
case (sql, expectedError) =>
new HiveDialect(Map.empty).parser.parseStatement(sql)
.fold(_.toString(sql, ' ').trim, _ => "[NO ERROR]") should be (expectedError.toString.stripMargin.trim)
}
}
}
示例6: MockAuthenticatingMarathonServerSpec
//设置package包名称以及导入依赖的类
package sbtmarathon
import java.net.URL
import org.scalatest.{FlatSpec, Matchers, EitherValues}
class MockAuthenticatingMarathonServerSpec extends FlatSpec with Matchers with EitherValues {
import MockAuthenticatingMarathonServer._
behavior of "MockAuthenticatingMarathonServer"
it should "accept requests for that contain valid credentials" in {
withServer("user" -> "password") { server =>
val url = new URL(s"http://user:[email protected]:${server.port}")
val service = new MarathonService(url)
val applicationId = "foo"
val result1 = service.start(s"""{"id":"$applicationId"}""")
result1.isGood shouldBe true
val resultE1 = result1.toEither
resultE1.right.value shouldBe a [MarathonService.Success]
val result2 = service.destroy(applicationId)
result2.isGood shouldBe true
val resultE2 = result2.toEither
resultE2.right.value shouldBe a [MarathonService.Success]
}
}
it should "deny requests with invalid credentials" in {
withServer("user" -> "password") { server =>
val url = new URL(s"http://foo:[email protected]:${server.port}")
val service = new MarathonService(url)
val result = service.start(s"""{"id":"foo"}""")
result.isGood shouldBe true
val resultE = result.toEither
resultE.right.value shouldBe a [MarathonService.UserError]
}
}
it should "deny requests with non-existent credentials" in {
withServer("user" -> "password") { server =>
val url = new URL(s"http://127.0.0.1:${server.port}")
val service = new MarathonService(url)
val result = service.start(s"""{"id":"foo"}""")
result.isGood shouldBe true
val resultE = result.toEither
resultE.right.value shouldBe a [MarathonService.UserError]
}
}
}
示例7: GrammarTest
//设置package包名称以及导入依赖的类
package com.github.kczulko.isc.dhcp
import com.github.kczulko.isc.dhcp.data.MultipleLeases._
import com.github.kczulko.isc.dhcp.data.SingleLeaseWithServerDuid._
import com.github.kczulko.isc.dhcp.data.SingleLeaseWithoutSomeData._
import com.github.kczulko.isc.dhcp.model.Result
import org.scalatest.{EitherValues, FlatSpec, Inside, Matchers}
class GrammarTest
extends FlatSpec
with Matchers
with Inside
with EitherValues {
val grammar = new Grammar
"leases parser" should "parse valid single entry without some data" in {
inside(Grammar(singleLeaseWithoutSomeData._1).right.value) {
case Result(leases, serverDuid) =>
serverDuid shouldEqual None
leases should have length 1
leases should contain only
singleLeaseWithoutSomeData._2
}
}
it should "parse multiple entries" in {
inside(Grammar(multipleLeases._1).right.value) {
case Result(leases, serverDuid) =>
serverDuid shouldEqual None
leases.length shouldEqual multipleLeases._2.length
leases should contain theSameElementsAs multipleLeases._2
}
}
it should "parse entry with server-duid" in {
inside(Grammar(singleLeaseWithServerDuid._1).right.value) {
case result @ Result(leases, serverDuid) =>
result shouldEqual singleLeaseWithServerDuid._2
}
}
it should "not fail when unknow entry appears in file stream" in {
Grammar(singleLeaseWithServerDuid._1 + "\n whatever can be here\n").isRight shouldBe true
}
it should "not fail when comment line appears in file stream" in {
Grammar("# any comment here\n" + singleLeaseWithServerDuid._1).isRight shouldBe true
}
}