11package com .baeldung .annotation .servletcomponentscan ;
22
3- import com .baeldung .annotation .servletcomponentscan .javaee .AttrListener ;
4- import com .baeldung .annotation .servletcomponentscan .javaee .EchoServlet ;
5- import com .baeldung .annotation .servletcomponentscan .javaee .HelloFilter ;
6- import com .baeldung .annotation .servletcomponentscan .javaee .HelloServlet ;
7- import org .jboss .arquillian .container .test .api .Deployment ;
8- import org .jboss .arquillian .container .test .api .RunAsClient ;
9- import org .jboss .arquillian .junit .Arquillian ;
10- import org .jboss .arquillian .test .api .ArquillianResource ;
11- import org .jboss .shrinkwrap .api .ShrinkWrap ;
12- import org .jboss .shrinkwrap .api .spec .WebArchive ;
13- import org .junit .Test ;
14- import org .junit .runner .RunWith ;
3+ import static org .junit .Assert .assertEquals ;
4+ import static org .junit .Assert .assertNotNull ;
5+ import static org .junit .Assert .assertTrue ;
6+
7+ import java .net .MalformedURLException ;
8+ import java .net .URI ;
9+ import java .net .URL ;
1510
1611import javax .inject .Inject ;
1712import javax .servlet .FilterRegistration ;
2217import javax .ws .rs .client .WebTarget ;
2318import javax .ws .rs .core .MediaType ;
2419import javax .ws .rs .core .Response ;
25- import java .net .MalformedURLException ;
26- import java .net .URI ;
27- import java .net .URL ;
2820
29- import static org .junit .Assert .*;
21+ import org .jboss .arquillian .container .test .api .Deployment ;
22+ import org .jboss .arquillian .container .test .api .RunAsClient ;
23+ import org .jboss .arquillian .junit .Arquillian ;
24+ import org .jboss .arquillian .test .api .ArquillianResource ;
25+ import org .jboss .shrinkwrap .api .ShrinkWrap ;
26+ import org .jboss .shrinkwrap .api .spec .WebArchive ;
27+ import org .junit .Test ;
28+ import org .junit .runner .RunWith ;
29+
30+ import com .baeldung .annotation .servletcomponentscan .javaee .AttrListener ;
31+ import com .baeldung .annotation .servletcomponentscan .javaee .EchoServlet ;
32+ import com .baeldung .annotation .servletcomponentscan .javaee .HelloFilter ;
33+ import com .baeldung .annotation .servletcomponentscan .javaee .HelloServlet ;
3034
3135@ RunWith (Arquillian .class )
32- public class JavaEEAppTest {
36+ public class JavaEEAppIntegrationTest {
3337
3438 @ Deployment
3539 public static WebArchive createDeployment () {
36- return ShrinkWrap
37- .create (WebArchive .class )
38- .addClass (JavaEEApp .class )
39- .addClasses (AttrListener .class , HelloFilter .class , HelloServlet .class , EchoServlet .class );
40+ return ShrinkWrap .create (WebArchive .class ).addClass (JavaEEApp .class ).addClasses (AttrListener .class , HelloFilter .class , HelloServlet .class , EchoServlet .class );
4041 }
4142
42- @ Inject private ServletContext servletContext ;
43+ @ Inject
44+ private ServletContext servletContext ;
4345
4446 @ Test
4547 public void givenServletContextListener_whenAccessSpecialAttrs_thenFound () throws MalformedURLException {
@@ -54,21 +56,18 @@ public void givenServletContext_whenCheckHelloFilterMappings_thenCorrect() throw
5456 FilterRegistration filterRegistration = servletContext .getFilterRegistration ("hello filter" );
5557
5658 assertNotNull (filterRegistration );
57- assertTrue (filterRegistration
58- .getServletNameMappings ()
59- .contains ("echo servlet" ));
59+ assertTrue (filterRegistration .getServletNameMappings ().contains ("echo servlet" ));
6060 }
6161
62- @ ArquillianResource private URL base ;
62+ @ ArquillianResource
63+ private URL base ;
6364
6465 @ Test
6566 @ RunAsClient
6667 public void givenFilterAndServlet_whenGetHello_thenRespondFilteringHello () throws MalformedURLException {
6768 Client client = ClientBuilder .newClient ();
6869 WebTarget target = client .target (URI .create (new URL (base , "hello" ).toExternalForm ()));
69- Response response = target
70- .request ()
71- .get ();
70+ Response response = target .request ().get ();
7271
7372 assertEquals ("filtering hello" , response .readEntity (String .class ));
7473 }
@@ -78,9 +77,7 @@ public void givenFilterAndServlet_whenGetHello_thenRespondFilteringHello() throw
7877 public void givenFilterAndServlet_whenPostEcho_thenEchoFiltered () throws MalformedURLException {
7978 Client client = ClientBuilder .newClient ();
8079 WebTarget target = client .target (URI .create (new URL (base , "echo" ).toExternalForm ()));
81- Response response = target
82- .request ()
83- .post (Entity .entity ("echo" , MediaType .TEXT_PLAIN_TYPE ));
80+ Response response = target .request ().post (Entity .entity ("echo" , MediaType .TEXT_PLAIN_TYPE ));
8481
8582 assertEquals ("filtering echo" , response .readEntity (String .class ));
8683 }
0 commit comments