forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HotReloadTest.java
122 lines (103 loc) · 4.68 KB
/
HotReloadTest.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package io.quarkus.smallrye.graphql.deployment;
import static io.quarkus.smallrye.graphql.deployment.AbstractGraphQLTest.MEDIATYPE_JSON;
import org.hamcrest.CoreMatchers;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;
/**
* Test Hot reload after a code change
*/
public class HotReloadTest extends AbstractGraphQLTest {
private static final Logger LOG = Logger.getLogger(HotReloadTest.class);
@RegisterExtension
final static QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestResource.class, TestPojo.class, TestRandom.class, TestGenericsPojo.class,
TestUnion.class, TestUnionMember.class, CustomDirective.class, BusinessException.class)
.addAsResource(new StringAsset(getPropertyAsString()), "application.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));
@Test
public void testAddAndRemoveFieldChange() {
String fooRequest = getPayload("{\n" +
" foo {\n" +
" message\n" +
" randomNumber{\n" +
" value\n" +
" }\n" +
" foo\n" +
" list\n" +
" }\n" +
"}");
// Do a request
RestAssured.given().when()
.accept(MEDIATYPE_JSON)
.contentType(MEDIATYPE_JSON)
.body(fooRequest)
.post("/graphql")
.then()
.assertThat()
.statusCode(200)
.and()
.body(CoreMatchers.containsString(
"{\"errors\":[{\"message\":\"Validation error (FieldUndefined@[foo/foo]) : Field 'foo' in type 'TestPojo' is undefined\",\"locations\":[{\"line\":7,\"column\":5}],\"extensions\":{\"classification\":\"ValidationError\"}}],\"data\":null}"));
LOG.info("Initial request done");
// Make a code change (add a field)
TEST.modifySourceFile("TestPojo.java", s -> s.replace("// <placeholder>",
"private String foo = \"bar\";\n" +
" public String getFoo(){\n" +
" return foo;\n" +
" }"));
LOG.info("Code change done - field added");
// Do the request again
RestAssured.given().when()
.accept(MEDIATYPE_JSON)
.contentType(MEDIATYPE_JSON)
.body(fooRequest)
.post("/graphql")
.then()
.assertThat()
.statusCode(200)
.and()
.body(CoreMatchers.containsString(
"{\"data\":{\"foo\":{\"message\":\"bar\",\"randomNumber\":{\"value\":123.0},\"foo\":\"bar\",\"list\":[\"a\",\"b\",\"c\"]}}}"));
LOG.info("Hot reload done");
// Make a code change again (remove)
TEST.modifySourceFile("TestPojo.java", s -> s.replace("private String foo = \"bar\";\n" +
" public String getFoo(){\n" +
" return foo;\n" +
" }", "// <placeholder>"));
// Do the request yet again
RestAssured.given().when()
.accept(MEDIATYPE_JSON)
.contentType(MEDIATYPE_JSON)
.body(fooRequest)
.post("/graphql")
.then()
.assertThat()
.statusCode(200)
.and()
.body(CoreMatchers.containsString(
"{\"errors\":[{\"message\":\"Validation error (FieldUndefined@[foo/foo]) : Field 'foo' in type 'TestPojo' is undefined\",\"locations\":[{\"line\":7,\"column\":5}],\"extensions\":{\"classification\":\"ValidationError\"}}],\"data\":null}"));
LOG.info("Code change done - field removed");
}
@Test
public void testCodeChange() {
// Do a request
pingTest();
LOG.info("Initial ping done");
// Make a code change
TEST.modifySourceFile("TestResource.java", s -> s.replace("// <placeholder>",
" @Query(\"pong\")\n" +
" public TestPojo pong() {\n" +
" return new TestPojo(\"ping\");\n" +
" }"));
LOG.info("Code change done");
// Do a request again
pongTest();
LOG.info("Pong done");
}
}