1 Reply Latest reply on Aug 29, 2012 4:19 AM by Sven Schoeni

    Testing a custom exceptionHandler

    Sven Schoeni Newbie

      Hey there. i googled a bit around and couldn't find  an aswer for my question.

      how can i test a custom exceptionahndler with JSF Unit ?

       

      Thanks for answers

        • 1. Re: Testing a custom exceptionHandler
          Sven Schoeni Newbie

          So this is kind an easy way to do it. just add custom faces-config.xml that contains the exception handler factory.

          Like this :

           

          <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">

                    <factory>

                              <exception-handler-factory>CheckedExceptionHandlerFactory</exception-handler-factory>

                    </factory>

          </faces-config>

           

          then create a xhtml page with a button on it to throw the exception

          Like this:

           

          <?xml version="1.0" encoding="UTF-8"?>

          <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:ui="http://java.sun.com/jsf/facelets">

          <h:head></h:head>

          <h:body>

                    <h:commandButton action="#{exceptionHandlerTestBean.throwBusinessException}" id="businessexception" />

          </h:body>

          </html>

           

          absoluty important is NOT to add a <h:form> other wise you will get an exception like this:

          org.jboss.arquillian.test.spi.ArquillianProxyException: com.gargoylesoftware.htmlunit.ScriptException : TypeError: Cannot read property "0" from null (http://127.0.0.1:8080/businessexceptionhandlertest/javax.faces.resource/bridge.js.xhtml?v=1577144572#1958) [Proxied because : Original exception not serializable, NotSerializableException]

                    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.callFunction(JavaScriptEngine.java:531)

                    at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:906)

                    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:197)

                    at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:216)

                    at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:686)

                    at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:885)

                    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.html.HtmlElement.fireEvent(HtmlElement.java:890)

                    at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:865)

                    at com.gargoylesoftware.htmlunit.html.HtmlForm.submit(HtmlForm.java:108)

                    at com.gargoylesoftware.htmlunit.html.HtmlSubmitInput.doClickAction(HtmlSubmitInput.java:77)

                    at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1263)

                    at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1214)

                    at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1177)

                    at org.jboss.jsfunit.jsfsession.JSFClientSession.click(JSFClientSession.java:225)

                    at ch.mobi.weblibs.exception.impl.commons_v3.BusinessExceptionHandlerJSFUnitTest.testhandleNavigation(BusinessExceptionHandlerJSFUnitTest.java:63)

                    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)

                    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.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:270)

                    at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.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 java.lang.reflect.Method.invoke(Method.java:601)

                    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

                    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.container.test.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)

                    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)

                    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

                    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.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 java.lang.reflect.Method.invoke(Method.java:601)

                    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

                    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 java.lang.reflect.Method.invoke(Method.java:601)

                    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

                    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 java.lang.reflect.Method.invoke(Method.java:601)

                    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)

                    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.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)

                    at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:263)

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

                    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:734)

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

                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)

                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

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

                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)

                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

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

                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)

                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

                    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

                    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

                    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)

                    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)

                    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

                    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

                    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)

                    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

                    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)

                    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)

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

          Caused by: org.jboss.arquillian.test.spi.ArquillianProxyException: net.sourceforge.htmlunit.corejs.javascript.EcmaError : TypeError: Cannot read property "0" from null (http://127.0.0.1:8080/businessexceptionhandlertest/javax.faces.resource/bridge.js.xhtml?v=1577144572#1958) [Proxied because : Original exception not serializable, NotSerializableException]

                    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.typeError(ScriptRuntime.java:3778)

                    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3797)

                    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3810)

                    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectIndex(ScriptRuntime.java:1545)

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

                    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.call(InterpretedFunction.java:162)

                    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:559)

                    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:524)

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

                    ... 115 more

           

           

          By now you can test the exceptionhandler