Last active
August 29, 2015 13:57
-
-
Save hierynomus/9627861 to your computer and use it in GitHub Desktop.
Spray time-out with StatusCode 205
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
apply plugin: "scala" | |
apply plugin: "idea" | |
repositories { | |
maven { url "http://repo.spray.io" } | |
mavenCentral() | |
} | |
dependencies { | |
compile "org.scala-lang:scala-library:2.10.3" | |
compile "io.spray:spray-client:1.3.1" | |
compile "com.typesafe.akka:akka-actor_2.10:2.3.0" | |
compile "com.typesafe.akka:akka-slf4j_2.10:2.3.0" | |
testCompile "junit:junit:4.11" | |
testCompile "org.scalatest:scalatest_2.10:2.1.0" | |
testCompile "com.xebialabs.restito:restito:0.4-beta-2" | |
runtime "ch.qos.logback:logback-classic:1.0.9" | |
} | |
sourceSets.test.scala.srcDirs = [project.projectDir] |
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 org.scalatest.{BeforeAndAfterAll, ShouldMatchers, BeforeAndAfter, FunSpec} | |
import com.xebialabs.restito.server.StubServer | |
import com.xebialabs.restito.builder.stub.StubHttp._ | |
import com.xebialabs.restito.semantics.Condition._ | |
import com.xebialabs.restito.semantics.Action._ | |
import org.glassfish.grizzly.http.util.HttpStatus | |
import akka.actor.ActorSystem | |
import spray.client.pipelining._ | |
import scala.concurrent.{Await, Future} | |
import spray.http.{StatusCodes, HttpResponse} | |
import scala.concurrent.duration._ | |
import language.postfixOps | |
import org.junit.runner.RunWith | |
import org.scalatest.junit.JUnitRunner | |
@RunWith(classOf[JUnitRunner]) | |
class Spray205Test extends FunSpec with BeforeAndAfterAll with ShouldMatchers { | |
var server: StubServer = _ | |
implicit var actorSystem: ActorSystem = _ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
override def beforeAll() { | |
server = new StubServer().run() | |
actorSystem = ActorSystem("yakshop-tester") | |
whenHttp(server).`match`(post("/reset-me"), withPostBody()).`then`(status(HttpStatus.RESET_CONTENT_205)) | |
whenHttp(server).`match`(post("/ok-me"), withPostBody()).`then`(status(HttpStatus.OK_200)) | |
} | |
override def afterAll() { | |
server.stop() | |
actorSystem.shutdown() | |
} | |
describe("Spray Client") { | |
it("should not time out when posting and getting a '200 OK' response status") { | |
val future: Future[HttpResponse] = Post(s"http://localhost:${server.getPort}/ok-me", "I want to be ok") ~> sendReceive | |
Await.result(future, 5 seconds).status should equal(StatusCodes.OK) | |
} | |
it("should not time out when posting and getting a '205 Reset Content' response status") { | |
val future: Future[HttpResponse] = Post(s"http://localhost:${server.getPort}/reset-me", "I want to reset") ~> sendReceive | |
Await.result(future, 5 seconds).status should equal(StatusCodes.ResetContent) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment