1
1
package org .javaee8 .servlet .http2 ;
2
2
3
3
import static org .jboss .shrinkwrap .api .ShrinkWrap .create ;
4
- import static org .junit .Assert .assertEquals ;
5
4
import static org .junit .Assert .assertNotNull ;
5
+ import static org .junit .Assert .assertThat ;
6
6
7
7
import java .io .File ;
8
- import java .net .URISyntaxException ;
8
+ import java .net .URI ;
9
9
import java .net .URL ;
10
- import java .util .concurrent .ExecutionException ;
11
- import java .util .concurrent .TimeoutException ;
12
10
13
11
import javax .ws .rs .client .Client ;
14
12
import javax .ws .rs .client .ClientBuilder ;
15
13
import javax .ws .rs .core .Response ;
16
14
17
15
import org .glassfish .jersey .client .ClientConfig ;
16
+ import org .hamcrest .Matchers ;
18
17
import org .jboss .arquillian .container .test .api .Deployment ;
19
18
import org .jboss .arquillian .container .test .api .RunAsClient ;
20
19
import org .jboss .arquillian .junit .Arquillian ;
25
24
import org .junit .Test ;
26
25
import org .junit .runner .RunWith ;
27
26
27
+
28
+ /**
29
+ * Test for the HTTP/2 and the JAX-RS client
30
+ */
28
31
@ RunWith (Arquillian .class )
29
32
public class Http2Test {
30
33
34
+ @ ArquillianResource
35
+ private URL basicUrl ;
31
36
private Client jaxrsClient ;
32
37
38
+
33
39
@ Deployment
34
40
public static WebArchive createDeployment () {
35
- return create (WebArchive .class ).addPackages (true , "org.javaee8.servlet.http2" )
41
+ final WebArchive war = create (WebArchive .class ).addPackages (true , "org.javaee8.servlet.http2" )
36
42
.addAsWebResource (new File ("src/main/webapp/images/payara-logo.jpg" ), "images/payara-logo.jpg" )
37
43
.addAsWebInfResource (new File ("src/main/webapp/WEB-INF/web.xml" ));
38
- }
39
-
40
- @ Test
41
- @ RunAsClient
42
- public void testHttp2ControlGroup ()
43
- throws InterruptedException , ExecutionException , TimeoutException , URISyntaxException {
44
- testUrl ("https://http2.akamai.com/" );
45
- }
46
-
47
- @ Test
48
- @ RunAsClient
49
- public void testServerHttp2 (@ ArquillianResource URL url )
50
- throws InterruptedException , ExecutionException , TimeoutException , URISyntaxException {
51
- Response response = testUrl (url .toURI ().toString ());
52
- assertEquals (
53
- "Request wasn't over HTTP/2."
54
- + " Either the wrong servlet was returned, or the server doesn't support HTTP/2." ,
55
- response .getHeaderString ("protocol" ), "HTTP/2" );
56
- }
57
-
58
- private Response testUrl (String url ) {
59
- Response response = jaxrsClient .target (url ).request ().get ();
60
- assertNotNull (response );
61
- return response ;
44
+ System .out .println ("War file content: \n " + war .toString (true ));
45
+ return war ;
62
46
}
63
47
64
48
@ Before
@@ -73,4 +57,37 @@ public void cleanUp() throws Exception {
73
57
jaxrsClient .close ();
74
58
}
75
59
60
+
61
+ /**
62
+ * This test runs against the public website supporting HTTP/2
63
+ *
64
+ * @throws Exception
65
+ */
66
+ @ Test (timeout = 10000L )
67
+ @ RunAsClient
68
+ public void testHttp2ControlGroup () throws Exception {
69
+ Response response = testUri (new URI ("https://http2.akamai.com/" ));
70
+ assertThat ("myproto header" , response .getHeaderString ("myproto" ), Matchers .equalTo ("h2" ));
71
+ }
72
+
73
+ /**
74
+ * This test runs against our private website supporting HTTP/2
75
+ *
76
+ * @throws Exception
77
+ */
78
+ @ Test (timeout = 10000L )
79
+ @ RunAsClient
80
+ public void testServerHttp2 () throws Exception {
81
+ Response response = testUri (basicUrl .toURI ());
82
+ // the header 'protocol' is set in the Servlet class.
83
+ assertThat (
84
+ "Request wasn't over HTTP/2. Either the wrong servlet was returned, or the server doesn't support HTTP/2." ,
85
+ response .getHeaderString ("protocol" ), Matchers .equalTo ("HTTP/2" ));
86
+ }
87
+
88
+ private Response testUri (URI uri ) {
89
+ Response response = jaxrsClient .target (uri ).request ().get ();
90
+ assertNotNull ("response" , response );
91
+ return response ;
92
+ }
76
93
}
0 commit comments