0 Replies Latest reply on Jan 3, 2012 4:42 AM by Carlos Romero

    jsfunit - test failures due to illegalstate and nullpointers

    Carlos Romero Newbie

      Hello all,

       

      I'm trying to run an interface tests with JSFUnit. Right now my only concern is writing some text (spiderman, for instance) in a search box (filters:text_anno), clicking on a search button, and recovering the bean with the results in order to check it is producing what's actually expected. Thing is, I'm facing a couple of problems.

       

      a) Once I simulate a click on the search button (client.click("filters:searchButton");)the resulting control obtained via client.getElement() is empty. However, if I access the running application via a web browser and repeat the same steps, I can see it gets filled. The control is a dropdown menu, the options of which act as a further filter for the results. Perhaps it's a problem with the tests running too fast for the controls to be refreshed, so to speak? Of course, trying to click one of the non-existent options results in a null pointer exception.

       

      b)If I don't try to further filter the results (that is, not choosing anything in the dropdown menu) and instead just recover the results bean, I get an IllegalStateException.

       

       

      The test code I'm running is the following:

       

      package com.playence.media.test;

       

      import java.io.IOException;

      import java.net.URL;

      import java.util.Iterator;

       

      import javax.faces.application.Application;

      import javax.faces.component.html.HtmlSelectOneMenu;

      import javax.faces.context.ExternalContext;

      import javax.faces.context.FacesContext;

      import javax.faces.el.ValueBinding;

       

      import junit.framework.Test;

      import junit.framework.TestSuite;

       

      import org.apache.cactus.ServletTestCase;

      import org.jboss.jsfunit.framework.FacesContextBridge;

      import org.jboss.jsfunit.framework.WebClientSpec;

      import org.jboss.jsfunit.jsfsession.JSFClientSession;

      import org.jboss.jsfunit.jsfsession.JSFServerSession;

      import org.jboss.jsfunit.jsfsession.JSFSession;

      import org.w3c.dom.html.HTMLAnchorElement;

      import org.w3c.dom.html.HTMLOptionElement;

       

      import com.gargoylesoftware.htmlunit.BrowserVersion;

      import com.gargoylesoftware.htmlunit.Page;

      import com.gargoylesoftware.htmlunit.WebClient;

      import com.gargoylesoftware.htmlunit.html.HtmlDivision;

      import com.gargoylesoftware.htmlunit.html.HtmlAnchor;

      import com.gargoylesoftware.htmlunit.html.HtmlForm;

      import com.gargoylesoftware.htmlunit.html.HtmlHeading4;

      import com.gargoylesoftware.htmlunit.html.HtmlInput;

      import com.gargoylesoftware.htmlunit.html.HtmlOption;

      import com.gargoylesoftware.htmlunit.html.HtmlPage;

      import com.gargoylesoftware.htmlunit.html.HtmlSelect;

      import com.gargoylesoftware.htmlunit.html.HtmlSpan;

      import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;

      import com.playence.uisearch.bean.SearchResults;

       

      public class JSFunitSearch extends ServletTestCase {

          private JSFClientSession client;

          private JSFServerSession server;

        

       

          // JUnit suite() method

          public static Test suite() {

              return new TestSuite(JSFunitSearch.class);

          }

       

          // optional JUnit setUp() method

          public void setUp() throws Exception {

          

              JSFSession jsfSession = new JSFSession("/sections/explore/index.jsf");

              // CLIENT-SIDE SETUP

              this.client = jsfSession.getJSFClientSession();

               this.client.getContentPage().getEnclosingWindow().getWebClient().setJavaScriptEnabled(false);

              this.client.getContentPage().getEnclosingWindow().getWebClient().setThrowExceptionOnScriptError(false);

              // SERVER-SIDE SETUP

              this.server = jsfSession.getJSFServerSession();

          }

       

         

          public void testSearchFilterByLocation() throws IOException {

              //FacesContext context = FacesContext.getCurrentInstance();

              FacesContext context = server.getFacesContext();

              Application app = context.getApplication();

             

             

       

             

              client.setValue("filters:text_anno", "spiderman");

              client.click("filters:searchButton");

              ValueBinding binding = app.createValueBinding("#{searchResults}");

            

              //((HtmlSelect)client.getElement("filters:location_feature")).getOption(1)

              HtmlOption ho =  ((HtmlSelect)client.getElement("filters:location_feature")).getOptionByText("New York (3)");

              ho.setSelected(true);

             

              SearchResults sResults = (SearchResults) binding.getValue(context);

       

          }

      }

       

       

       

       

      The IllegalStateException I'm getting is the following:

       

      Test set: com.playence.media.test.JSFunitSearch

      -------------------------------------------------------------------------------

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

      testSearchFilterByLocation(com.playence.media.test.JSFunitSearch)  Time elapsed: 11.282 sec  <<< ERROR!

      java.lang.IllegalStateException

          at com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:655)

          at com.sun.faces.context.FacesContextImpl.getELContext(FacesContextImpl.java:250)

          at org.jboss.jsfunit.context.JSFUnitFacesContext.getELContext(JSFUnitFacesContext.java:340)

          at com.sun.faces.application.ValueBindingValueExpressionAdapter.getValue(ValueBindingValueExpressionAdapter.java:113)

          at com.playence.media.test.JSFunitSearch.testSearchFilterByLocation(JSFunitSearch.java:136)

          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 junit.framework.TestCase.runTest(TestCase.java:168)

          at junit.framework.TestCase.runBare(TestCase.java:134)

          at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:155)

          at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:120)

          at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java:94)

          at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java:102)

          at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java:73)

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

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

          at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)

          at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)

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

          at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:343)

          at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)

          at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:112)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:188)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:109)

          at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:355)

          at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:149)

          at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)

          at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)

          at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)

          at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)

          at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)

          at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)

          at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)

          at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)

          at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)

          at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)

          at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

          at org.mortbay.jetty.Server.handle(Server.java:326)

          at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)

          at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)

          at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)

          at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)

          at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)

          at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)

          at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

       

      I'm pretty new to this technology, and definitely stuck in this - any help or pointers you could provide would be extremely welcome. Also, if you need me to post anything, I'll gladly do so.