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


Scala FeatureSpec类代码示例

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


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

示例1: AppSpec

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

import org.scalatest.{FeatureSpec, GivenWhenThen}

class AppSpec extends FeatureSpec with GivenWhenThen {

  info("As an app developer I want to be able to access the app, its settings and properties")

  feature("Application class") {
    scenario("can be instantiated in Headless mode") {
      Given("a default location app.Main for the app")
      When("the class is instantiated as a headless")
      val application = new app.Main(true)
      Then("the object should be instantiated")
      assert(application.isInstanceOf[app.Main])
    }
  }
} 
开发者ID:Y-Experiment,项目名称:LW3D,代码行数:19,代码来源:AppSpec.scala

示例2: ReadFromFileSpec

//设置package包名称以及导入依赖的类
import org.scalatest.{FeatureSpec, GivenWhenThen}


class ReadFromFileSpec extends FeatureSpec with GivenWhenThen {

  info("As a user from PSP1")
  info("I want to calculate the mean of a file compound by decimal numbers")
  info("So I don't have to type them manually")
  info("And save my time")

  feature("Calculate mean") {
    scenario("User sends a file with the numbers, one per line") {
      val fileName = getClass.getResource("test.txt").getFile
      Given("the file is not empty")
      assert(scala.io.Source.fromFile(fileName).getLines().nonEmpty)
      Given("the file has just numbers")
      assert(!scala.io.Source.fromFile(fileName).getLines().exists(!ReadFromFile.isAllDigits(_)))
      When("the mean is calculated for that file")
      val list = ReadFromFile.getListFromFile(fileName)
      val mean = list.mean
      Then("the result should be a decimal number")
      assert(mean.isInstanceOf[Double])
    }
  }
} 
开发者ID:camilosampedro,项目名称:PSP-TDD,代码行数:26,代码来源:ReadFromFileSpec.scala

示例3: PtxTrackleTransformerServiceTest

//设置package包名称以及导入依赖的类
package com.ubirch.avatar.transformer.services

import com.typesafe.scalalogging.slf4j.StrictLogging
import com.ubirch.transformer.services.PtxTransformerService
import com.ubirch.util.json.MyJsonProtocol
import org.scalatest.{FeatureSpec, Matchers}


class PtxTrackleTransformerServiceTest extends FeatureSpec
  with Matchers
  with StrictLogging
  with MyJsonProtocol {

  feature("PTX") {
    scenario("temp gt 0") {
      val adc1: BigDecimal = 21285.0
      val t1: BigDecimal = 24.69

      PtxTransformerService.pt100_temperature(adc = adc1).setScale(2, BigDecimal.RoundingMode.HALF_UP) shouldBe t1
    }

    scenario("temp lt 0") {
      val adc1: BigDecimal = 10.0
      val t1: BigDecimal = -241.91

      PtxTransformerService.pt100_temperature(adc = adc1).setScale(2, BigDecimal.RoundingMode.HALF_UP) shouldBe t1
    }
  }
} 
开发者ID:ubirch,项目名称:ubirch-avatar-service,代码行数:30,代码来源:PtxTrackleTransformerServiceTest.scala

示例4: HealthCheckFeature

//设置package包名称以及导入依赖的类
package com.reactivecore.quotes.workshop.api.feature

import com.reactivecore.quotes.workshop.api.QuotesWorkshopApiService
import org.scalatest.concurrent.{PatienceConfiguration, ScalaFutures}
import org.scalatest.time.{Seconds, Span}
import org.scalatest.{FeatureSpec, GivenWhenThen, Matchers}
import play.api.http.Status

class HealthCheckFeature extends FeatureSpec with GivenWhenThen with Matchers with ScalaFutures with PatienceConfiguration {

  override implicit val patienceConfig = PatienceConfig(
    timeout = scaled(Span(1, Seconds))
  )

  feature("health check") {
    scenario("service is healthy") {
      Given("a service")
      val service = QuotesWorkshopApiService()

      When("getting the /health endpoint")
      val response = get(s"http://localhost:${service.port}/health").futureValue

      Then("the response status should be OK")
      response.status should be(Status.OK)

      service.stop()
    }
  }

} 
开发者ID:bschaff,项目名称:quotes-workshop-api,代码行数:31,代码来源:HealthCheckFeature.scala

示例5: OptionsFeature

