-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
DevMojoIT.java
1633 lines (1350 loc) · 76 KB
/
DevMojoIT.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package io.quarkus.maven.it;
import static io.quarkus.maven.it.ApplicationNameAndVersionTestUtil.assertApplicationPropertiesSetCorrectly;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.IntStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import io.quarkus.bootstrap.model.CapabilityErrors;
import io.quarkus.devui.tests.DevUIJsonRPCTest;
import io.quarkus.maven.it.continuoustesting.ContinuousTestingMavenTestUtils;
import io.quarkus.maven.it.verifier.MavenProcessInvocationResult;
import io.quarkus.maven.it.verifier.RunningInvoker;
import io.quarkus.test.devmode.util.DevModeClient;
/**
* Tests tests in the quarkus:dev mojo.
*
* @author <a href="http://escoffier.me">Clement Escoffier</a>
* <p>
* NOTE to anyone diagnosing failures in this test, to run a single method use:
* <p>
* mvn install -Dit.test=DevMojoIT#methodName
*/
@DisableForNative
public class DevMojoIT extends LaunchMojoTestBase {
protected DevModeClient devModeClient = new DevModeClient(getPort());
@Override
protected ContinuousTestingMavenTestUtils getTestingTestUtils() {
return new ContinuousTestingMavenTestUtils();
}
@Test
public void testFlattenedPomInTargetDir() throws MavenInvocationException, IOException {
testDir = initProject("projects/pom-in-target-dir");
run(true);
assertThat(devModeClient.getHttpResponse("/hello")).isEqualTo("Hello from Quarkus REST");
}
@Test
public void testConfigFactoryInAppModuleBannedInCodeGen() throws MavenInvocationException, IOException {
testDir = initProject("projects/codegen-config-factory", "projects/codegen-config-factory-banned");
run(true);
assertThat(devModeClient.getHttpResponse("/codegen-config/acme-config-factory")).isEqualTo("n/a");
assertThat(devModeClient.getHttpResponse("/codegen-config/acme-config-provider")).isEqualTo("n/a");
assertThat(devModeClient.getHttpResponse("/runtime-config/acme-config-factory"))
.isEqualTo("org.acme.AppConfigSourceFactory");
assertThat(devModeClient.getHttpResponse("/runtime-config/acme-config-provider"))
.isEqualTo("org.acme.AppConfigSourceProvider");
}
@Test
public void testConfigFactoryInAppModuleFilteredInCodeGen() throws MavenInvocationException, IOException {
testDir = initProject("projects/codegen-config-factory", "projects/codegen-config-factory-filtered");
run(true, "-Dconfig-factory.enabled");
assertThat(devModeClient.getHttpResponse("/codegen-config/acme-config-factory"))
.isEqualTo("org.acme.config.AcmeConfigSourceFactory");
assertThat(devModeClient.getHttpResponse("/codegen-config/acme-config-provider"))
.isEqualTo("org.acme.config.AcmeConfigSourceProvider");
assertThat(devModeClient.getHttpResponse("/runtime-config/acme-config-factory"))
.isEqualTo("org.acme.AppConfigSourceFactory");
assertThat(devModeClient.getHttpResponse("/runtime-config/acme-config-provider"))
.isEqualTo("org.acme.AppConfigSourceProvider");
}
@Test
public void testSystemPropertiesConfig() throws MavenInvocationException, IOException {
testDir = initProject("projects/dev-mode-sys-props-config");
run(true);
assertThat(devModeClient.getHttpResponse("/hello")).isEqualTo("hello, out there");
}
@Test
public void testEnvironmentVariablesConfig() throws MavenInvocationException, IOException {
testDir = initProject("projects/dev-mode-env-vars-config");
run(true);
assertThat(devModeClient.getHttpResponse("/hello")).isEqualTo("hello, WORLD");
}
@Test
void testClassLoaderLinkageError()
throws MavenInvocationException, IOException {
testDir = initProject("projects/classloader-linkage-error", "projects/classloader-linkage-error-dev");
run(true);
assertThat(devModeClient.getHttpResponse("/hello")).isEqualTo("hello");
}
@Test
public void testCapabilitiesConflict() throws MavenInvocationException, IOException {
testDir = getTargetDir("projects/capabilities-conflict");
final File runnerPom = new File(testDir, "runner/pom.xml");
if (!runnerPom.exists()) {
fail("Failed to locate runner/pom.xml in " + testDir);
}
run(true);
final CapabilityErrors error = new CapabilityErrors();
error.addConflict("sunshine", "org.acme:alt-quarkus-ext:1.0-SNAPSHOT");
error.addConflict("sunshine", "org.acme:acme-quarkus-ext:1.0-SNAPSHOT");
String response = devModeClient.getHttpResponse("/hello", true);
assertThat(response).contains(error.report());
filter(runnerPom, Map.of("<artifactId>acme-quarkus-ext</artifactId>", "<artifactId>alt-quarkus-ext</artifactId>"));
assertThat(devModeClient.getHttpResponse("/hello", false)).isEqualTo("hello");
filter(runnerPom, Map.of("<artifactId>alt-quarkus-ext</artifactId>", "<artifactId>acme-quarkus-ext</artifactId>"));
assertThat(devModeClient.getHttpResponse("/hello", false)).isEqualTo("hello");
}
@Test
public void testCapabilitiesMissing() throws MavenInvocationException, IOException {
testDir = getTargetDir("projects/capabilities-missing");
final File runnerPom = new File(testDir, "runner/pom.xml");
if (!runnerPom.exists()) {
fail("Failed to locate runner/pom.xml in " + testDir);
}
run(true);
final CapabilityErrors error = new CapabilityErrors();
error.addMissing("sunshine", "org.acme:acme-quarkus-ext:1.0-SNAPSHOT");
String response = devModeClient.getHttpResponse("/hello", true);
assertThat(response).contains(error.report());
final StringWriter buf = new StringWriter();
try (BufferedWriter writer = new BufferedWriter(buf)) {
writer.write(" <dependency>");
writer.newLine();
writer.write(" <groupId>org.acme</groupId>");
writer.newLine();
writer.write(" <artifactId>alt-quarkus-ext</artifactId>");
writer.newLine();
writer.write(" </dependency>");
writer.newLine();
}
final String acmeDep = buf.toString();
filter(runnerPom, Collections.singletonMap("<!-- missing -->", acmeDep));
assertThat(devModeClient.getHttpResponse("/hello", false)).isEqualTo("hello");
}
@Test
public void testPropertyOverridesTest() throws MavenInvocationException, IOException {
testDir = getTargetDir("projects/property-overrides");
runAndCheck("-Dlocal-dep.version=1.0-SNAPSHOT");
}
@Test
public void testSystemPropertyWithSpacesOnCommandLine() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-prop-with-spaces");
runAndCheck("-Dgreeting=\"1 2 3\"");
final String greeting = devModeClient.getHttpResponse("/app/hello/greeting");
assertThat(greeting).isEqualTo("1 2 3");
}
@Test
public void testCommandModeAppSystemPropArguments() throws MavenInvocationException, IOException {
testDir = initProject("projects/basic-command-mode", "projects/command-mode-app-args");
run(false, "-Dquarkus.args='1 2'");
// Wait until this file exists
final File done = new File(testDir, "done.txt");
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(20, TimeUnit.MINUTES).until(done::exists);
// read the log and check the passed in args
final File log = new File(testDir, "build-command-mode-app-args.log");
assertThat(log).exists();
String loggedArgs = extractLoggedArgs(log);
assertThat(loggedArgs).isEqualTo("ARGS: [1, 2]");
}
@Test
public void testCommandModeAppPomConfigArguments() throws MavenInvocationException, IOException {
testDir = initProject("projects/command-mode-app-args-plugin-config", "projects/command-mode-app-pom-args");
run(false);
// Wait until this file exists
final File done = new File(testDir, "done.txt");
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(20, TimeUnit.MINUTES).until(done::exists);
// read the log and check the passed in args
final File log = new File(testDir, "build-command-mode-app-pom-args.log");
assertThat(log).exists();
String loggedArgs = extractLoggedArgs(log);
assertThat(loggedArgs).isEqualTo("ARGS: [plugin, pom, config]");
}
private String extractLoggedArgs(final File log) throws IOException {
String loggedArgs = null;
try (BufferedReader reader = new BufferedReader(new FileReader(log))) {
String s;
while ((s = reader.readLine()) != null) {
// not startsWith() because line might start with ANSI escape sequence (which must be stripped)
int indexOfARGS = s.indexOf("ARGS: ");
if (indexOfARGS > -1) {
loggedArgs = s.substring(indexOfARGS);
break;
}
}
}
return loggedArgs;
}
@Test
public void testThatClassAppCanRun() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-run");
runAndCheck();
//make sure that the Class.getPackage() works for app classes
String pkg = devModeClient.getHttpResponse("/app/hello/package");
assertThat(pkg).isEqualTo("org.acme");
//make sure the proper profile is set
String profile = devModeClient.getHttpResponse("/app/hello/profile");
assertThat(profile).isEqualTo("dev");
//make sure webjars work
devModeClient.getHttpResponse("webjars/jquery-ui/1.13.0/jquery-ui.min.js");
assertThatOutputWorksCorrectly(running.log());
assertApplicationPropertiesSetCorrectly();
}
@Test
public void testThatResteasyWithoutUndertowCanRun() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic-no-undertow", "projects/project-classic-no-undertow-run");
run(false);
//make sure that a simple HTTP GET request always works
IntStream.range(0, 10).forEach(i -> {
assertThat(devModeClient.getStrictHttpResponse("/hello", 200)).isTrue();
});
}
@Test
public void testThatInitialMavenResourceFilteringWorks() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic-resource-filtering", "projects/project-classic-resource-filtering");
//also test that a zipfile must not be filtered because of nonFilteredFileExtensions configuration
//as initProject() would already corrupt the zipfile, it has to be created _after_ initProject()
try (ZipOutputStream zipOut = new ZipOutputStream(
new FileOutputStream(new File(testDir, "src/main/resources/test.zip")))) {
ZipEntry zipEntry = new ZipEntry("test.txt");
zipOut.putNextEntry(zipEntry);
zipOut.write("test".getBytes());
}
run(false);
//make sure that a simple HTTP GET request always works
IntStream.range(0, 10).forEach(i -> {
assertThat(devModeClient.getStrictHttpResponse("/hello", 200)).isTrue();
});
//try to open the copied test.zip (which will fail if it was filtered)
File copiedTestZipFile = new File(testDir, "target/classes/test.zip");
assertThat(copiedTestZipFile).exists();
try (ZipFile zipFile = new ZipFile(copiedTestZipFile)) {
//everything is fine once we get here (ZipFile is still readable)
}
}
@Test
public void testThatTheApplicationIsReloadedOnJavaChange() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-run-java-change");
runAndCheck();
// Edit the "Hello" message.
File source = new File(testDir, "src/main/java/org/acme/HelloResource.java");
String uuid = UUID.randomUUID().toString();
filter(source, Collections.singletonMap("return \"hello\";", "return \"" + uuid + "\";"));
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains(uuid));
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.until(source::isFile);
filter(source, Collections.singletonMap(uuid, "carambar"));
// Wait until we get "carambar"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains("carambar"));
}
@Test
public void testCustomOutputDirSetInProfile() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-custom-output-dir");
runAndCheck("-PcustomOutputDir");
}
@Test
public void testThatNonExistentSrcDirCanBeAdded() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-non-existent-src-dir-can-be-added");
File sourceDir = new File(testDir, "src/main/java");
File sourceDirMoved = new File(testDir, "src/main/java-moved");
if (!sourceDir.renameTo(sourceDirMoved)) {
Assertions.fail("move failed");
}
//we need this to make run and check work
File hello = new File(testDir, "src/main/resources/META-INF/resources/app/hello");
hello.getParentFile().mkdir();
try (var o = new FileOutputStream(hello)) {
o.write("hello".getBytes(StandardCharsets.UTF_8));
}
runAndCheck();
hello.delete();
if (!devModeClient.getHttpResponse("/app/hello", 404)) {
Assertions.fail("expected resource to be deleted");
}
if (!sourceDirMoved.renameTo(sourceDir)) {
Assertions.fail("move failed");
}
// Wait until we get "hello"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains("hello"));
}
@Test
public void testThatInstrumentationBasedReloadWorks() throws MavenInvocationException, IOException, Exception {
DevUIJsonRPCTest devUIJsonRPCTest = new DevUIJsonRPCTest("devui-continuous-testing", "http://localhost:8080");
testDir = initProject("projects/classic-inst", "projects/project-instrumentation-reload");
runAndCheck();
// Enable instrumentation based reload to begin with
devUIJsonRPCTest.executeJsonRPCMethod("toggleInstrumentation");
//if there is an instrumentation based reload this will stay the same
String firstUuid = devModeClient.getHttpResponse("/app/uuid");
// Edit the "Hello" message.
File source = new File(testDir, "src/main/java/org/acme/HelloResource.java");
String uuid = UUID.randomUUID().toString();
filter(source, Collections.singletonMap("return \"hello\";", "return \"" + uuid + "\";"));
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains(uuid));
//verify that this was an instrumentation based reload
Assertions.assertEquals(firstUuid, devModeClient.getHttpResponse("/app/uuid"));
source = new File(testDir, "src/main/java/org/acme/HelloService.java");
filter(source, Collections.singletonMap("\"Stuart\"", "\"Stuart Douglas\""));
// Wait until we get "Stuart Douglas"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/name").contains("Stuart Douglas"));
//this bean observes startup event, so it should be different UUID
String secondUUid = devModeClient.getHttpResponse("/app/uuid");
Assertions.assertNotEquals(secondUUid, firstUuid);
//now disable instrumentation based restart, and try again
//change it back to hello
devUIJsonRPCTest.executeJsonRPCMethod("toggleInstrumentation");
source = new File(testDir, "src/main/java/org/acme/HelloResource.java");
filter(source, Collections.singletonMap("return \"" + uuid + "\";", "return \"hello\";"));
// Wait until we get "hello"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains("hello"));
//verify that this was not instrumentation based reload
Assertions.assertNotEquals(secondUUid, devModeClient.getHttpResponse("/app/uuid"));
secondUUid = devModeClient.getHttpResponse("/app/uuid");
//now re-enable
//and repeat
devUIJsonRPCTest.executeJsonRPCMethod("toggleInstrumentation");
source = new File(testDir, "src/main/java/org/acme/HelloResource.java");
filter(source, Collections.singletonMap("return \"hello\";", "return \"" + uuid + "\";"));
// Wait until we get uuid
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains(uuid));
//verify that this was an instrumentation based reload
Assertions.assertEquals(secondUUid, devModeClient.getHttpResponse("/app/uuid"));
// verify that add + change results in full reload
// add a new class
Files.write(Paths.get(testDir.toString(), "src/main/java/org/acme/AnotherClass.java"),
"package org.acme;\nclass ItDoesntMatter{}".getBytes());
// change back to hello
source = new File(testDir, "src/main/java/org/acme/HelloResource.java");
filter(source, Collections.singletonMap("return \"" + uuid + "\";", "return \"hello\";"));
// Wait until we get "hello"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains("hello"));
//verify that this was not instrumentation based reload
Assertions.assertNotEquals(secondUUid, devModeClient.getHttpResponse("/app/uuid"));
secondUUid = devModeClient.getHttpResponse("/app/uuid");
}
@Test
public void testThatSourceChangesAreDetectedOnPomChange() throws Exception {
testDir = initProject("projects/classic", "projects/project-classic-run-src-and-pom-change");
runAndCheck(false);
// Edit a Java file too
final File javaSource = new File(testDir, "src/main/java/org/acme/HelloResource.java");
final String uuid = UUID.randomUUID().toString();
filter(javaSource, Collections.singletonMap("return \"hello\";", "return \"hello " + uuid + "\";"));
// edit the application.properties too
final File applicationProps = new File(testDir, "src/main/resources/application.properties");
filter(applicationProps, Collections.singletonMap("greeting=bonjour", "greeting=" + uuid + ""));
// Now edit the pom.xml to trigger the dev mode restart
final File pomSource = new File(testDir, "pom.xml");
filter(pomSource, Collections.singletonMap("<!-- insert test dependencies here -->",
" <dependency>\n" +
" <groupId>io.quarkus</groupId>\n" +
" <artifactId>quarkus-smallrye-openapi</artifactId>\n" +
" </dependency>"));
// Wait until we get the updated responses
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> {
System.out.println(devModeClient.getHttpResponse("/app/hello"));
return devModeClient.getHttpResponse("/app/hello").contains("hello " + uuid);
});
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello/greeting").contains(uuid));
}
@Test
public void testAlternatePom() throws Exception {
testDir = initProject("projects/classic", "projects/project-classic-alternate-pom");
File pom = new File(testDir, "pom.xml");
if (!pom.exists()) {
throw new IllegalStateException("Failed to locate project's pom.xml at " + pom);
}
final String alternatePomName = "alternate-pom.xml";
File alternatePom = new File(testDir, alternatePomName);
if (alternatePom.exists()) {
alternatePom.delete();
}
Files.copy(pom.toPath(), alternatePom.toPath());
// Now edit the pom.xml to trigger the dev mode restart
filter(alternatePom, Collections.singletonMap("<!-- insert test dependencies here -->",
" <dependency>\n" +
" <groupId>io.quarkus</groupId>\n" +
" <artifactId>quarkus-smallrye-openapi</artifactId>\n" +
" </dependency>"));
runAndCheck();
assertThat(devModeClient.getHttpResponse("/q/openapi", true)).contains("Resource Not Found");
shutdownTheApp();
runAndCheck("-f", alternatePomName);
devModeClient.getHttpResponse("/q/openapi").contains("hello");
}
@Test
public void testThatTheApplicationIsReloadedOnPomChange() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-run-pom-change");
runAndCheck();
// Edit the pom.xml.
File source = new File(testDir, "pom.xml");
filter(source, Collections.singletonMap("<!-- insert test dependencies here -->",
" <dependency>\n" +
" <groupId>io.quarkus</groupId>\n" +
" <artifactId>quarkus-smallrye-openapi</artifactId>\n" +
" </dependency>"));
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/q/openapi").contains("hello"));
}
@Test
public void testProjectWithExtension() throws MavenInvocationException, IOException {
testDir = getTargetDir("projects/project-with-extension");
runAndCheck();
final List<String> artifacts = getNonReloadableArtifacts(
Files.readAllLines(testDir.toPath().resolve("build-project-with-extension.log")));
assertTrue(artifacts.contains("- org.acme:acme-quarkus-ext:1.0-SNAPSHOT"));
assertTrue(artifacts.contains("- org.acme:acme-quarkus-ext-deployment:1.0-SNAPSHOT"));
assertTrue(artifacts.contains("- org.acme:acme-common:1.0-SNAPSHOT"));
assertTrue(artifacts.contains("- org.acme:acme-common-transitive:1.0-SNAPSHOT"));
assertEquals(4, artifacts.size());
}
protected List<String> getNonReloadableArtifacts(final List<String> log) {
final List<String> artifacts = new ArrayList<>();
boolean inWarn = false;
for (String line : log) {
if (inWarn) {
if (line.equals(
"The artifacts above appear to be either dependencies of non-reloadable application dependencies or Quarkus extensions")) {
break;
}
artifacts.add(line);
} else if (line.equals(
"[WARNING] [io.quarkus.bootstrap.devmode.DependenciesFilter] Live reload was disabled for the following project artifacts:")) {
inWarn = true;
}
}
return artifacts;
}
@Test
public void testRestClientCustomHeadersExtension() throws MavenInvocationException, IOException {
testDir = getTargetDir("projects/rest-client-custom-headers-extension");
runAndCheck();
final List<String> artifacts = getNonReloadableArtifacts(
Files.readAllLines(testDir.toPath().resolve("build-rest-client-custom-headers-extension.log")));
assertTrue(artifacts.contains("- org.acme:rest-client-custom-headers:1.0-SNAPSHOT"));
assertTrue(artifacts.contains("- org.acme:rest-client-custom-headers-deployment:1.0-SNAPSHOT"));
assertEquals(2, artifacts.size());
assertThat(devModeClient.getHttpResponse("/app/frontend")).isEqualTo("CustomValue1 CustomValue2");
}
@Test
public void testThatJUnitTestTemplatesWork() throws MavenInvocationException, IOException {
//we also check continuous testing
testDir = initProject("projects/test-template", "projects/test-template-processed");
runAndCheck();
ContinuousTestingMavenTestUtils testingTestUtils = new ContinuousTestingMavenTestUtils();
ContinuousTestingMavenTestUtils.TestStatus results = testingTestUtils.waitForNextCompletion();
//check that the tests in both modules run
Assertions.assertEquals(2, results.getTestsPassed());
// Re-running the tests when changes happen is covered by testThatChangesTriggerRerunsOfJUnitTestTemplates
}
@Disabled("Not working; tracked by #40770")
@Test
public void testThatChangesTriggerRerunsOfJUnitTestTemplates() throws MavenInvocationException, IOException {
//we also check continuous testing
testDir = initProject("projects/test-template", "projects/test-template-processed");
runAndCheck();
ContinuousTestingMavenTestUtils testingTestUtils = new ContinuousTestingMavenTestUtils();
ContinuousTestingMavenTestUtils.TestStatus results = testingTestUtils.waitForNextCompletion();
//check that the tests in both modules run
Assertions.assertEquals(2, results.getTestsPassed());
// Edit the "Hello" message.
File source = new File(testDir, "src/main/java/org/acme/HelloResource.java");
final String uuid = UUID.randomUUID().toString();
filter(source, Collections.singletonMap("return \"hello\";", "return \"" + uuid + "\";"));
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains(uuid));
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.until(source::isFile);
results = testingTestUtils.waitForNextCompletion();
//make sure the test is failing now
Assertions.assertEquals(0, results.getTestsPassed());
Assertions.assertEquals(2, results.getTestsFailed());
}
@Test
public void testThatTheApplicationIsReloadedMultiModule() throws MavenInvocationException, IOException {
//we also check continuous testing
testDir = initProject("projects/multimodule", "projects/multimodule-with-deps");
runAndCheck();
// test that we don't get multiple instances of a resource when loading from the ClassLoader
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(5, TimeUnit.SECONDS)
.until(() -> devModeClient.getHttpResponse("/app/hello/resourcesCount").equals("1"));
ContinuousTestingMavenTestUtils testingTestUtils = new ContinuousTestingMavenTestUtils();
ContinuousTestingMavenTestUtils.TestStatus results = testingTestUtils.waitForNextCompletion();
//check that the tests in both modules run
Assertions.assertEquals(2, results.getTestsPassed());
// Edit the "Hello" message.
File source = new File(testDir, "rest/src/main/java/org/acme/HelloResource.java");
final String uuid = UUID.randomUUID().toString();
filter(source, Collections.singletonMap("return \"hello\";", "return \"" + uuid + "\";"));
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains(uuid));
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.until(source::isFile);
results = testingTestUtils.waitForNextCompletion();
//make sure the test is failing now
Assertions.assertEquals(1, results.getTestsFailed());
//now modify the passing test
var testSource = new File(testDir, "rest/src/test/java/org/acme/test/SimpleTest.java");
filter(testSource, Collections.singletonMap("Assertions.assertTrue(true);", "Assertions.assertTrue(false);"));
results = testingTestUtils.waitForNextCompletion();
Assertions.assertEquals(2, results.getTotalTestsFailed());
//fix it again
filter(testSource, Collections.singletonMap("Assertions.assertTrue(false);", "Assertions.assertTrue(true);"));
results = testingTestUtils.waitForNextCompletion();
Assertions.assertEquals(1, results.getTotalTestsFailed(), "Failed, actual results " + results);
Assertions.assertEquals(1, results.getTotalTestsPassed(), "Failed, actual results " + results);
filter(source, Collections.singletonMap(uuid, "carambar"));
// Wait until we get "carambar"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains("carambar"));
// Create a new resource
source = new File(testDir, "html/src/main/resources/META-INF/resources/lorem.txt");
FileUtils.write(source,
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"UTF-8");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/lorem.txt").contains("Lorem ipsum"));
// Update the resource
FileUtils.write(source, uuid, "UTF-8");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/lorem.txt").contains(uuid));
// Delete the resource
source.delete();
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/lorem.txt", 404));
}
@Test
public void testMultiModuleDevModeWithLocalDepsDisabled() throws MavenInvocationException, IOException {
testDir = initProject("projects/multimodule", "projects/multimodule-nodeps");
runAndCheck("-DnoDeps");
String greeting = devModeClient.getHttpResponse("/app/hello/greeting");
assertThat(greeting).containsIgnoringCase("bonjour");
// Edit the "Hello" message.
File source = new File(testDir, "rest/src/main/java/org/acme/HelloResource.java");
filter(source, Collections.singletonMap("return \"hello\";", "return \"" + UUID.randomUUID().toString() + "\";"));
// Edit the greeting property.
source = new File(testDir, "runner/src/main/resources/application.properties");
final String uuid = UUID.randomUUID().toString();
filter(source, Collections.singletonMap("greeting=bonjour", "greeting=" + uuid + ""));
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello/greeting").contains(uuid));
greeting = devModeClient.getHttpResponse("/app/hello");
assertThat(greeting).containsIgnoringCase("hello");
}
@Test
public void testMultiModuleProjectWithRevisionVersion() throws MavenInvocationException, IOException {
testDir = initProject("projects/multimodule-revision-prop");
final String projectVersion = System.getProperty("project.version");
runAndCheck("-Dquarkus.platform.version=" + projectVersion,
"-Dquarkus-plugin.version=" + projectVersion);
// Edit the "Hello" message.
File source = new File(testDir, "rest/src/main/java/org/acme/HelloResource.java");
final String uuid = UUID.randomUUID().toString();
filter(source, Collections.singletonMap("return \"hello\";", "return \"" + uuid + "\";"));
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello").contains(uuid));
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.until(source::isFile);
}
@Test
public void testTestScopedLocalProjectDependency() throws MavenInvocationException, IOException {
testDir = initProject("projects/test-module-dependency");
final String projectVersion = System.getProperty("project.version");
run(true, "-Dquarkus.platform.version=" + projectVersion,
"-Dquarkus-plugin.version=" + projectVersion);
assertEquals("Test class is not visible", devModeClient.getHttpResponse("/hello"));
}
@Test
public void testThatTheApplicationIsReloadedOnNewResource() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-run-new-resource");
runAndCheck();
File source = new File(testDir, "src/main/java/org/acme/MyNewResource.java");
String myNewResource = "package org.acme;\n" +
"\n" +
"import jakarta.ws.rs.GET;\n" +
"import jakarta.ws.rs.Path;\n" +
"import jakarta.ws.rs.Produces;\n" +
"import jakarta.ws.rs.core.MediaType;\n" +
"\n" +
"@Path(\"/foo\")\n" +
"public class MyNewResource {\n" +
" @GET\n" +
" @Produces(MediaType.TEXT_PLAIN)\n" +
" public String foo() {\n" +
" return \"bar\";\n" +
" }\n" +
"}\n";
FileUtils.write(source, myNewResource, StandardCharsets.UTF_8);
// Wait until we get "bar"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/foo").contains("bar"));
}
@Test
public void testThatClassFileAreCleanedUp() throws MavenInvocationException, IOException, InterruptedException {
testDir = initProject("projects/classic", "projects/project-class-file-deletion");
File source = new File(testDir, "src/main/java/org/acme/ClassDeletionResource.java");
String classDeletionResource = "package org.acme;\n" +
"\n" +
"import jakarta.ws.rs.GET;\n" +
"import jakarta.ws.rs.Path;\n" +
"import jakarta.ws.rs.Produces;\n" +
"import jakarta.ws.rs.core.MediaType;\n" +
"\n" +
"@Path(\"/deletion\")\n" +
"public class ClassDeletionResource {\n" +
" public static class InnerClass {} \n" +
" @GET\n" +
" @Produces(MediaType.TEXT_PLAIN)\n" +
" public String toDelete() {\n" +
" return Hello.message();\n" +
" }\n" +
"}\n " +
"class Hello {\n" +
" public static String message() {\n" +
" return \"to be deleted\";\n" +
" }\n" +
"}";
FileUtils.write(source, classDeletionResource, StandardCharsets.UTF_8);
runAndCheck();
// Wait until source file is compiled
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/deletion").contains("to be deleted"));
// Remove InnerClass
filter(source, Collections.singletonMap("public static class InnerClass {}", ""));
File helloClassFile = new File(testDir, "target/classes/org/acme/Hello.class");
File innerClassFile = new File(testDir, "target/classes/org/acme/ClassDeletionResource$InnerClass.class");
File classDeletionResourceClassFile = new File(testDir, "target/classes/org/acme/ClassDeletionResource.class");
// Make sure that other class files have not been deleted.
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello/package", 200));
// Verify that only ClassDeletionResource$InnerClass.class to be deleted
assertThat(innerClassFile).doesNotExist();
assertThat(helloClassFile).exists();
assertThat(classDeletionResourceClassFile).exists();
// Delete source file
source.delete();
// Wait until we get "404 Not Found" because ClassDeletionResource.class have been deleted.
await()
.pollDelay(1, TimeUnit.SECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/deletion", 404));
// Make sure that class files for the deleted source file have also been deleted
assertThat(helloClassFile).doesNotExist();
assertThat(classDeletionResourceClassFile).doesNotExist();
}
@Test
public void testSourceModificationBeforeFirstCallWorks() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-source-modification-before-first-call");
run(true);
File source = new File(testDir, "src/main/java/org/acme/HelloResource.java");
// Edit the "Hello" message and provide a random string.
String uuid = UUID.randomUUID().toString();
filter(source, Collections.singletonMap("return \"hello\";", "return \"" + uuid + "\";"));
// Check that the random string is returned
String greeting = devModeClient.getHttpResponse("/app/hello");
assertThat(greeting).containsIgnoringCase(uuid);
}
@Test
public void testThatTheApplicationIsReloadedOnConfigChange() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-run-config-change");
assertThat(testDir).isDirectory();
running = new RunningInvoker(testDir, false);
final Properties mvnRunProps = new Properties();
mvnRunProps.setProperty("debug", "false");
running.execute(Arrays.asList("compile", "quarkus:dev", "-Dquarkus.analytics.disabled=true"), Collections.emptyMap(),
mvnRunProps);
String resp = devModeClient.getHttpResponse();
assertThat(resp).containsIgnoringCase("ready").containsIgnoringCase("application").containsIgnoringCase("org.acme")
.containsIgnoringCase("1.0-SNAPSHOT");
String greeting = devModeClient.getHttpResponse("/app/hello/greeting");
assertThat(greeting).containsIgnoringCase("bonjour");
File source = new File(testDir, "src/main/resources/application.properties");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.until(source::isFile);
String uuid = UUID.randomUUID().toString();
filter(source, Collections.singletonMap("bonjour", uuid));
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(TestUtils.getDefaultTimeout(), TimeUnit.MINUTES)
.until(() -> devModeClient.getHttpResponse("/app/hello/greeting").contains(uuid));
}
@Test
public void testThatAddingConfigFileWorksCorrectly() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic-noconfig", "projects/project-classic-run-noconfig-add-config");
assertThat(testDir).isDirectory();
running = new RunningInvoker(testDir, false);
final Properties mvnRunProps = new Properties();
mvnRunProps.setProperty("debug", "false");
running.execute(Arrays.asList("compile", "quarkus:dev", "-Dquarkus.analytics.disabled=true"), Collections.emptyMap(),
mvnRunProps);
String resp = devModeClient.getHttpResponse();
assertThat(resp).containsIgnoringCase("ready").containsIgnoringCase("application").containsIgnoringCase("org.acme")
.containsIgnoringCase("1.0-SNAPSHOT");
String greeting = devModeClient.getHttpResponse("/app/hello/greeting");
assertThat(greeting).contains("initialValue");
File configurationFile = new File(testDir, "src/main/resources/application.properties");
assertThat(configurationFile).doesNotExist();
String uuid = UUID.randomUUID().toString();
FileUtils.write(configurationFile,
"greeting=" + uuid,
"UTF-8");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.until(configurationFile::isFile);
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(10, TimeUnit.SECONDS)
.until(() -> devModeClient.getHttpResponse("/app/hello/greeting").contains(uuid));
}
@Test
public void testThatExternalConfigOverridesConfigInJar() throws MavenInvocationException, IOException {
testDir = initProject("projects/classic", "projects/project-classic-external-config");
File configurationFile = new File(testDir, "config/application.properties");
assertThat(configurationFile).doesNotExist();
String uuid = UUID.randomUUID().toString();
FileUtils.write(configurationFile,
"greeting=" + uuid,
"UTF-8");
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.until(configurationFile::isFile);
run(true);
// Wait until we get "uuid"
await()
.pollDelay(100, TimeUnit.MILLISECONDS)
.atMost(60, TimeUnit.SECONDS)
.until(() -> devModeClient.getHttpResponse("/app/hello/greeting").contains(uuid));
}
@Test
public void testThatConfigFileDeletionsAreDetected() throws MavenInvocationException, IOException {
testDir = initProject("projects/dev-mode-file-deletion");
runAndCheck();