Skip to content

Commit 2bd3c87

Browse files
committed
Issue #20 More stable Http2Test, cleanup
- added safety timeouts - test hangs sometimes. - added assert for header even in the public variant - shows the content of the war file in logs - removed unuseful exception declarations
1 parent ad609b5 commit 2bd3c87

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package org.javaee8.servlet.http2;
22

33
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
4-
import static org.junit.Assert.assertEquals;
54
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertThat;
66

77
import java.io.File;
8-
import java.net.URISyntaxException;
8+
import java.net.URI;
99
import java.net.URL;
10-
import java.util.concurrent.ExecutionException;
11-
import java.util.concurrent.TimeoutException;
1210

1311
import javax.ws.rs.client.Client;
1412
import javax.ws.rs.client.ClientBuilder;
1513
import javax.ws.rs.core.Response;
1614

1715
import org.glassfish.jersey.client.ClientConfig;
16+
import org.hamcrest.Matchers;
1817
import org.jboss.arquillian.container.test.api.Deployment;
1918
import org.jboss.arquillian.container.test.api.RunAsClient;
2019
import org.jboss.arquillian.junit.Arquillian;
@@ -25,40 +24,25 @@
2524
import org.junit.Test;
2625
import org.junit.runner.RunWith;
2726

27+
28+
/**
29+
* Test for the HTTP/2 and the JAX-RS client
30+
*/
2831
@RunWith(Arquillian.class)
2932
public class Http2Test {
3033

34+
@ArquillianResource
35+
private URL basicUrl;
3136
private Client jaxrsClient;
3237

38+
3339
@Deployment
3440
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")
3642
.addAsWebResource(new File("src/main/webapp/images/payara-logo.jpg"), "images/payara-logo.jpg")
3743
.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;
6246
}
6347

6448
@Before
@@ -73,4 +57,37 @@ public void cleanUp() throws Exception {
7357
jaxrsClient.close();
7458
}
7559

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+
}
7693
}

0 commit comments

Comments
 (0)