6 Replies Latest reply on Oct 13, 2010 9:29 PM by Samuel Santos

    Arquillian run modes

    Samuel Santos Newbie

      While the following TestNG test works fine with the mode RunModeType.AS_CLIENT:

       

      @Run(RunModeType.AS_CLIENT)
      public class FooServiceTest extends Arquillian {
      
          private static final Logger log = Logger.getLogger(FooServiceTest.class.getName());
      
          @Deployment
          public static EnterpriseArchive createDeployment() throws IOException {
              final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar").addClasses(FooService.class,
                      FooServiceBean.class);
              final WebArchive war = ShrinkWrap.create(WebArchive.class, "foo.war").addClasses(EJBBean.class,
                      EJBInterceptor.class, BaseActionBean.class, FooActionBean.class).addLibraries("stripes-1.5.3.jar")
                      .setWebXML("WEB-INF/web.xml"); // Find a better way to inject dependencies
              final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "stripes-ejb3.ear").addModule(ejbJar)
                      .addModule(war);
              log.info(ear.toString(true));
      
              return ear;
          }
      
          @Test
          public void shouldGreetUser() throws IOException {
              final String name = "Earthlings";
              final URL url = new URL("http://localhost:8080/foo/Foo.action");
              StringBuilder builder = new StringBuilder();
              BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
              String line;
      
              while ((line = reader.readLine()) != null) {
                  builder.append(line);
              }
              reader.close();
      
              log.info("Returned response:");
              log.info(builder.toString());
              assertEquals(builder.toString(), FooService.GREETING + name);
          }
      }
      

       

      It fails with the default mode RunModeType.IN_CONTAINER.

      Doing the following request

      127.0.0.1 - - [11/Oct/2010:02:10:06 +0100] "GET /test/ArquillianServletRunner?outputMode=serializedObject&className=my.package.FooServiceTest&methodName=shouldGreetUser HTTP/1.1" 200 2971
      

      instead of

      127.0.0.1 - - [11/Oct/2010:02:33:35 +0100] "GET /foo/Foo.action HTTP/1.1" 200 17
      

       

      Does anyone knows why this happens?

       

      Cheers,

      Samuel

        • 1. Re: Arquillian run modes
          Aslak Knutsen Master

          Samuel Santos wrote:

           

          It fails with the default mode RunModeType.IN_CONTAINER.

          Doing the following request

          127.0.0.1 - - [11/Oct/2010:02:10:06 +0100] "GET /test/ArquillianServletRunner?outputMode=serializedObject&className=my.package.FooServiceTest&methodName=shouldGreetUser HTTP/1.1" 200 2971
          

          instead of

          127.0.0.1 - - [11/Oct/2010:02:33:35 +0100] "GET /foo/Foo.action HTTP/1.1" 200 17

          When running IN_CONTAINER you will get the first URL executed, it's how Arquillian talks to the container. But that shouldn't stop the second one from working..

           

          Do you get any exception?

           

          What container are you using?

          • 2. Re: Arquillian run modes
            Samuel Santos Newbie

            Hi Aslak,

             

            Thanks for the quick reply!

             

            No, I don't get any exception.

             

            I've tested it with two containers:

            • arquillian-jbossas-remote-5.1 using JBoss AS 5.1.0.GA
            • arquillian-jbossas-embedded-6 using JBoss AS 6.0.0.20100911-M5

             

            It works fine in both cases as long as you use the AS_CLIENT mode.

             

            Aslak Knutsen wrote:

             

            When running IN_CONTAINER you will get the first URL executed, it's how Arquillian talks to the container. But that shouldn't stop the second one from working..

             

             

            But running IN_CONTAINER never executes the second URL.

            • 3. Re: Arquillian run modes
              Samuel Santos Newbie

              Hi Aslak,

               

              Any news on this?

              • 4. Re: Arquillian run modes
                Dan Allen Master

                You are confusing the HTTP request that you are issuing with the HTTP request that Arquillian is issuing. When you run in-container, Arquillian first has to reach out to the server to execute the test, hence the GET request for /test/ArquillianServletRunner...

                 

                Your test method is not getting executed (or it's executed after that, if the test is passing).

                 

                Why do you want to run in-container if you are accessing the web application using an HTTP request?

                 

                The point of the client mode is for HTTP testing (and other protocols). In-container testing is when you want to execute the server-side components directly. (You can use a gray box approach as well, where the test runs in-container but then hits the container via the loopback interface).

                1 of 1 people found this helpful
                • 5. Re: Arquillian run modes
                  Dan Allen Master

                  Also note that we've got some improvements coming to how archives are handled in Servlet 2.5 environments. So for maximum success in the short-run, use a Servlet 3 environment (such as JBoss AS 6).

                  • 6. Re: Arquillian run modes
                    Samuel Santos Newbie

                    Thanks Dan,

                     

                    The difference between the two run modes is now clearer.

                    I assumed something was wrong there since my HTTP request was never being issued after Arquillian's request.