forked from gemiusz/gatling-examples-maven-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCase0010JsonEditVariableSimulation.java
66 lines (59 loc) · 3.15 KB
/
Case0010JsonEditVariableSimulation.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
package pl.gemiusz;
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Session;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;
import java.util.Map;
import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;
public class Case0010JsonEditVariableSimulation extends Simulation {
HttpProtocolBuilder httpProtocol =
http
.baseUrl("https://postman-echo.com");
ScenarioBuilder scn =
scenario("GeMi_JsonEditVariableSimulation")
.exec(
http("GeMi_JsonEditVariableSimulation_post")
.post("/post")
.body(StringBody("{\"status\":\"GOOD\",\"fruit\":\"Apple\"}"))
.asJson()
.check(
jmesPath("json")
.ofObject()
.is(
Map.of("status", "GOOD",
"fruit", "Apple"
)
)
.saveAs("GeMi_Obj")
)
).exec(session -> {
System.out.println("GeMi_Obj: " + session.get("GeMi_Obj").toString());
Map<String, Object> gemiObj = session.get("GeMi_Obj");
//changing value from GOOD to BAD
gemiObj.put("status", "BAD");
Session sessionGeMiObj = session.set("changed_GeMi_Obj", gemiObj);
return sessionGeMiObj;
}).exec(
http("GeMi_JsonEditVariableSimulation_post_changed")
.post("/post")
.body(StringBody("#{changed_GeMi_Obj.jsonStringify()}"))
.asJson()
.check(
jmesPath("json")
.ofObject()
.is(
Map.of("status", "BAD",
"fruit", "Apple"
)
)
.saveAs("GeMi_Obj_aftter_change")
)
).exec(session -> {
System.out.println("GeMi_Obj_aftter_change: " + session.get("GeMi_Obj_aftter_change").toString());
return session;
});
{
setUp(scn.injectOpen(atOnceUsers(1)).protocols(httpProtocol));
}
}