Created
September 18, 2017 17:53
-
-
Save mraible/daa4c7548f3f209f742a7cb2ede6a551 to your computer and use it in GitHub Desktop.
Gatling test for Keycloak Login
This file contains 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 _root_.io.gatling.core.scenario.Simulation | |
import ch.qos.logback.classic.{Level, LoggerContext} | |
import io.gatling.core.Predef._ | |
import io.gatling.http.Predef._ | |
import org.slf4j.LoggerFactory | |
import scala.concurrent.duration._ | |
/** | |
* Performance test for the Blog entity. | |
*/ | |
class BlogGatlingTest extends Simulation { | |
val context: LoggerContext = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext] | |
// Log all HTTP requests | |
//context.getLogger("io.gatling.http").setLevel(Level.valueOf("TRACE")) | |
// Log failed HTTP requests | |
//context.getLogger("io.gatling.http").setLevel(Level.valueOf("DEBUG")) | |
val baseURL = Option(System.getProperty("baseURL")) getOrElse """http://localhost:8080""" | |
val httpConf = http | |
.baseURL(baseURL) | |
.inferHtmlResources() | |
.acceptHeader("*/*") | |
.acceptEncodingHeader("gzip, deflate") | |
.acceptLanguageHeader("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3") | |
.connectionHeader("keep-alive") | |
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:33.0) Gecko/20100101 Firefox/33.0") | |
val headers_http = Map( | |
"Accept" -> """application/json""" | |
) | |
val headers_http_authenticated = Map( | |
"Accept" -> """application/json""", | |
"X-XSRF-TOKEN" -> "${xsrf_token}" | |
) | |
val scn = scenario("Test the Blog entity") | |
.exec(http("First unauthenticated request") | |
.get("/api/account") | |
.headers(headers_http) | |
.check(status.is(401))).exitHereIfFailed | |
.pause(10) | |
.exec(http("Authentication") | |
.get("/login") | |
.formParam("username", "admin") | |
.formParam("password", "admin") | |
.formParam("login", "Login") | |
.check(headerRegex("Set-Cookie", "XSRF-TOKEN=(.*);[\\s]").saveAs("xsrf_token"))).exitHereIfFailed | |
.pause(1) | |
.exec(http("Authenticated request") | |
.get("/api/account") | |
.headers(headers_http_authenticated) | |
.check(status.is(200))) | |
.pause(10) | |
.repeat(2) { | |
exec(http("Get all blogs") | |
.get("/api/blogs") | |
.headers(headers_http_authenticated) | |
.check(status.is(200))) | |
.pause(10 seconds, 20 seconds) | |
.exec(http("Create new blog") | |
.post("/api/blogs") | |
.headers(headers_http_authenticated) | |
.body(StringBody("""{"id":null, "name":"SAMPLE_TEXT"}""")).asJSON | |
.check(status.is(201)) | |
.check(headerRegex("Location", "(.*)").saveAs("new_blog_url"))).exitHereIfFailed | |
.pause(10) | |
.repeat(5) { | |
exec(http("Get created blog") | |
.get("${new_blog_url}") | |
.headers(headers_http_authenticated)) | |
.pause(10) | |
} | |
.exec(http("Delete created blog") | |
.delete("${new_blog_url}") | |
.headers(headers_http_authenticated)) | |
.pause(10) | |
} | |
val users = scenario("Users").exec(scn) | |
setUp( | |
users.inject(rampUsers(Integer.getInteger("users", 100)) over (Integer.getInteger("ramp", 1) minutes)) | |
).protocols(httpConf) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment