-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
OperationGatlingTest.java
96 lines (85 loc) · 4.16 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
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.header;
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.8.0/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> headersHttpAuthentication = Map.of("Content-Type", "application/json", "Accept", "application/json");
Map<String, String> headersHttpAuthenticated = Map.of("Accept", "application/json", "Authorization", "${access_token}");
ChainBuilder scn = exec(http("First unauthenticated request").get("/api/account").headers(headersHttp).check(status().is(401)))
.exitHereIfFailed()
.pause(10)
.exec(
http("Authentication")
.post("/api/authenticate")
.headers(headersHttpAuthentication)
.body(StringBody("{\"username\":\"admin\", \"password\":\"admin\"}"))
.asJson()
.check(header("Authorization").saveAs("access_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);
}
}