//设置package包名称以及导入依赖的类
package com.reactivecore.quotes.workshop.api.feature

import com.reactivecore.quotes.workshop.api.QuotesWorkshopApiService
import org.scalatest.concurrent.{PatienceConfiguration, ScalaFutures}
import org.scalatest.time.{Seconds, Span}
import org.scalatest.{FeatureSpec, GivenWhenThen, Matchers}
import play.api.http.Status

class OptionsFeature extends FeatureSpec with GivenWhenThen with Matchers with ScalaFutures with PatienceConfiguration {

  override implicit val patienceConfig = PatienceConfig(
    timeout = scaled(Span(1, Seconds))
  )

  feature("options") {
    scenario("requests options of /items") {
      Given("a service")
      val service = QuotesWorkshopApiService()

      When("requesting for the options of /items endpoint")
      val response = options(s"http://localhost:${service.port}/items").futureValue

      Then("the response status should be OK")
      response.status should be(Status.OK)

      service.stop()
    }
  }

} 
开发者ID:bschaff,项目名称:quotes-workshop-api,代码行数:31,代码来源:OptionsFeature.scala

示例6: GreetingEndpointFeature

//设置package包名称以及导入依赖的类
package org.akka.templates.features

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.testkit.ScalatestRouteTest
import org.akka.templates.endpoints.GreetingEndpoint
import org.scalatest.{FeatureSpec, Matchers}
import org.akka.templates.response.rejection._


class GreetingEndpointFeature
  extends FeatureSpec
    with Matchers
    with ScalatestRouteTest
    with GreetingEndpoint {

  feature("greeting api") {
    scenario("successful get") {
      Get(s"/api/greetings?name=gabriel&greeting=hello") ~> Route.seal(apiRoute) ~> check {
        status shouldBe StatusCodes.OK
        responseAs[String] should include (s"hello, gabriel")
      }
    }

    scenario("unprocessable entity get") {
      Get(s"/api/greetings?name=gabriel&greeting=") ~> Route.seal(apiRoute) ~> check {
        status shouldBe StatusCodes.UnprocessableEntity
      }
    }
  }
} 
开发者ID:gabfssilva,项目名称:akka-http-microservice-templates,代码行数:32,代码来源:GreetingEndpointFeature.scala

示例7: Prod1FeatureTest

//设置package包名称以及导入依赖的类
package com.stulsoft.pscalatest.prod.integrationTest

import com.stulsoft.pscalatest.prod.Prod1

import org.scalatest.{FeatureSpec, GivenWhenThen}


class Prod1FeatureTest extends FeatureSpec with GivenWhenThen {
  info("As owner")
  info("I want increase age")
  info("So I can increase age when I want")
  feature("Prod1") {
    scenario("Increasing p1") {
      Given("a Prod1 object with p1 = 1")
      val p = Prod1(1, "test")
      When("increase p1 by 1")
      p.incrementP1(1)
      Then("p1 must be 2")
      assert(p.p1 == 2)
    }
  }
} 
开发者ID:ysden123,项目名称:poc,代码行数:23,代码来源:Prod1FeatureTest.scala

示例8: EventSourcingTest

//设置package包名称以及导入依赖的类
package br.com.uol.plataforma.event.sourcing

import java.util.UUID

import br.com.uol.plataforma.event.sourcing.commands.BankAccountCommands._
import br.com.uol.plataforma.event.sourcing.model.{Event, Request}
import br.com.uol.plataforma.event.sourcing.player.EventPlayer._
import br.com.uol.plataforma.event.sourcing.state.BankAccount
import br.com.uol.plataforma.event.sourcing.store.BankAccountEventStore.eventStore
import org.scalatest.{FeatureSpec, Matchers}


class EventSourcingTest extends FeatureSpec with Matchers {
  feature("Creating an account and then closing it") {
    scenario("Create an account and then assert that replay restores the actual state of the BankAccount object") {
      val aggregationId = UUID.randomUUID().toString

      val f =
        createAccount(Request("owner" -> "John Doe", "id" -> 123))
          .andThen(deposit(Request("amount" -> 20)))
          .andThen(changeOwner(Request("newOwner" -> "Jane Doe")))
          .andThen(withdrawal(Request("amount" -> 10)))
          .andThen(close(Request("reason" -> "Unavailable address")))

      val actualState: BankAccount = f(BankAccount(aggregationId))
      val events: Seq[Event[BankAccount]] = eventStore.get(aggregationId)
      val playedState: BankAccount = events.play(BankAccount(aggregationId))

      actualState shouldEqual playedState
    }
  }
} 
开发者ID:gabfssilva,项目名称:event-sourcing-sample,代码行数:33,代码来源:EventSourcingTest.scala

