5 Replies Latest reply on Feb 18, 2014 9:46 AM by Bartosz Majsak

    Warp and Mockito

    Euber Almeida Newbie

      This error happens when use mock.

      The login action on website goes OK, but after the @AfterServlet i got this:

       

       

      org.jboss.arquillian.warp.exception.ServerWarpExecutionException: failed to retrieve a response payloade: java.lang.ClassNotFoundException: org.arquillian.example.model.ILogin$$EnhancerByMockitoWithCGLIB$$84cbfdcb
      at org.jboss.arquillian.warp.impl.client.execution.DefaultResponseDeenrichmentService.retrieveResponsePayload(DefaultResponseDeenrichmentService.java:124)
      at org.jboss.arquillian.warp.impl.client.execution.DefaultResponseDeenrichmentService.deenrichResponse(DefaultResponseDeenrichmentService.java:83)
      at org.jboss.arquillian.warp.impl.client.execution.EnrichmentObserver.deenrichResponse(EnrichmentObserver.java:113)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
      at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
      at org.jboss.arquillian.warp.impl.client.execution.EnrichmentObserver.tryDeenrichResponse(EnrichmentObserver.java:94)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
      at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
      at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
      at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
      at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
      at org.jboss.arquillian.warp.impl.client.execution.DefaultResponseDeenrichmentFilter.filterResponse(DefaultResponseDeenrichmentFilter.java:55)
      at org.jboss.arquillian.warp.impl.client.proxy.DefaultProxyService$4.performInContext(DefaultProxyService.java:124)
      at org.jboss.arquillian.warp.impl.client.proxy.DefaultProxyService$4.performInContext(DefaultProxyService.java:121)
      at org.jboss.arquillian.warp.impl.client.context.operation.Contextualizer$2.performInContext(Contextualizer.java:54)
      at org.jboss.arquillian.warp.impl.client.proxy.DefaultProxyService$7.filterResponse(DefaultProxyService.java:149)
      at org.littleshoot.proxy.HttpRelayingHandler.messageReceived(HttpRelayingHandler.java:190)
      at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
      at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
      at org.jboss.netty.channel.SimpleChannelHandler.messageReceived(SimpleChannelHandler.java:149)
      at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:95)
      at org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler.handleUpstream(IdleStateAwareChannelHandler.java:43)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
      at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
      at org.jboss.netty.handler.timeout.IdleStateHandler.messageReceived(IdleStateHandler.java:294)
      at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
      at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
      at org.jboss.netty.handler.codec.http.HttpChunkAggregator.messageReceived(HttpChunkAggregator.java:149)
      at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
      at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
      at org.jboss.netty.handler.codec.http.HttpContentDecoder.messageReceived(HttpContentDecoder.java:100)
      at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
      at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791)
      at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
      at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:455)
      at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:538)
      at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:437)
      at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:563)
      at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:558)
      at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
      at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
      at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:91)
      at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedKeys(AbstractNioWorker.java:373)
      at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:247)
      at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)
      at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102)
      at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)
      Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: org.arquillian.example.model.ILogin$$EnhancerByMockitoWithCGLIB$$84cbfdcb
      at org.jboss.arquillian.warp.impl.utils.SerializationUtils.deserializeFromBytes(SerializationUtils.java:54)
      at org.jboss.arquillian.warp.impl.client.execution.DefaultResponseDeenrichmentService$RetrievePayloadFromServer.getResponsePayload(DefaultResponseDeenrichmentService.java:162)
      at org.jboss.arquillian.warp.impl.client.execution.DefaultResponseDeenrichmentService.retrieveResponsePayload(DefaultResponseDeenrichmentService.java:119)
      ... 67 more
      Caused by: java.lang.ClassNotFoundException: org.arquillian.example.model.ILogin$$EnhancerByMockitoWithCGLIB$$84cbfdcb
      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:247)
      at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:603)
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
      at java.util.ArrayList.readObject(ArrayList.java:593)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:969)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
      at org.jboss.arquillian.warp.impl.utils.SerializationUtils.deserializeFromBytes(SerializationUtils.java:50)
      ... 69 more
      
      

       

       

      @Test
      @RunAsClient
      public void dummyTest() {
      
      browser.navigate().to(contextPath + "login.jsf");
      
      Warp.initiate(new Activity() {
      
      public void perform() {
      
      WebElement userName = browser.findElement(By
      .id("loginForm:userName"));
      WebElement password = browser.findElement(By
      .id("loginForm:password"));
      WebElement loginButton = browser.findElement(By
      .id("loginForm:login"));
      
      userName.sendKeys("demo"); // 3. control the page
      password.sendKeys("demo");
      
      guardHttp(loginButton).click();
      }
      })
      
      .inspect(new Inspection() {
      private static final long serialVersionUID = 1L;
      @ArquillianResource
      HttpServletRequest request;
      
      @Inject
      private LoginController loginController;
      
      private ILogin loginFacade;
      
      @BeforeServlet
      public void verifyRequestMethod() {
      loginFacade = Mockito.mock(ILogin.class, Mockito.withSettings()
      .serializable()
      .verboseLogging());
      
      System.out.println(loginFacade.doLogin("demo", "demo"));
      Mockito.when(loginFacade.doLogin("demo", "demo")).thenReturn(true);
      Mockito.when(loginFacade.getUsername()).thenReturn("demo");
      System.out.println(loginFacade.doLogin("demo", "demo"));
      
      loginController.setLoginFacade(loginFacade);
      
      }
      
      @AfterServlet
      public void verifyAfter() {
      if (loginController.getCurrentUser() != null) {
      System.out.println(loginController.getCurrentUser()
      .getUsername());
      }
      }
      });
      }
      
        • 1. Re: Warp and Mockito
          Bartosz Majsak Master

          Can you share your deployment method as well? Are you adding mockito to the web application you are testing?

          • 2. Re: Re: Warp and Mockito
            Euber Almeida Newbie

            Yes.

            In debug mode the mock works, the user login in application, but when the request finish i got the error.

             

            HomePageWarpTest.java

            package org.arquillian.example;
            
            import static org.jboss.arquillian.graphene.Graphene.guardHttp;
            import static org.junit.Assert.assertTrue;
            
            import java.net.URL;
            
            import javax.inject.Inject;
            import javax.servlet.http.HttpServletRequest;
            
            import org.arquillian.example.model.ILogin;
            import org.jboss.arquillian.container.test.api.Deployment;
            import org.jboss.arquillian.container.test.api.RunAsClient;
            import org.jboss.arquillian.drone.api.annotation.Drone;
            import org.jboss.arquillian.junit.Arquillian;
            import org.jboss.arquillian.test.api.ArquillianResource;
            import org.jboss.arquillian.warp.Activity;
            import org.jboss.arquillian.warp.Inspection;
            import org.jboss.arquillian.warp.Warp;
            import org.jboss.arquillian.warp.WarpTest;
            import org.jboss.arquillian.warp.servlet.AfterServlet;
            import org.jboss.arquillian.warp.servlet.BeforeServlet;
            import org.jboss.shrinkwrap.api.spec.WebArchive;
            import org.junit.Test;
            import org.junit.runner.RunWith;
            import org.mockito.Mockito;
            import org.openqa.selenium.By;
            import org.openqa.selenium.WebDriver;
            import org.openqa.selenium.WebElement;
            
            @RunAsClient
            @WarpTest
            @RunWith(Arquillian.class)
            public class HomePageWarpTest {
            
            @Drone
            private WebDriver browser;
            
            @ArquillianResource
            private URL contextPath;
            
            
            
            @Deployment
            public static WebArchive createDeployment() {
            return Deployments.createLoginScreenDeployment();
            }
            
            @Test
            @RunAsClient
            public void dummyTest() {
            
            browser.navigate().to(contextPath + "login.jsf");
            
            Warp.initiate(new Activity() {
            
            public void perform() {
            
            WebElement userName = browser.findElement(By
            .id("loginForm:userName"));
            WebElement password = browser.findElement(By
            .id("loginForm:password"));
            WebElement loginButton = browser.findElement(By
            .id("loginForm:login"));
            
            userName.sendKeys("demo"); // 3. control the page
            password.sendKeys("demo");
            
            guardHttp(loginButton).click();
            }
            })
            
            .inspect(new Inspection() {
            private static final long serialVersionUID = 1L;
            @ArquillianResource
            HttpServletRequest request;
            
            @Inject
            private LoginController loginController;
            
            private ILogin loginFacade;
            
            @BeforeServlet
            public void verifyRequestMethod() {
            loginFacade = Mockito.mock(ILogin.class, Mockito.withSettings()
            .serializable());
            //System.out.println(loginFacade.doLogin("demo", "demo"));
            Mockito.when(loginFacade.doLogin("demo", "demo")).thenReturn(true);
            Mockito.when(loginFacade.getUsername()).thenReturn("demo");
            //System.out.println(loginFacade.doLogin("demo", "demo"));
            
            loginController.setLoginFacade(loginFacade);
            
            }
            
            @AfterServlet
            public void verifyAfter() {
            if (loginController.getCurrentUser() != null) {
            System.out.println(loginController.getCurrentUser()
            .getUsername());
            }
            }
            });
            }
            
            }
            

             

            Deployments

             

            package org.arquillian.example;
            
            import org.arquillian.example.model.ILogin;
            import org.arquillian.example.model.LoginProd;
            import org.arquillian.example.util.ReadPropertiesFile;
            import org.jboss.shrinkwrap.api.Filters;
            import org.jboss.shrinkwrap.api.GenericArchive;
            import org.jboss.shrinkwrap.api.ShrinkWrap;
            import org.jboss.shrinkwrap.api.asset.EmptyAsset;
            import org.jboss.shrinkwrap.api.asset.StringAsset;
            import org.jboss.shrinkwrap.api.importer.ExplodedImporter;
            import org.jboss.shrinkwrap.api.spec.WebArchive;
            import org.jboss.shrinkwrap.resolver.api.maven.Maven;
            
            public class Deployments {
            private static final String WEBAPP_SRC = "src/main/webapp";
            
            public static WebArchive createLoginScreenDeployment() {
            return ShrinkWrap
            .create(WebArchive.class, "login.war")
            .addClasses(Credentials.class, User.class,
            ReadPropertiesFile.class, LoginController.class,
            ILogin.class, LoginProd.class)
            .addAsLibraries(
            Maven.resolver()
            .resolve("org.mockito:mockito-all:1.9.5")
            .withTransitivity().asFile())
            .merge(ShrinkWrap.create(GenericArchive.class)
            .as(ExplodedImporter.class).importDirectory(WEBAPP_SRC)
            .as(GenericArchive.class), "/",
            Filters.include(".*\\.xhtml$"))
            .addAsResource("config.properties")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsWebInfResource(
            new StringAsset("<faces-config version=\"2.0\"/>"),
            "faces-config.xml");
            }
            
            
            • 3. Re: Re: Warp and Mockito
              Bartosz Majsak Master

              I knew it's ain't that easy Would it be possible to isolate the problem and share through github?

              • 4. Re: Warp and Mockito
                Euber Almeida Newbie

                Project File (33Kb)

                http://www.datafilehost.com/d/b4e0d53b

                 

                The error occurs on method:

                 

                public static <T extends Serializable> T deserializeFromBytes(byte[] serializedObject) {

                 

                File  SerializationUtils

                 

                Open a issue in github or publish the project?

                • 5. Re: Warp and Mockito
                  Bartosz Majsak Master

                  It's enough for me now. I will keep you in the loop.