|
| 1 | +package org.javaee7.servlet.filters; |
| 2 | + |
| 3 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 4 | +import org.jboss.arquillian.container.test.api.RunAsClient; |
| 5 | +import org.jboss.arquillian.junit.Arquillian; |
| 6 | +import org.jboss.arquillian.test.api.ArquillianResource; |
| 7 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 8 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 9 | +import org.junit.Assert; |
| 10 | +import org.junit.Test; |
| 11 | +import org.junit.runner.RunWith; |
| 12 | + |
| 13 | +import javax.ws.rs.client.Client; |
| 14 | +import javax.ws.rs.client.ClientBuilder; |
| 15 | +import javax.ws.rs.client.WebTarget; |
| 16 | +import javax.ws.rs.core.Response; |
| 17 | +import java.net.MalformedURLException; |
| 18 | +import java.net.URI; |
| 19 | +import java.net.URL; |
| 20 | + |
| 21 | +import static org.hamcrest.CoreMatchers.*; |
| 22 | + |
| 23 | +@RunWith(Arquillian.class) |
| 24 | +public class FilterServletTest { |
| 25 | + |
| 26 | + @Deployment |
| 27 | + public static WebArchive createDeployment() { |
| 28 | + return ShrinkWrap.create(WebArchive.class) |
| 29 | + .addClass(CharResponseWrapper.class) |
| 30 | + .addClasses(TestServlet.class, FooBarFilter.class); |
| 31 | + } |
| 32 | + |
| 33 | + @ArquillianResource |
| 34 | + private URL base; |
| 35 | + |
| 36 | + @Test |
| 37 | + @RunAsClient |
| 38 | + public void filtered_servlet_should_return_enhanced_foobar_text() throws MalformedURLException { |
| 39 | + Client client = ClientBuilder.newClient(); |
| 40 | + WebTarget target = client.target(URI.create(new URL(base, "filtered/TestServlet").toExternalForm())); |
| 41 | + |
| 42 | + Response response = target.request().get(); |
| 43 | + Assert.assertThat(response.readEntity(String.class), is(equalTo("foo--bar--bar"))); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + @RunAsClient |
| 48 | + public void standard_servlet_should_return_simple_text() throws MalformedURLException { |
| 49 | + Client client = ClientBuilder.newClient(); |
| 50 | + WebTarget target = client.target(URI.create(new URL(base, "TestServlet").toExternalForm())); |
| 51 | + |
| 52 | + Response response = target.request().get(); |
| 53 | + Assert.assertThat(response.readEntity(String.class), is(equalTo("bar"))); |
| 54 | + } |
| 55 | +} |
0 commit comments