示例9: BlacklistSpecification

//设置package包名称以及导入依赖的类
package scorex.network

import java.net.{InetAddress, InetSocketAddress}

import com.typesafe.config.ConfigFactory
import com.wavesplatform.network.PeerDatabaseImpl
import com.wavesplatform.settings.NetworkSettings
import net.ceedubs.ficus.Ficus._
import org.scalatest.{FeatureSpec, GivenWhenThen}

class BlacklistSpecification extends FeatureSpec with GivenWhenThen {
  private val config = ConfigFactory.parseString(
    """waves.network {
      |  known-peers = []
      |  file = null
      |  black-list-residence-time: 1s
      |}""".stripMargin).withFallback(ConfigFactory.load()).resolve()

  private val networkSettings = config.as[NetworkSettings]("waves.network")

  info("As a Peer")
  info("I want to blacklist other peers for certain time")
  info("So I can give them another chance after")

  feature("Blacklist") {
    scenario("Peer blacklist another peer") {

      Given("Peer database is empty")
      val peerDatabase = new PeerDatabaseImpl(networkSettings)

      def isBlacklisted(address: InetSocketAddress) = peerDatabase.blacklistedHosts.contains(address.getAddress)

      assert(peerDatabase.knownPeers.isEmpty)
      assert(peerDatabase.blacklistedHosts.isEmpty)

      When("Peer adds another peer to knownPeers")
      val address = new InetSocketAddress(InetAddress.getByName("localhost"), 1234)
      peerDatabase.touch(address)
      assert(peerDatabase.knownPeers.contains(address))
      assert(!isBlacklisted(address))

      And("Peer blacklists another peer")
      peerDatabase.blacklist(address.getAddress)
      assert(isBlacklisted(address))
      assert(!peerDatabase.knownPeers.contains(address))

      And("Peer waits for some time")
      Thread.sleep(networkSettings.blackListResidenceTime.toMillis + 500)

      Then("Another peer disappear from blacklist")
      assert(!isBlacklisted(address))

      And("Another peer became known")
      assert(peerDatabase.knownPeers.contains(address))
    }
  }
} 
开发者ID:wavesplatform,项目名称:Waves,代码行数:58,代码来源:BlacklistSpecification.scala

示例10: GuaranteeRepositoryTest

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

import domain.Guarantee
import org.scalatest.{FeatureSpec, GivenWhenThen}

import scala.concurrent.Await


class GuaranteeRepositoryTest extends FeatureSpec with GivenWhenThen{

  feature("Create guarantee") {
    info("Add guarantee")
    scenario("Add new guarantee ") {
      Given("Given all data")
      val guaranteeId = "12345678"
      val amount = 120000
      val currency = "US"

      Then("Add guarantee ")
      val guarantee = Guarantee(guaranteeId, amount, currency)
      val guaranteeRepo = GuaranteeRepository
      guaranteeRepo.save(guarantee)
      Then("Display All ")
      val displayAllGuarantee = Await.result(guaranteeRepo.getGuaranteeById(guaranteeId), 2 minutes)
      displayAllGuarantee.foreach(i => println("Guarantee=======>", i))
      val displayIdStatus = Await.result(guaranteeRepo.getGuaranteeById(guaranteeId), 2 minutes)
      displayIdStatus.foreach(i => println("GuaranteeStatus=======>", i))
    }
  }
} 
开发者ID:boniface,项目名称:opsapi,代码行数:31,代码来源:GuaranteeRepositoryTest.scala

示例11: FeatureRepositoryTest

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

import domain.Feature
import org.scalatest.{FeatureSpec, GivenWhenThen}


class FeatureRepositoryTest extends FeatureSpec with GivenWhenThen{

