当前位置: 首页>>代码示例>>Scala>>正文


Scala BeforeAndAfterAll类代码示例

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


在下文中一共展示了BeforeAndAfterAll类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: DataLoadSuite

//设置package包名称以及导入依赖的类
import org.apache.hadoop.hbase.client.Scan
import org.apache.hadoop.hbase.{TableName, HBaseTestingUtility}
import org.apache.hadoop.hbase.util.Bytes
import org.scalatest.{FunSuite, BeforeAndAfterEach, BeforeAndAfterAll}


class DataLoadSuite extends FunSuite with BeforeAndAfterEach with BeforeAndAfterAll {

  var htu: HBaseTestingUtility = null

  override def beforeAll() {

    htu = HBaseTestingUtility.createLocalHTU()

    htu.cleanupTestDir()
    println("starting minicluster")
    htu.startMiniZKCluster()
    htu.startMiniHBaseCluster(1, 1)
    println(" - minicluster started")
    try {
      htu.deleteTable(Bytes.toBytes(HBaseContants.tableName))
    } catch {
      case e: Exception => {
        println(" - no table " + HBaseContants.tableName + " found")
      }
    }
    println(" - creating table " + HBaseContants.tableName)
    htu.createTable(Bytes.toBytes(HBaseContants.tableName), HBaseContants.columnFamily)
    println(" - created table")

  }

  override def afterAll() {
    htu.deleteTable(Bytes.toBytes(HBaseContants.tableName))
    println("shuting down minicluster")
    htu.shutdownMiniHBaseCluster()
    htu.shutdownMiniZKCluster()
    println(" - minicluster shut down")
    htu.cleanupTestDir()
  }

  test("test the load") {
    HBasePopulator.populate(100, 5000, 1, htu.getConnection, HBaseContants.tableName)
    HBasePopulator.megaScan(htu.getConnection, HBaseContants.tableName)

    val table = htu.getConnection.getTable(TableName.valueOf(HBaseContants.tableName))

    println("Single Record Test")

    val scan = new Scan()
    scan.setStartRow(Bytes.toBytes("10_"))
    scan.setStopRow(Bytes.toBytes("10__"))
    scan.setCaching(1)
    val scanner = table.getScanner(scan)
    val it = scanner.iterator()
    val result = it.next()
    println(" - " + Bytes.toString(result.getRow) + ":" +
      Bytes.toString(result.getValue(HBaseContants.columnFamily,
        HBaseContants.column)))
  }
} 
开发者ID:khajaasmath786,项目名称:HBASEScalaSBT-Spark,代码行数:62,代码来源:DataLoadSuite.scala

示例2: CountriesDestroySpec

//设置package包名称以及导入依赖的类
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.PlaySpec

import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.FakeRequest
import play.api.test.Helpers._

import play.api.libs.json._

import test.helpers.{DatabaseCleaner, DatabaseInserter}

import play.api.Play

import utils.TimeUtil.now

class CountriesDestroySpec extends PlaySpec with BeforeAndAfterAll {
  val app = new GuiceApplicationBuilder().build

  override def beforeAll() {
    Play.maybeApplication match {
      case Some(app) => ()
      case _ => Play.start(app)
    }

    DatabaseCleaner.clean(List("Countries"))
    DatabaseInserter.insert("Users", 12, List("[email protected]", "John", "Doe", "password", "token", now.toString, "User", "1", "999999", "2016-01-01"))
    DatabaseInserter.insert("Users", 13, List("[email protected]", "Johnny", "Doe", "password", "admin_token", now.toString, "Admin", "1", "999999", "2016-01-01"))
    DatabaseInserter.insert("Countries", 11, List("Denmark", "DEN", "1", "2016-10-10"))
  }

  override def afterAll() {
    DatabaseCleaner.clean(List("Countries"))
  }

