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