-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
OperationGatlingTest.java
108 lines (97 loc) · 4.42 KB
/
OperationGatlingTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package gatling.simulations;
import static io.gatling.javaapi.core.CoreDsl.StringBody;
import static io.gatling.javaapi.core.CoreDsl.exec;
import static io.gatling.javaapi.core.CoreDsl.rampUsers;
import static io.gatling.javaapi.core.CoreDsl.scenario;
import static io.gatling.javaapi.http.HttpDsl.headerRegex;
import static io.gatling.javaapi.http.HttpDsl.http;
import static io.gatling.javaapi.http.HttpDsl.status;
import io.gatling.javaapi.core.ChainBuilder;
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;
import java.time.Duration;
import java.util.Map;
import java.util.Optional;
/**
* Performance test for the Operation entity.
*
* @see <a href="https://github.com/jhipster/generator-jhipster/tree/v8.7.3/generators/gatling#logging-tips">Logging tips</a>
*/
public class OperationGatlingTest extends Simulation {
String baseURL = Optional.ofNullable(System.getProperty("baseURL")).orElse("http://localhost:8080");
HttpProtocolBuilder 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")
.silentResources(); // Silence all resources like css or css so they don't clutter the results
Map<String, String> headersHttp = Map.of("Accept", "application/json");
Map<String, String> headersHttpAuthenticated = Map.of("Accept", "application/json", "X-XSRF-TOKEN", "${xsrf_token}");
Map<String, String> keycloakHeaders = Map.of(
"Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Upgrade-Insecure-Requests",
"1"
);
ChainBuilder scn = exec(
http("First unauthenticated request")
.get("/api/account")
.headers(headersHttp)
.check(status().is(401))
.check(headerRegex("Set-Cookie", "XSRF-TOKEN=(.*);[\\s]").saveAs("xsrf_token"))
)
.exitHereIfFailed()
.pause(10)
.exec(
http("Authentication")
.post("/api/authentication")
.headers(headersHttpAuthenticated)
.formParam("username", "admin")
.formParam("password", "admin")
.formParam("remember-me", "true")
.formParam("submit", "Login")
.check(headerRegex("Set-Cookie", "XSRF-TOKEN=(.*);[\\s]").saveAs("xsrf_token"))
)
.exitHereIfFailed()
.pause(2)
.exec(http("Authenticated request").get("/api/account").headers(headersHttpAuthenticated).check(status().is(200)))
.pause(10)
.repeat(2)
.on(
exec(http("Get all operations").get("/api/operations").headers(headersHttpAuthenticated).check(status().is(200)))
.pause(Duration.ofSeconds(10), Duration.ofSeconds(20))
.exec(
http("Create new operation")
.post("/api/operations")
.headers(headersHttpAuthenticated)
.body(
StringBody(
"{" +
"\"date\": \"2020-01-01T00:00:00.000Z\"" +
", \"description\": \"SAMPLE_TEXT\"" +
", \"amount\": 0" +
"}"
)
)
.asJson()
.check(status().is(201))
.check(headerRegex("Location", "(.*)").saveAs("new_operation_url"))
)
.exitHereIfFailed()
.pause(10)
.repeat(5)
.on(exec(http("Get created operation").get("${new_operation_url}").headers(headersHttpAuthenticated)).pause(10))
.exec(http("Delete created operation").delete("${new_operation_url}").headers(headersHttpAuthenticated))
.pause(10)
);
ScenarioBuilder users = scenario("Test the Operation entity").exec(scn);
{
setUp(
users.injectOpen(rampUsers(Integer.getInteger("users", 100)).during(Duration.ofMinutes(Integer.getInteger("ramp", 1))))
).protocols(httpConf);
}
}