0 Replies Latest reply on Nov 11, 2013 11:30 PM by alexey plotnikov

    Seam 2.3.1 and Arquillian with glassfish3(managed)

    alexey plotnikov Newbie

      Hi all, i read this article Seam - Contextual Components.

      I try run integration test with Arquillian.

      My application use Seam 2.3.1.Final, Richfaces 4.3.4.Final, Hibernate 4.1.1.Final as JPA provider. I use ant for build my project.

      I don't found any manuals about ant and managed glassfish with arquillian, so i have problems.

      My steps:

      1) In documentation above i saw this command

      ant -f get-arquillian-libs.xml -Dtest.lib.dir=lib/test
      
      

      I executed this command successfully.

      2) I want use my custom glassfish as container for tests, so i deleted all files with name "jboss-as-*" in  "lib/test" directory(in this directory was downloaded arquillian libs).

      3) From here http://arquillian.org/modules/arquillian-glassfish-embedded-3.1-container-adapter/ i downloaded files "org.jboss.arquillian.container:arquillian-glassfish-common:jar:1.0.0.CR4" and "org.jboss.arquillian.container:arquillian-glassfish-managed-3.1:jar:1.0.0.CR4" to "lib/test"

      4) i copied next files to "lib/test"(because arquillian-glassfish-managed-3.1.jar requires this libs)

      jersey-client.jar
      jersey-core.jar
      jersey-gf-server.jar
      jersey-gf-servlet.jar
      jersey-gf-statsproviders.jar
      jersey-grizzly.jar
      jersey-json.jar
      jersey-moxy.jar
      jersey-multipart.jar
      
      

      from "[GLASSFISH_HOME]/glassfish/modules/" folder

      5) In root test folder i create arquillian.xml file

      <?xml version="1.0" encoding="UTF-8"?>
      <arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns="http://jboss.org/schema/arquillian"
                  xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
      
          <defaultProtocol type="Servlet 3.0"/>
      
          <extension qualifier="seam2">
              <property name="autoPackage">false</property>
          </extension>
      
          <container qualifier="glassfish" default="true">
              <configuration>
                  <property name="glassFishHome">/srv/glassfish-3.1.2.2/</property>
                  <property name="domain">arquillian</property>
                  <property name="adminHost">localhost</property>
                  <property name="adminPort">4848</property>
                  <property name="outputToConsole">true</property>
                  <property name="allowConnectingToRunningServer">true</property>
              </configuration>
          </container>
      
          <container qualifier="glassfish-auth">
              <configuration>
                  <property name="glassFishHome">/srv/glassfish-3.1.2.2/</property>
                  <property name="adminHost">localhost</property>
                  <property name="adminPort">4848</property>
                  <property name="adminUser">admin</property>
                  <property name="adminPassword">adminadmin</property>
              </configuration>
          </container>
      </arquillian>
      
      

      6) In root test folder i create "mock-web.xml" file. This file same as web.xml(contains richfaces preferences, filters(including seam filter), some servlets, additional facelets tag library, listeners), but listener "<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>" was replaced to "<listener-class>org.jboss.seam.mock.MockSeamListener</listener-class>"(according to the documentation above).

      7) In root test folder i create RootTest.java file:

      @RunWith(Arquillian.class)
      public class RootTest extends JUnitSeamTest {
      
          @Deployment
          @OverProtocol("Servlet 3.0")
          public static Archive<?> createDeployment() {
              WebArchive web = ShrinkWrap.create(ZipImporter.class, "[PROJECT-NAME].war").
                      importFrom(new File("[FULL PATH TO PROJECT-NAME].war")).
                      as(WebArchive.class).
                      addClasses(RootTest.class);
      
              web.delete("/WEB-INF/web.xml");
              web.addAsWebInfResource("mock-web.xml", "web.xml");
      
              return web;
          }
      
          @Before
          public void before() {
              Lifecycle.beginCall();
          }
      
          @After
          public void after(){
              Lifecycle.endCall();
          }
      
          protected void setValue(String valueExpression, Object value) {
              Expressions.instance().createValueExpression(valueExpression).setValue(value);
          }
      
          @Test
          public void testLogin() throws Exception {
              new FacesRequest("/login.xhtml") {
                  @Override
                  protected void processValidations() throws Exception {
                      validateValue("#{identity.username}", "1ovthafew");
                      validateValue("#{identity.password}", "Gavin King");
                      assert !isValidationFailure();
                  }
      
                  @Override
                  protected void updateModelValues() throws Exception {
                      setValue("#{identity.username}", "1ovthafew");
                      setValue("#{identity.password}", "Gavin King");
                  }
      
                  @Override
                  protected void invokeApplication() {
                      Object a = invokeMethod("#{identity.login}");
                      System.out.println("a="+a);
                      assert a.equals("/main_page.xhtml");
                      setOutcome("/main_page.xhtml");
                  }
      
                  @Override
                  protected void afterRequest() {
                      assert isInvokeApplicationComplete();
                      assert !isRenderResponseBegun();
                  }
      
              }.run();
          }
      
      }
      
      

      8) i run test and get exception:

      
      
      java.lang.NullPointerException
        at org.jboss.seam.contexts.Contexts.destroy(Contexts.java:280)
        at org.jboss.seam.contexts.Lifecycle.endCall(Lifecycle.java:100)
        at RootTest.after(RootTest.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:36)
        at org.jboss.arquillian.junit.Arquillian$StatementLifecycleExecutor.invoke(Arquillian.java:351)
        at org.jboss.arquillian.container.test.impl.execution.AfterLifecycleEventExecuter.on(AfterLifecycleEventExecuter.java:35)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        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.testenricher.cdi.CreationalContextDestroyer.destory(CreationalContextDestroyer.java:44)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
        at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
        at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
        at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
        at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
        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.test.impl.EventTestRunnerAdaptor.after(EventTestRunnerAdaptor.java:103)
        at org.jboss.arquillian.junit.Arquillian$5$1.evaluate(Arquillian.java:245)
        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
        at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:240)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
        at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)
        at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
        at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
        at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
        at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
        at org.jboss.arquillian.junit.container.JUnitTestRunner.execute(JUnitTestRunner.java:65)
        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.executeTest(ServletTestRunner.java:160)
        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.execute(ServletTestRunner.java:126)
        at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:90)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:722)
      
      
      
      
      Process finished with exit code 255
      
      

       

      In server log i see:

      javax.el.ELException: java.lang.NullPointerException
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
              at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
              at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
              at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java
      ....................................................................................
      Caused by: java.lang.NullPointerException
              at eu.bitwalker.useragentutils.Browser.isInUserAgentString(Browser.java:330)
              at eu.bitwalker.useragentutils.Browser.checkUserAgent(Browser.java:354)
              at eu.bitwalker.useragentutils.Browser.parseUserAgentString(Browser.java:399)
              at eu.bitwalker.useragentutils.Browser.parseUserAgentString(Browser.java:384)
              at eu.bitwalker.useragentutils.UserAgent.<init>(UserAgent.java:86)
              at eu.bitwalker.useragentutils.UserAgent.parseUserAgentString(UserAgent.java:106)
              at ru.softlogic.server.auth.AuthenticatorAction.authenticate(AuthenticatorAction.java:66)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:601)
      
      

       

      What can be wrong???

       

      And second question: i exported war file(WebArchive) using ShrinkWrap and i compared original file and modified file. And i saw next difference:

      1) to modified archive added RootTest.class and RootTest$1.class(this my test)

      2) in modified archive another web.xml(same as mock-web.xml described above)

      Then i deploy original archive - everythings fine. But then i deploy modified archive i get next error in server.log:

      java.lang.InstantiationException
              at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:124)
              at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4685)
              at org.apache.catalina.core.StandardContext.start(StandardContext.java:5377)
              at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
              at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
              at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
              at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
              at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2019)
              at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
              at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
              at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
      .................................................................................
      Caused by: java.lang.NullPointerException
              at org.jboss.seam.servlet.SeamFilter.getSortedFilters(SeamFilter.java:112)
              at org.jboss.seam.servlet.SeamFilter.init(SeamFilter.java:93)
              at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:264)
              at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:120)
              ... 65 more