@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addClass(CharResponseWrapper.class)
.addClasses(TestServlet.class, FooBarFilter.class);
}
cd javaee7-samples/servlet/servlet-filters/Now we are ready to start testing. You can run all the tests in this sample by executing:
mvn test
Or you can run individual tests by executing one of the following:mvn test -Dtest=FilterServletTest
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addClass(CharResponseWrapper.class)
.addClasses(TestServlet.class, FooBarFilter.class);
}
@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")));
}
There's a lot more about JavaEE to cover. If you're ready to learn more, check out the other available samples.
git clone git://github.com/javaee-samples/javaee7-samples.git
cd javaee7-samples/servlet/servlet-filters/
Do the changes as you see fit and send a pull request!
Good Luck!