  "deleting countries" should {
    "returns 404 if no such record" in {
      val request = FakeRequest(DELETE, "/countries/200").withHeaders("Authorization" -> "admin_token")
      val destroy = route(app, request).get

      status(destroy) mustBe NOT_FOUND
    }

    "returns 204 if successfully deleted and user is Admin" in {
      val request = FakeRequest(DELETE, "/countries/11").withHeaders("Authorization" -> "admin_token")
      val destroy = route(app, request).get

      status(destroy) mustBe NO_CONTENT
    }

    "returns 403 if user is not Admin" in {
      val request = FakeRequest(DELETE, "/countries/11").withHeaders("Authorization" -> "token")
      val destroy = route(app, request).get

      status(destroy) mustBe FORBIDDEN
    }
  }
} 
开发者ID:dsounded,项目名称:money_exchanger,代码行数:58,代码来源:CountriesDestroySpec.scala

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

示例4: LagomhandsondevelopmentServiceSpec

//设置package包名称以及导入依赖的类
package com.example.lagomhandsondevelopment.impl

import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import com.example.lagomhandsondevelopment.api._

class LagomhandsondevelopmentServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {

  private val server = ServiceTest.startServer(
    ServiceTest.defaultSetup
      .withCassandra(true)
  ) { ctx =>
    new LagomhandsondevelopmentApplication(ctx) with LocalServiceLocator
  }

  val client = server.serviceClient.implement[LagomhandsondevelopmentService]

  override protected def afterAll() = server.stop()

  "lagom-hands-on-development service" should {

    "say hello" in {
      client.hello("Alice").invoke().map { answer =>
        answer should ===("Hello, Alice!")
      }
    }

    "allow responding with a custom message" in {
      for {
        _ <- client.useGreeting("Bob").invoke(GreetingMessage("Hi"))
        answer <- client.hello("Bob").invoke()
      } yield {
        answer should ===("Hi, Bob!")
      }
    }
  }
} 
开发者ID:negokaz,项目名称:lagom-hands-on-development.scala,代码行数:39,代码来源:LagomhandsondevelopmentServiceSpec.scala

示例5: HelloEntitySpec

//设置package包名称以及导入依赖的类
package se.hultner.hello.impl

import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec}

class HelloEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {

  private val system = ActorSystem("HelloEntitySpec",
    JsonSerializerRegistry.actorSystemSetupFor(HelloSerializerRegistry))

  override protected def afterAll(): Unit = {
    TestKit.shutdownActorSystem(system)
  }

  private def withTestDriver(block: PersistentEntityTestDriver[HelloCommand[_], HelloEvent, HelloState] => Unit): Unit = {
    val driver = new PersistentEntityTestDriver(system, new HelloEntity, "hello-1")
    block(driver)
    driver.getAllIssues should have size 0
  }

  "Hello entity" should {

    "say hello by default" in withTestDriver { driver =>
      val outcome = driver.run(Hello("Alice", None))
      outcome.replies should contain only "Hello, Alice!"
    }

    "allow updating the greeting message" in withTestDriver { driver =>
      val outcome1 = driver.run(UseGreetingMessage("Hi"))
      outcome1.events should contain only GreetingMessageChanged("Hi")
      val outcome2 = driver.run(Hello("Alice", None))
      outcome2.replies should contain only "Hi, Alice!"
    }

  }
} 
开发者ID:Hultner,项目名称:hello_scala_microservices,代码行数:40,代码来源:HelloEntitySpec.scala

示例6: HelloServiceSpec

//设置package包名称以及导入依赖的类
package se.hultner.hello.impl

import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import se.hultner.hello.api._

class HelloServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {

  private val server = ServiceTest.startServer(
    ServiceTest.defaultSetup
      .withCassandra(true)
  ) { ctx =>
    new HelloApplication(ctx) with LocalServiceLocator
  }

  val client = server.serviceClient.implement[HelloService]

  override protected def afterAll() = server.stop()

