This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//creates a fake Play 2.0 server running on 3333 which defines the gatling plugin automatically | |
val server = Util.createServer(3333) | |
//function that starts the server, should be used in a specs Step BEFORE the whole specification starts | |
def startServer { | |
server.start() | |
} | |
//function that stops the server, should be used in a specs Step AFTER the whole specification has ran | |
def stopServer { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class ValidationPromised[E, A](promised: Promise[Validation[E, A]]) { | |
def map[B](f: A => B): ValidationPromised[E, B] = | |
ValidationPromised(promised map { valid => | |
valid.fold( | |
fail => KO(fail), | |
suc => OK(f(suc)) | |
) | |
}) | |
def flatMap[B](f: A => ValidationPromised[E, B]): ValidationPromised[E, B] = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val stealUserName = Intercept( | |
r => Cache.getAs[String]("username").toSuccess(NonEmptyList("No username")), | |
(err, v:Failure[NonEmptyList[String], String]) => BadRequest(v.e.list.mkString("\n")) | |
) | |
val stealUserId = Intercept( | |
r => Cache.getAs[String]("userid").map(_.toInt).toSuccess(NonEmptyList("No userid")), | |
(err, v:Failure[NonEmptyList[String], Int]) => BadRequest(v.e.list.mkString("\n")) | |
) | |
val stealUserNameAndId = Intercept( | |
r => for { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val securedByUserName = Intercept( | |
r => Cache.getAs[String]("username").toSuccess(NonEmptyList("No username")), | |
(err, v:Failure[NonEmptyList[String], String]) => Unauthorized(v.e.list.mkString("\n")) | |
) | |
val securedByUserId = Intercept( | |
r => Cache.getAs[String]("userid").map(_.toInt).toSuccess(NonEmptyList("No userid")), | |
(err, v:Failure[NonEmptyList[String], Int]) => Unauthorized(v.e.list.mkString("\n")) | |
) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
import Keys._ | |
import GatlingPlugin._ | |
object MinimalBuild extends Build { | |
val SNAPSHOT = "-SNAPSHOT" | |
val appName = "gatling-sbt-sample" | |
val buildVersion = "0.0.1-SNAPSHOT" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Banque(nom:String) {banque => | |
def accepte(m:Montant) = | |
CompteBuilder(banque, m) | |
} | |
implicit def stringToBanque(s:String) = Banque(s) | |
implicit def intWithDevise(i:Int) = new { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tc | |
object Main extends App { | |
import tc.Action._ | |
import tc.Generator._ | |
import tc.User._ | |
// a user | |
val user = User(None, "noootsab", true, 31) | |
println(s"User $user") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Covariant extends App { | |
trait Vehicle { | |
def name:String | |
def velocity:Float | |
} | |
case class Car(name:String, velocity:Float) extends Vehicle | |
object VehiculeStats { | |
def meanVelocity(vs:List[Vehicle]):Float = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
object Template { | |
case object A { | |
def apply(i:Int) = "A " + i | |
} | |
case object B { | |
def apply() = "B" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api.libs.json._ | |
//this is crap but ease a lot the switch to play 2.1 | |
implicit def smashThat[A](js:JsResult[A]):A = js.recoverTotal { err => throw new RuntimeException(Json.stringify(JsError.toFlatJson(err))) } | |
val j = Json.obj("a"->1, "b"->2) | |
val m:Map[String, Int] = Json.fromJson[Map[String, Int]](j) |