1 2 Previous Next 21 Replies Latest reply: Oct 12, 2011 1:50 PM by badr elhouari RSS

JsfUnit2 with Primefaces?

Craig Greenhalgh Newbie

Hi has anyone managed to get jsfunit2 working with primefaces 2.x or 3 ?

 

I use arquillian and it all works fine until I swap a standard component for the primefaces equivalent.

 

Has anyone expirienced this?

 

Thanks

 

Craig

  • 1. JsfUnit2 with Primefaces?
    Arek C Newbie

    Hi *,

     

    i try to run primefaces with jsfunit2 and have no luck:

     

    - snip -

    Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError:

    ReferenceError: "PrimeFaces" is not defined. (script in

    http://localhost:8080/test/index.faces from (9, 227) to (9, 323)#9)

           at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3772)

    - snip -

     

    complete stack trace...

     

    org.jboss.arquillian.impl.event.FiredEventException:

    java.lang.RuntimeException: Could not inject members

           at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:68)

           at org.jboss.arquillian.impl.context.AbstractEventContext.fire(AbstractEventContext.java:115)

           at org.jboss.arquillian.impl.EventTestRunnerAdaptor.before(EventTestRunnerAdaptor.java:127)

           at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:206)

           at org.jboss.arquillian.junit.Arquillian$5$1.evaluate(Arquillian.java:225)

           at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:297)

           at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:221)

           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)

           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

           at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)

           at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)

           at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)

           at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)

           at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)

           at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:163)

           at org.jboss.arquillian.junit.Arquillian$3$1.evaluate(Arquillian.java:186)

           at org.jboss.arquillian.junit.Arquillian$MultiStatementExecutor.execute(Arquillian.java:297)

           at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:182)

           at org.junit.runners.ParentRunner.run(ParentRunner.java:236)

           at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:127)

           at org.junit.runner.JUnitCore.run(JUnitCore.java:157)

           at org.junit.runner.JUnitCore.run(JUnitCore.java:136)

           at org.jboss.arquillian.junit.JUnitTestRunner.execute(JUnitTestRunner.java:69)

           at org.jboss.arquillian.protocol.servlet_3.ServletTestRunner.doGet(ServletTestRunner.java:84)

           at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

           at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

           at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:530)

           at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1219)

           at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:119)

           at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1190)

           at org.jboss.jsfunit.arquillian.JSFUnitCleanupTestTreadFilter.doFilter(JSFUnitCleanupTestTreadFilter.java:51)

           at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1190)

           at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:424)

           at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)

           at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:494)

           at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:229)

           at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:931)

           at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:361)

           at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)

           at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:867)

           at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)

           at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)

           at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)

           at org.eclipse.jetty.server.Server.handle(Server.java:337)

           at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:581)

           at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1005)

           at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:560)

           at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:222)

           at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:417)

           at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:474)

           at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:437)

           at java.lang.Thread.run(Thread.java:619)

    Caused by: java.lang.RuntimeException: Could not inject members

           at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:104)

           at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.enrich(CDIInjectionEnricher.java:52)

           at org.jboss.arquillian.impl.handler.TestCaseEnricher.callback(TestCaseEnricher.java:42)

           at org.jboss.arquillian.impl.handler.TestCaseEnricher.callback(TestCaseEnricher.java:32)

           at org.jboss.arquillian.impl.event.MapEventManager.fire(MapEventManager.java:63)

           ... 51 more

    Caused by: com.gargoylesoftware.htmlunit.ScriptException:

    ReferenceError: "PrimeFaces" is not defined. (script in

    http://localhost:8080/test/index.faces from (9, 227) to (9, 323)#9)

           at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:601)

           at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)

           at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)

           at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:499)

           at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:474)

           at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:880)

           at com.gargoylesoftware.htmlunit.html.HtmlScript.executeInlineScriptIfNeeded(HtmlScript.java:312)

           at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:379)

           at com.gargoylesoftware.htmlunit.html.HtmlScript$1.execute(HtmlScript.java:225)

           at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:245)

           at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:578)

           at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)

           at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:536)

           at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1136)

           at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1038)

           at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:206)

           at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:329)

           at org.cyberneko.html.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:2999)

           at org.cyberneko.html.HTMLScanner$ContentScanner.scan(HTMLScanner.java:1991)

           at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:895)

           at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:499)

           at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:452)

           at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)

           at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:765)

           at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:211)

           at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:165)

           at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:225)

           at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:108)

           at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:429)

           at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307)

           at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:369)

           at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:354)

           at org.jboss.jsfunit.framework.SimpleInitialRequestStrategy.doInitialRequest(SimpleInitialRequestStrategy.java:48)

           at org.jboss.jsfunit.framework.WebClientSpec.doInitialRequest(WebClientSpec.java:259)

           at org.jboss.jsfunit.jsfsession.JSFSession.<init>(JSFSession.java:81)

           at org.jboss.jsfunit.cdi.JSFSessionFactory.createJSFSession(JSFSessionFactory.java:177)

           at org.jboss.jsfunit.cdi.JSFSessionFactory.findJSFSession(JSFSessionFactory.java:195)

           at org.jboss.jsfunit.cdi.JSFSessionFactory.getJSFClientSession(JSFSessionFactory.java:202)

           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.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305)

           at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)

           at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)

           at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299)

           at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:188)

           at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstance(MethodInjectionPoint.java:169)

           at org.jboss.weld.bean.ProducerMethod$1.produce(ProducerMethod.java:149)

           at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:361)

           at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:67)

           at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:690)

           at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:772)

           at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:138)

           at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:872)

           at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:884)

           at org.jboss.weld.manager.SimpleInjectionTarget$1.proceed(SimpleInjectionTarget.java:120)

           at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:54)

           at org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:114)

           at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectNonContextualInstance(CDIInjectionEnricher.java:114)

           at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:93)

           ... 55 more

    Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError:

    ReferenceError: "PrimeFaces" is not defined. (script in

    http://localhost:8080/test/index.faces from (9, 227) to (9, 323)#9)

           at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3772)

           at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3750)

           at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3835)

           at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.name(ScriptRuntime.java:1763)

           at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1781)

           at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:845)

           at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)

           at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:429)

           at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:269)

           at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3162)

           at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)

           at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$3.doRun(JavaScriptEngine.java:490)

           at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595)

           ... 115 more

  • 2. JsfUnit2 with Primefaces?
    Stan Silvert Master

    Does it work with JSFUnit 3.1?  JSFUnit 2 uses the same version of HtmlUnit.  Maybe Arquillian/JSFUnit is more sensitive to javascript errors.

     

    I did find these.  Maybe they will be helpful:

    http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&t=1118

     

    http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&t=1530

     

    Stan

  • 3. JsfUnit2 with Primefaces?
    Arek C Newbie

    Hi Stan,

     

    JSFUnit 3? Or do you mean primefaces 3 ? I use primefaces 3 in my exception enviroment.

     

    Thanks for the primefaces links, i will try to track the problem fix´s and change my code...

     

    Arek

  • 4. JsfUnit2 with Primefaces?
    Craig Greenhalgh Newbie

    I've tried primefaces 2.2.1 and 3.0 snaphot and still no luck

     

    Thanks

     

    Craig

  • 5. JsfUnit2 with Primefaces?
    Stan Silvert Master

    Arek C wrote:

     

    Hi Stan,

     

    JSFUnit 3? Or do you mean primefaces 3 ? I use primefaces 3 in my exception enviroment.

     

    Thanks for the primefaces links, i will try to track the problem fix´s and change my code...

     

    Arek

    Sorry, I meant JSFUnit 1.3.  I was talking about doing things the old way using Cactus, but you might not want to go to the trouble of trying that.  Hopefully, getting PrimeFaces to behave will fix the problem.

     

    Stan

  • 6. JsfUnit2 with Primefaces?
    Stan Silvert Master

    Hi guys.  For those of you having trouble with PrimeFaces, I'm wondering if this Jira is related:

    https://issues.jboss.org/browse/JSFUNIT-267

     

    I don't have time to look into it right now, but if I remember correctly it has to do with the JSFUnit console mapping to *.jsfunit.  PrimeFaces doesn't like this for some reason?  I don't really remember, and I wish I could go in there and fix it now.  Maybe that Jira will help.

     

    Stan

  • 7. Re: JsfUnit2 with Primefaces?
    badr elhouari Novice

    Hi Stan,

     

    is there any update about this issue ! is the beta2 contains the bug fix ?!

  • 8. Re: JsfUnit2 with Primefaces?
    Stan Silvert Master

    It wasn't fixed, but I doubt that this would be an issue if you are using Arquillian.

     

    Stan

  • 9. Re: JsfUnit2 with Primefaces?
    badr elhouari Novice

    Yes i'm using Arquillian, but i don't think so that the problem is due to that !

     

    The getting started example here http://community.jboss.org/wiki/JSFUnit200Beta2GettingStartedExample  works fine for me!

     

    for a simple test with primefaces i've added the dependency to primefaces 2.2 and i've modifed the index.xhtml as bellow:

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml"

          xmlns:h="http://java.sun.com/jsf/html"

          xmlns:f="http://java.sun.com/jsf/core"

         xmlns:p="http://primefaces.prime.com.tr/ui">

      <f:view>

        <h:form id="form1">

          <h:outputText value="Enter Your Name:"/>

         <p:inputText id="name"/>

          <h:commandButton id="submit_button"/>

        </h:form>

        <h:outputText id="greeting"

                      rendered="#{not empty request.getParameter('form1:name')}"

                      value=" Hello #{request.getParameter('form1:name')}"/>

      </f:view>

    </html>

     

    The surfire report say:

     

    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 16.697 sec <<< FAILURE!

    testInitialPage(org.jboss.jsfunit.example.hellojsf.HelloJSFTest)  Time elapsed: 1.982 sec  <<< ERROR!

    java.lang.IllegalArgumentException: This method can not be used on components of type com.gargoylesoftware.htmlunit.html.HtmlUnknownElement

              at org.jboss.jsfunit.jsfsession.JSFClientSession.setValue(JSFClientSession.java:172)

              at org.jboss.jsfunit.example.hellojsf.HelloJSFTest.testInitialPage(HelloJSFTest.java:74)

              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)....

     

    the HelloJSFTest.java:74 is client.setValue("name", "Stan");

     

    PS:I have checked my jboss7 server log i saw that the test.war was deployed and undeployed succefully, so it isn't an Arquillian problem

  • 10. Re: JsfUnit2 with Primefaces?
    badr elhouari Novice

    Hi Stan!

     

    I think there is no issue with primefaces ;-) my previous error is due to the fact that the primefaces jar wasn't in my War archive ! i've triyed the Maven resolver for ShrinkWrap to add it, but i had some issue with it (i'll look for that later)

     

    To test the integration quickly i've put the primefaces-2.2.jar into a lib folder under WEB-INF directory and add this line to my deplyoment methode:

     

    .addAsWebInfResource(new File("src/main/webapp/WEB-INF/lib/primefaces-2.2.jar"),"lib/primefaces-2.2.jar");

     

    After that i get the error  "PrimeFaces" is not defined...

     

    I've just added the <h:head></h:head> to the index.xhtml file and my test succed !!!! witch means that the primefaces resources was included automatically !!!

     

    i'm glad it works ! and i'm glad to discover that JSFUnit is being so powerful !

  • 11. Re: JsfUnit2 with Primefaces?
    Nico Knabe Newbie

    Hi badr elhouari,

     

    How far you are with the Primefacestests?

    I have trouble with same Primefaces-components like <p:calendar>. I can't use the setValue methode...

    Can you help me?

     

    ty

    Nico

  • 12. Re: JsfUnit2 with Primefaces?
    badr elhouari Novice

    Hi Niko,

     

    Sorry for he late response !  i guess you try the setValue with the id you gave to your p:calendar (<p:calendar id="date"/>), if the case you get the error :

     

    java.lang.IllegalArgumentException: This method can not be used on components of type com.gargoylesoftware.htmlunit.html.HtmlSpan

     

    it's normal because the <p:calendar id="date"> give <span id=date"> <inputText id="date_input"/> </span> and the setValue is used for input field not for span ;-) so you should use setValue ("date_input", VALUE) instead of setValue("date",VALUE)

  • 13. Re: JsfUnit2 with Primefaces?
    badr elhouari Novice

    I'm adding the full example for p:calendar here based on the getting starded example  ;-)

     

    test page :

     

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head></h:head>
      <f:view>
        <h:form id="form1">
          <h:outputText value="Enter Your date"/>
          <p:calendar id="date"></p:calendar>
          <h:commandButton id="submit_button"/>
        </h:form>
        <h:outputText id="greeting"
                      rendered="#{not empty request.getParameter('form1:date_input')}"
                      value=" Hello #{request.getParameter('form1:date_input')}"/>
      </f:view>
    
    </html>
    
    

     

    Test methode

    public void testInitialPage(JSFServerSession server, JSFClientSession client)
                throws IOException {
    
            // Set the param and submit
            String sDate = new Date().toString();
            client.setValue("date_input", sDate);
            client.click("submit_button");
    
    
    
            // Assert that the greeting component is in the component tree and rendered
            UIComponent greeting = server.findComponent("greeting");
            Assert.assertTrue(greeting.isRendered());
    
    
            // Test a managed bean using EL. We cheat and use the request object.
            Assert.assertEquals(sDate,
                    server.getManagedBeanValue("#{request.getParameter('form1:date_input')}"));
        }
    
    

     

     

    Hope it helps

  • 14. Re: JsfUnit2 with Primefaces?
    Nico Knabe Newbie

    Hi,

     

    and thank you. Now it works fine ^^.

     

    But now I have two new problems.

    1. I want to test the authentication mechanism, but it use the captcha component. I have to deactivate this element to test it. But this is not the correct solution, I think.

     

    2. I have five small JSFTests. One war file, which is build by shrinkwrap, has a size of 14MB. The internal memory of JBoss rise up from 600MB to 1600MB and doesn't go down after testing. I have to restart the JBoss every two testings. Is there a better solution?

     

    Big thanks!

1 2 Previous Next