  "Hello service" should {

    "say hello" in {
      client.hello("Alice").invoke().map { answer =>
        answer should ===("Hello, Alice!")
      }
    }

    "allow responding with a custom message" in {
      for {
        _ <- client.useGreeting("Bob").invoke(GreetingMessage("Hi"))
        answer <- client.hello("Bob").invoke()
      } yield {
        answer should ===("Hi, Bob!")
      }
    }
  }
} 
开发者ID:Hultner,项目名称:hello_scala_microservices,代码行数:39,代码来源:HelloServiceSpec.scala

示例7: MemoryBufferSpec

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.s3.impl

import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorMaterializerSettings}
import akka.stream.scaladsl.{Sink, Source}
import akka.testkit.TestKit
import akka.util.ByteString
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import org.scalatest.concurrent.ScalaFutures

class MemoryBufferSpec(_system: ActorSystem)
    extends TestKit(_system)
    with FlatSpecLike
    with Matchers
    with BeforeAndAfterAll
    with ScalaFutures {

  def this() = this(ActorSystem("MemoryBufferSpec"))

  implicit val defaultPatience =
    PatienceConfig(timeout = Span(5, Seconds), interval = Span(30, Millis))

  implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system).withDebugLogging(true))

  "MemoryBuffer" should "emit a chunk on its output containg the concatenation of all input values" in {
    val result = Source(Vector(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12), ByteString(13, 14)))
      .via(new MemoryBuffer(200))
      .runWith(Sink.seq)
      .futureValue

    result should have size (1)
    val chunk = result.head
    chunk.size should be(14)
    chunk.data.runWith(Sink.seq).futureValue should be(Seq(ByteString(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)))
  }

  it should "fail if more than maxSize bytes are fed into it" in {
    whenReady(
      Source(Vector(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12), ByteString(13, 14)))
        .via(new MemoryBuffer(10))
        .runWith(Sink.seq)
        .failed
    ) { e =>
      e shouldBe a[IllegalStateException]
    }
  }
} 
开发者ID:akka,项目名称:alpakka,代码行数:49,代码来源:MemoryBufferSpec.scala

示例8: SplitAfterSizeSpec

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.s3.impl

import akka.testkit.TestKit
import akka.stream.ActorMaterializerSettings
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import akka.stream.ActorMaterializer
import akka.actor.ActorSystem
import org.scalatest.Matchers
import org.scalatest.FlatSpecLike
import akka.stream.scaladsl.Source
import akka.stream.scaladsl.Flow
import akka.util.ByteString
import akka.stream.scaladsl.Sink
import org.scalatest.time.{Millis, Seconds, Span}
import scala.concurrent.duration._

class SplitAfterSizeSpec(_system: ActorSystem)
    extends TestKit(_system)
    with FlatSpecLike
    with Matchers
    with BeforeAndAfterAll
    with ScalaFutures {

  def this() = this(ActorSystem("SplitAfterSizeSpec"))
  implicit val defaultPatience =
    PatienceConfig(timeout = Span(5, Seconds), interval = Span(30, Millis))

  implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system).withDebugLogging(true))

  "SplitAfterSize" should "yield a single empty substream on no input" in {
    Source
      .empty[ByteString]
      .via(
        SplitAfterSize(10)(Flow[ByteString]).concatSubstreams
      )
      .runWith(Sink.seq)
      .futureValue should be(Seq.empty)
  }

  it should "start a new stream after the element that makes it reach a maximum, but not split the element itself" in {
    Source(Vector(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12), ByteString(13, 14)))
      .via(
        SplitAfterSize(10)(Flow[ByteString]).prefixAndTail(10).map { case (prefix, tail) => prefix }.concatSubstreams
      )
      .runWith(Sink.seq)
      .futureValue should be(
      Seq(
        Seq(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12)),
        Seq(ByteString(13, 14))
      )
    )
  }

} 
开发者ID:akka,项目名称:alpakka,代码行数:56,代码来源:SplitAfterSizeSpec.scala