  feature("Create feature") {
    info("Add an feature")
    scenario("Add new feature ") {
      Given("Given all data")
      val featureId = "123456"
      val code = "code"
      val featureOf = "featureOf"
      val relatedItem = "relatedItem"
      val title = "title"
      val description = "description"
      val enum = "featurevalue"

      Then("Add feature ")
      val feature = Feature(featureId, code, featureOf, relatedItem, title, description, enum)
      val featureRepo = FeatureRepository
      featureRepo.save(feature)
      Then("Display All ")
      val displayAllcancelled = Await.result(featureRepo.getFeatureById(featureId), 2 minutes)
      displayAllfeature.foreach(i => println("Feature=======>", i))
      val displayIdStatus = Await.result(featureRepo.getFeatureById(featureId), 2 minutes)
      displayIdStatus.foreach(i => println("FeatureStatus=======>", i))
    }
    }
  } 
开发者ID:boniface,项目名称:opsapi,代码行数:33,代码来源:FeatureRepositoryTest.scala

示例12: CancellationRepositoryTest

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

import domain.Cancellation
import org.scalatest.{FeatureSpec, GivenWhenThen}
import repositories.CancellationRepository

import scala.concurrent.Await


class CancellationRepositoryTest extends FeatureSpec with GivenWhenThen {

  feature("Create cancellation") {
    info("Add an cancellation")
    scenario("Add new cancellation ") {
      Given("Given cancellationId,reason,date,status,document,cancellationOf,relatedLot")
      val cancellationId = "12345"
      val reason = "Nothing"
      val date = "26/18/12"
      val status = "Done"
      val documents = "Documnets"
      val cancellationOf = "Bond"
      val relatedLot = "related"

      Then("Add cancellation ")
      val cancellation = Cancellation(cancellationId,reason,date,status,documents,cancellationOf,cancellationOf,relatedLot)
      val cancellationRepo = CancellationRepository
      cancellationRepo.save(cancellation)
      Then("Display All ")
      val displayAllcancelled = Await.result(cancellationRepo.getCancellationById(cancellationId), 2 minutes)
      displayAllcancelled.foreach(i => println("Cancellation=======>", i))
      val displayIdStatus = Await.result(cancellationRepo.getCancellationById(cancellationId), 2 minutes)
      displayIdStatus.foreach(i => println("CancellationStatus=======>", i))
    }
  }

} 
开发者ID:boniface,项目名称:opsapi,代码行数:37,代码来源:CancellationRepositoryTest.scala

示例13: RevisionRepositoryTest

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

import domain.{Revision}
import org.scalatest.{FeatureSpec, GivenWhenThen}

import scala.collection.mutable
import scala.concurrent.Await


class RevisionRepositoryTest extends FeatureSpec with GivenWhenThen{

  feature("Create revision") {
    info("Add revision")
    scenario("Add new revision ") {
      Given("Given all data")
      val revisionId = "12345678"
      val date = "25/12/2016"
      val changes = mutable.MutableList[Object]()

      Then("Add guarantee ")
      val revision = Revision(revisionId, date, changes)
      val revisionRepo = RevisionRepository
      revisionRepo.save(revision)
      Then("Display All ")
      val displayAllRevision= Await.result(revisionRepo.getGuaranteeById(revisionId), 2 minutes)
      displayAllRevision.foreach(i => println("Revision=======>", i))
      val displayIdStatus = Await.result(revisionRepo.getGuaranteeById(revisionId), 2 minutes)
      displayIdStatus.foreach(i => println("RevisionStatus=======>", i))
    }
  }
} 
开发者ID:boniface,项目名称:opsapi,代码行数:32,代码来源:RevisionRepositoryTest.scala

示例14: ConfigurationTest

//设置package包名称以及导入依赖的类
package com.microsoft.azure.iot.iothubreact.checkpointing

import com.microsoft.azure.iot.iothubreact.checkpointing.backends.cassandra.lib.Auth
import com.typesafe.config.{Config, ConfigException}
import org.mockito.Mockito._
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{FeatureSpec, GivenWhenThen}

class ConfigurationTest extends FeatureSpec with GivenWhenThen with MockitoSugar {

  info("As a configured instance")
  info("I want logic around returned values to be consistent with application expectations")

