sourceval route =
setCookie(HttpCookie("userName", value ="paul")){
complete("The user was logged in")}// tests:Get("/")~> route ~> check {
responseAs[String] shouldEqual "The user was logged in"
header[`Set-Cookie`] shouldEqual Some(`Set-Cookie`(HttpCookie("userName", value ="paul")))}
sourceimport static akka.http.javadsl.server.Directives.complete;importstatic akka.http.javadsl.server.Directives.setCookie;finalRoute route = setCookie(HttpCookie.create("userName","paul"),()->
complete("The user was logged in"));// tests:finalHttpHeader expected =SetCookie.create(HttpCookie.create("userName","paul"));
testRoute(route).run(HttpRequest.GET("/")).assertEntity("The user was logged in").assertHeaderExists(expected);