11package org .javaee8 .servlet .http2 ;
22
33import static org .jboss .shrinkwrap .api .ShrinkWrap .create ;
4- import static org .junit .Assert .assertNotNull ;
5- import static org .junit .Assert .assertThat ;
4+ import static org .junit .Assert .assertEquals ;
65
76import java .io .File ;
87import java .net .URI ;
98import java .net .URL ;
9+ import java .util .concurrent .ExecutionException ;
10+ import java .util .concurrent .TimeoutException ;
1011
11- import javax .ws .rs .client .Client ;
12- import javax .ws .rs .client .ClientBuilder ;
13- import javax .ws .rs .core .Response ;
14-
15- import org .glassfish .jersey .client .ClientConfig ;
16- import org .hamcrest .Matchers ;
12+ import org .eclipse .jetty .client .HttpClient ;
13+ import org .eclipse .jetty .http .HttpVersion ;
1714import org .jboss .arquillian .container .test .api .Deployment ;
18- import org .jboss .arquillian .container .test .api .RunAsClient ;
1915import org .jboss .arquillian .junit .Arquillian ;
2016import org .jboss .arquillian .test .api .ArquillianResource ;
2117import org .jboss .shrinkwrap .api .spec .WebArchive ;
2420import org .junit .Test ;
2521import org .junit .runner .RunWith ;
2622
27-
2823/**
2924 * Test for the HTTP/2 and the JAX-RS client
3025 */
@@ -33,10 +28,9 @@ public class Http2Test {
3328
3429 @ ArquillianResource
3530 private URL basicUrl ;
36- private Client jaxrsClient ;
31+ private HttpClient client ;
3732
38-
39- @ Deployment
33+ @ Deployment (testable = false )
4034 public static WebArchive createDeployment () {
4135 final WebArchive war = create (WebArchive .class ).addClasses (Servlet .class )
4236 .addAsWebResource (new File ("src/main/webapp/images/payara-logo.jpg" ), "images/payara-logo.jpg" )
@@ -48,27 +42,23 @@ public static WebArchive createDeployment() {
4842
4943 @ Before
5044 public void setup () throws Exception {
51- ClientConfig config = new ClientConfig ();
52- config .connectorProvider (JettyConnector ::new );
53- jaxrsClient = ClientBuilder .newClient (config );
45+ client = new HttpClient ();
46+ client .start ();
5447 }
5548
5649 @ After
5750 public void cleanUp () throws Exception {
58- jaxrsClient . close ();
51+ client . stop ();
5952 }
6053
61-
6254 /**
6355 * This test runs against the public website supporting HTTP/2
6456 *
6557 * @throws Exception
6658 */
6759 @ Test (timeout = 10000L )
68- @ RunAsClient
6960 public void testHttp2ControlGroup () throws Exception {
70- Response response = testUri (new URI ("https://http2.akamai.com/" ));
71- assertThat ("myproto header" , response .getHeaderString ("myproto" ), Matchers .equalTo ("h2" ));
61+ testHttp2 (new URI ("https://http2.akamai.com/" ));
7262 }
7363
7464 /**
@@ -77,18 +67,11 @@ public void testHttp2ControlGroup() throws Exception {
7767 * @throws Exception
7868 */
7969 @ Test (timeout = 10000L )
80- @ RunAsClient
8170 public void testServerHttp2 () throws Exception {
82- Response response = testUri (basicUrl .toURI ());
83- // the header 'protocol' is set in the Servlet class.
84- assertThat (
85- "Request wasn't over HTTP/2. Either the wrong servlet was returned, or the server doesn't support HTTP/2." ,
86- response .getHeaderString ("protocol" ), Matchers .equalTo ("HTTP/2" ));
71+ testHttp2 (basicUrl .toURI ());
8772 }
8873
89- private Response testUri (URI uri ) {
90- Response response = jaxrsClient .target (uri ).request ().get ();
91- assertNotNull ("response" , response );
92- return response ;
74+ private void testHttp2 (URI uri ) throws InterruptedException , ExecutionException , TimeoutException {
75+ assertEquals ("Request wasn't over HTTP/2" , HttpVersion .HTTP_2 , client .GET (uri ).getVersion ());
9376 }
9477}
0 commit comments