示例9: Integration

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.sqs.scaladsl

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.amazonaws.auth.{AWSCredentialsProvider, AWSStaticCredentialsProvider, BasicAWSCredentials}
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.services.sqs.{AmazonSQSAsync, AmazonSQSAsyncClientBuilder}
import org.elasticmq.rest.sqs.{SQSRestServer, SQSRestServerBuilder}
import org.scalatest.{BeforeAndAfterAll, Suite, Tag}

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.util.Random

trait DefaultTestContext extends BeforeAndAfterAll { this: Suite =>

  lazy val sqsServer: SQSRestServer = SQSRestServerBuilder.withDynamicPort().start()
  lazy val sqsAddress = sqsServer.waitUntilStarted().localAddress
  lazy val sqsPort = sqsAddress.getPort
  lazy val sqsEndpoint: String = {
    s"http://${sqsAddress.getHostName}:$sqsPort"
  }

  object Integration extends Tag("akka.stream.alpakka.sqs.scaladsl.Integration")

  //#init-mat
  implicit val system = ActorSystem()
  implicit val mat = ActorMaterializer()
  //#init-mat

  val credentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials("x", "x"))

  implicit val sqsClient = createAsyncClient(sqsEndpoint, credentialsProvider)

  def randomQueueUrl(): String = sqsClient.createQueue(s"queue-${Random.nextInt}").getQueueUrl

  override protected def afterAll(): Unit = {
    super.afterAll()
    sqsServer.stopAndWait()
    Await.ready(system.terminate(), 5.seconds)
  }

  def createAsyncClient(sqsEndpoint: String, credentialsProvider: AWSCredentialsProvider): AmazonSQSAsync = {
    //#init-client
    val client: AmazonSQSAsync = AmazonSQSAsyncClientBuilder
      .standard()
      .withCredentials(credentialsProvider)
      .withEndpointConfiguration(new EndpointConfiguration(sqsEndpoint, "eu-central-1"))
      .build()
    //#init-client
    client
  }

} 
开发者ID:akka,项目名称:alpakka,代码行数:55,代码来源:DefaultTestContext.scala

示例10: CsvSpec

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.csv.scaladsl

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.testkit.TestKit
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Matchers, WordSpec}

abstract class CsvSpec
    extends WordSpec
    with Matchers
    with BeforeAndAfterAll
    with BeforeAndAfterEach
    with ScalaFutures {

  implicit val system = ActorSystem(this.getClass.getSimpleName)
  implicit val materializer = ActorMaterializer()

  override protected def afterAll(): Unit =
    TestKit.shutdownActorSystem(system)
} 
开发者ID:akka,项目名称:alpakka,代码行数:22,代码来源:CsvSpec.scala

示例11: TableSpec

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.dynamodb

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.alpakka.dynamodb.impl.DynamoSettings
import akka.stream.alpakka.dynamodb.scaladsl.DynamoClient
import akka.testkit.TestKit
import org.scalatest.{AsyncWordSpecLike, BeforeAndAfterAll, Matchers}

import scala.collection.JavaConverters._

class TableSpec extends TestKit(ActorSystem("TableSpec")) with AsyncWordSpecLike with Matchers with BeforeAndAfterAll {

  implicit val materializer = ActorMaterializer()
  implicit val ec = system.dispatcher

  val settings = DynamoSettings(system)
  val client = DynamoClient(settings)

  override def beforeAll() = {
    System.setProperty("aws.accessKeyId", "someKeyId")
    System.setProperty("aws.secretKey", "someSecretKey")
  }