  val confPath = "iothub-react.checkpointing."
  Feature("Configuration Cassandra authorization") {

    Scenario("Only one of username or password is supplied") {
      var cfg = mock[Config]
      when(cfg.getString(confPath + "storage.cassandra.username")).thenReturn("username")
      when(cfg.getString(confPath + "storage.cassandra.password")).thenThrow(new ConfigException.Missing("path"))
      assert(new CPConfiguration(cfg).cassandraAuth == None)

      cfg = mock[Config]
      when(cfg.getString(confPath + "storage.cassandra.username")).thenThrow(new ConfigException.Missing("path"))
      when(cfg.getString(confPath + "storage.cassandra.password")).thenReturn("password")
      assert(new CPConfiguration(cfg).cassandraAuth == None)
    }

    Scenario("Both username and password are supplied") {
      var cfg = mock[Config]
      when(cfg.getString(confPath + "storage.cassandra.username")).thenReturn("username")
      when(cfg.getString(confPath + "storage.cassandra.password")).thenReturn("password")
      assert(new CPConfiguration(cfg).cassandraAuth == Some(Auth("username", "password")))
    }
  }

  Feature("Storage namespace") {

    Scenario("Cassandra has a special namespace value") {
      var cfg = mock[Config]
      when(cfg.getString(confPath + "storage.namespace")).thenReturn("")

      when(cfg.getString(confPath + "storage.backendType")).thenReturn("anythingbutcassandra")
      assert(new CPConfiguration(cfg).storageNamespace == "iothub-react-checkpoints")

      when(cfg.getString(confPath + "storage.backendType")).thenReturn("AZUREBLOB")
      assert(new CPConfiguration(cfg).storageNamespace == "iothub-react-checkpoints")

      when(cfg.getString(confPath + "storage.backendType")).thenReturn("CASSANDRA")
      assert(new CPConfiguration(cfg).storageNamespace == "iothub_react_checkpoints")
    }
  }
} 
开发者ID:Azure,项目名称:toketi-iothubreact,代码行数:54,代码来源:ConfigurationTest.scala

示例15: CPConfigurationTest

//设置package包名称以及导入依赖的类
// Copyright (c) Microsoft. All rights reserved.

package com.microsoft.azure.iot.iothubreact.checkpointing

import com.microsoft.azure.iot.iothubreact.checkpointing.backends.cassandra.lib.Auth
import com.typesafe.config.{Config, ConfigException}
import org.mockito.Mockito._
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{FeatureSpec, GivenWhenThen}

class CPConfigurationTest extends FeatureSpec with GivenWhenThen with MockitoSugar {

  info("As a configured instance")
  info("I want logic around returned values to be consistent with application expectations")

  val confPath = "iothub-react.checkpointing."
  Feature("Configuration Cassandra authorization") {

    Scenario("Only one of username or password is supplied") {
      var cfg = mock[Config]
      when(cfg.getString(confPath + "storage.cassandra.username")).thenReturn("username")
      when(cfg.getString(confPath + "storage.cassandra.password")).thenThrow(new ConfigException.Missing("path"))
      assert(new CPConfiguration(cfg).cassandraAuth == None)

      cfg = mock[Config]
      when(cfg.getString(confPath + "storage.cassandra.username")).thenThrow(new ConfigException.Missing("path"))
      when(cfg.getString(confPath + "storage.cassandra.password")).thenReturn("password")
      assert(new CPConfiguration(cfg).cassandraAuth == None)
    }

    Scenario("Both username and password are supplied") {
      var cfg = mock[Config]
      when(cfg.getString(confPath + "storage.cassandra.username")).thenReturn("username")
      when(cfg.getString(confPath + "storage.cassandra.password")).thenReturn("password")
      assert(new CPConfiguration(cfg).cassandraAuth == Some(Auth("username", "password")))
    }
  }

  Feature("Storage namespace") {

    Scenario("Cassandra has a special namespace value") {
      var cfg = mock[Config]
      when(cfg.getString(confPath + "storage.namespace")).thenReturn("")

      when(cfg.getString(confPath + "storage.backendType")).thenReturn("anythingbutcassandra")
      assert(new CPConfiguration(cfg).storageNamespace == "iothub-react-checkpoints")

      when(cfg.getString(confPath + "storage.backendType")).thenReturn("AZUREBLOB")
      assert(new CPConfiguration(cfg).storageNamespace == "iothub-react-checkpoints")

      when(cfg.getString(confPath + "storage.backendType")).thenReturn("CASSANDRA")
      assert(new CPConfiguration(cfg).storageNamespace == "iothub_react_checkpoints")
    }
  }
} 
开发者ID:Azure,项目名称:toketi-iothubreact,代码行数:56,代码来源:CPConfigurationTest.scala


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