1
1
package com .example .payara .hello .test ;
2
2
3
3
import com .example .payara .hello .test .client .HelloApplicationClient ;
4
+ import jakarta .ws .rs .core .Response ;
5
+ import org .junit .jupiter .api .AfterAll ;
4
6
import org .junit .jupiter .api .BeforeEach ;
5
7
import org .junit .jupiter .api .Test ;
6
8
12
14
import java .util .logging .Logger ;
13
15
import java .util .stream .Collectors ;
14
16
17
+ import static java .lang .Thread .sleep ;
15
18
import static org .junit .jupiter .api .Assertions .assertEquals ;
16
19
17
20
class DeploymentIT {
@@ -22,21 +25,56 @@ class DeploymentIT {
22
25
Properties properties = loadProperties ();
23
26
String payaraHost = (String ) properties .get ("payara.host" );
24
27
int payaraPort = Integer .parseInt ((String ) properties .get ("payara.port" ));
28
+ int teardownDelay = Integer .parseInt ((String ) properties .get ("payara.teardownDelay" ));
29
+ static int staticTeardownDelay ;
25
30
26
31
private HelloApplicationClient client ;
27
32
28
33
@ BeforeEach
29
34
public void before () {
30
35
31
36
client = new HelloApplicationClient ("http://" +payaraHost +":" +payaraPort );
37
+ staticTeardownDelay = teardownDelay ;
38
+
39
+ }
40
+
41
+ @ AfterAll
42
+ public static void afterAll () throws InterruptedException {
43
+
44
+ // wait before teardown
45
+ sleep (staticTeardownDelay );
32
46
33
47
}
34
48
35
49
@ Test
36
50
void testHello (){
37
51
client .waitForServiceToBeHealthy ();
38
- assertEquals ("Hello, World!" , client .helloWorld ());
39
- assertEquals ("" , parseCommandOutput ("docker logs test-classes-payara-deployment-test-1" , "SEVERE" ));
52
+ assertEquals ("Hello, World!" , client .helloWorld (), "Hello world endpoint response message must match." );
53
+ assertEquals ("" , parseCommandOutput ("docker logs test-classes-payara-deployment-test-1" , "SEVERE" ),
54
+ "There should be no SEVERE log traces in the server logs after a hello world endpoint call." );
55
+ logger .info (parseCommandOutput ("docker logs test-classes-payara-deployment-test-1" , "successfully deployed in" ));
56
+ }
57
+
58
+ @ Test
59
+ void testHelloBadRequestValidationException (){
60
+ client .waitForServiceToBeHealthy ();
61
+ assertEquals (Response .Status .BAD_REQUEST .getStatusCode (), client .helloThrowNotWrappedStatus (), "ValidationException" +
62
+ "should be mapped to a bad request response with a 400 HTTP error status response code." );
63
+ assertEquals ("" , parseCommandOutput ("docker logs test-classes-payara-deployment-test-1" , "SEVERE" ),
64
+ "There should be no SEVERE log traces in the server logs after a ValidationException is mapped to an" +
65
+ " error response." );
66
+ logger .info (parseCommandOutput ("docker logs test-classes-payara-deployment-test-1" , "successfully deployed in" ));
67
+ }
68
+
69
+ @ Test
70
+ void testHelloBadRequestEJBExceptionWrappedValidationException (){
71
+ client .waitForServiceToBeHealthy ();
72
+ assertEquals (Response .Status .BAD_REQUEST .getStatusCode (), client .helloThrowWrappedStatus (), "EJBException " +
73
+ "wrapped ValidationException should be mapped to a bad request response with a 400 HTTP status " +
74
+ "error response code." );
75
+ assertEquals ("" , parseCommandOutput ("docker logs test-classes-payara-deployment-test-1" , "SEVERE" ),
76
+ "There should be no SEVERE log traces in the server logs after an " +
77
+ "EJBException-wrapped ValidationException is mapped to an error response." );
40
78
logger .info (parseCommandOutput ("docker logs test-classes-payara-deployment-test-1" , "successfully deployed in" ));
41
79
}
42
80
0 commit comments