  "DynamoDB Client" should {

    import TableSpecOps._
    import akka.stream.alpakka.dynamodb.scaladsl.DynamoImplicits._

    "1) create table" in {
      client.single(createTableRequest).map(_.getTableDescription.getTableName shouldEqual tableName)
    }

    "2) list tables" in {
      client.single(listTablesRequest).map(_.getTableNames.asScala.count(_ == tableName) shouldEqual 1)
    }

    "3) describe table" in {
      client.single(describeTableRequest).map(_.getTable.getTableName shouldEqual tableName)
    }

    "4) update table" in {
      client
        .single(describeTableRequest)
        .map(_.getTable.getProvisionedThroughput.getWriteCapacityUnits shouldEqual 10L)
        .flatMap(_ => client.single(updateTableRequest))
        .map(_.getTableDescription.getProvisionedThroughput.getWriteCapacityUnits shouldEqual newMaxLimit)
    }

    "5) delete table" in {
      client
        .single(deleteTableRequest)
        .flatMap(_ => client.single(listTablesRequest))
        .map(_.getTableNames.asScala.count(_ == tableName) shouldEqual 0)
    }

  }

} 
开发者ID:akka,项目名称:alpakka,代码行数:60,代码来源:TableSpec.scala

示例12: get

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

import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.play.{OneServerPerSuite, WsScalaTestClient}
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.ws.WSRequest
import uk.gov.hmrc.play.test.UnitSpec

trait DatabaseName {
  val testName: String = "updated-print-suppressions"
}

trait TestServer
  extends ScalaFutures
    with DatabaseName
    with UnitSpec
    with BeforeAndAfterAll
    with OneServerPerSuite
    with WsScalaTestClient {

  override implicit lazy val app = new GuiceApplicationBuilder()
    .configure(Map("auditing.enabled" -> false,
      "mongodb.uri" -> "mongodb://localhost:27017/updated-print-suppressions",
      "application.router" -> "testOnlyDoNotUseInAppConf.Routes"
    ))
    .build()


  def `/preferences/sa/individual/print-suppression`(updatedOn: Option[String], offset: Option[String], limit: Option[String], isAdmin: Boolean = false) = {

    val queryString = List(
      updatedOn.map(value => "updated-on" -> value),
      offset.map(value => "offset" -> value),
      limit.map(value => "limit" -> value)
    ).flatten

    if (isAdmin)
      wsUrl("/test-only/preferences/sa/individual/print-suppression").withQueryString(queryString: _*)
    else
      wsUrl("/preferences/sa/individual/print-suppression").withQueryString(queryString: _*)
  }

  def get(url: WSRequest) = url.get().futureValue

} 
开发者ID:hmrc,项目名称:updated-print-suppressions,代码行数:47,代码来源:TestServer.scala

示例13: LagomshoppingEntitySpec

//设置package包名称以及导入依赖的类
package com.example.lagomshopping.impl

import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec}

class LagomshoppingEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {

  private val system = ActorSystem("LagomshoppingEntitySpec",
    JsonSerializerRegistry.actorSystemSetupFor(LagomshoppingSerializerRegistry))

  override protected def afterAll(): Unit = {
    TestKit.shutdownActorSystem(system)
  }

  private def withTestDriver(block: PersistentEntityTestDriver[LagomshoppingCommand[_], LagomshoppingEvent, LagomshoppingState] => Unit): Unit = {
    val driver = new PersistentEntityTestDriver(system, new LagomshoppingEntity, "lagomshopping-1")
    block(driver)
    driver.getAllIssues should have size 0
  }

  "LagomShopping entity" should {

    "say hello by default" in withTestDriver { driver =>
      val outcome = driver.run(Hello("Alice", None))
      outcome.replies should contain only "Hello, Alice!"
    }

    "allow updating the greeting message" in withTestDriver { driver =>
      val outcome1 = driver.run(UseGreetingMessage("Hi"))
      outcome1.events should contain only GreetingMessageChanged("Hi")
      val outcome2 = driver.run(Hello("Alice", None))
      outcome2.replies should contain only "Hi, Alice!"
    }

  }
} 
开发者ID:code-star,项目名称:lagom-playground,代码行数:40,代码来源:LagomshoppingEntitySpec.scala

示例14: gen

//设置package包名称以及导入依赖的类
package org.dsa.iot.scala

import scala.collection.JavaConverters._

import org.dsa.iot.dslink.node.value.Value
import org.dsa.iot.dslink.util.json.{ JsonArray, JsonObject }
import org.scalacheck.{ Gen, Arbitrary }
import org.scalatest.{ BeforeAndAfterAll, Matchers, Suite, WordSpecLike }
import org.scalatest.prop.GeneratorDrivenPropertyChecks


trait AbstractSpec extends Suite
    with WordSpecLike
    with Matchers
    with BeforeAndAfterAll
    with GeneratorDrivenPropertyChecks {

  import Arbitrary._

  object gen {
    val ids = Gen.identifier.map(_.take(10))
    val scalars = Gen.oneOf(arbitrary[Number], arbitrary[Boolean], arbitrary[String], arbitrary[Array[Byte]])
    val scalarLists = Gen.resize(10, Gen.listOf(scalars))
    val scalarJavaLists = scalarLists.map(_.asJava)
    val scalarMaps = Gen.resize(10, Gen.mapOf(Gen.zip(ids, scalars)))
    val scalarJavaMaps = scalarMaps.map(_.asJava)
    val anyLists = Gen.resize(10, Gen.listOf(Gen.oneOf(scalars, scalarLists, scalarMaps)))
    val anyMaps = Gen.resize(10, Gen.mapOf(Gen.zip(ids, Gen.oneOf(scalars, scalarLists, scalarMaps))))
    val any = Gen.oneOf(scalars, anyLists, anyMaps)
  }

  object valueGen {
    val bools = arbitrary[Boolean] map (new Value(_))

    val ints = arbitrary[Int] map (new Value(_))
    val longs = arbitrary[Long] map (new Value(_))
    val shorts = arbitrary[Short] map (new Value(_))
    val bytes = arbitrary[Byte] map (new Value(_))
    val doubles = arbitrary[Double] map (new Value(_))
    val floats = arbitrary[Float] map (new Value(_))
    val numbers = Gen.oneOf(ints, longs, shorts, bytes, doubles, floats)

    val strings = arbitrary[String] map (new Value(_))

    val binary = arbitrary[Array[Byte]] map (new Value(_))

    val scalarArrays = gen.scalarLists map (x => new JsonArray(x.asJava))

    val scalarMaps = gen.scalarMaps map (x => new JsonObject(x.asInstanceOf[Map[String, Object]].asJava))

    val arrays = scalarArrays map (new Value(_))

    val maps = scalarMaps map (new Value(_))
  }
} 
开发者ID:IOT-DSA,项目名称:sdk-dslink-scala,代码行数:56,代码来源:AbstractSpec.scala

示例15: MyS3ObjectTest

//设置package包名称以及导入依赖的类
package example

import better.files.File
import org.scalatest.{BeforeAndAfterAll, FunSuite}


class MyS3ObjectTest extends FunSuite with BeforeAndAfterAll {

  val s3 = MyS3.create()
  val bucketName = s"rysh-${localName()}-my-s3-object-test"
  val file = File("my-s3-object-test").createIfNotExists()

  override def beforeAll() {
    val bucket = s3.createBucket(bucketName)
  }

  override def afterAll() {
    file.delete()
    s3.deleteBucket(bucketName)
  }

  test("Upload an Object") {
    s3.upload(bucketName, "my-s3-object-test", file)
  }

  ignore("List Objects") {
    ???
  }

  ignore("Download an Object") {
    ???
  }

  ignore("Copy, Move, or Rename Objects") {
    ???
  }

  ignore("Delete an Object") {
    ???
  }

  ignore("Delete Multiple Objects at Once") {
    ???
  }
} 
开发者ID:rysh,项目名称:my-scala-playground,代码行数:46,代码来源:MyS3ObjectTest.scala


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