-
1. Re: No SessionId when using JSFUnit (request alway null)
ssilvert Mar 31, 2008 9:31 AM (in response to jadtn)First, client = new JSFClientSession("/") definitely won't work. The argument must map into the FacesServlet.
How do you go into the application if you are hitting it from a browser? If your login page is something like http://localhost:8080/myapp/login.jsf then JSFClientSession("/login.jsf") is what you want. Otherwise, you need to start off like this using JSFUnit's WebConversationFactory:WebConversation webConv = WebConversationFactory.makeWebConversation(); WebRequest req = new GetMethodWebRequest(WebConversationFactory.getWARURL() + "/login.jsp"); WebResponse res = webConv.getResponse(req); WebForm loginform = res.getWebResponse().getFormWithID("loginform"); loginform.setParameter("j_username", "user"); loginform.setParameter("j_password", "user_password"); res = loginform.submit(); // now my session/webConv is authenticated. I can go to my JSF page JSFClientSession client = new JSFClientSession(webConv, "/mystartpage.jsf");
The WebConversationFactory will make sure that all requests are using the proper HttpSession.
Lastly, a null HttpSession can happen if the JSFUnit filter is not correctly configured. Make sure that it is mapped like this:<filter> <filter-name>JSFUnitFilter</filter-name> <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class> </filter> <filter-mapping> <filter-name>JSFUnitFilter</filter-name> <servlet-name>ServletTestRunner</servlet-name> </filter-mapping> <filter-mapping> <filter-name>JSFUnitFilter</filter-name> <servlet-name>ServletRedirector</servlet-name> </filter-mapping>
Hope that helps. I've been getting a lot of "login" questions lately. We obviously need some more/better examples. Please let me know how this goes for you.
Regards,
Stan -
2. Re: No SessionId when using JSFUnit (request alway null)
freemarket Dec 15, 2008 1:58 PM (in response to jadtn)Hi,
I am now attempting to integrate jsfunit 1.0.0 GA into our web application which has Acegi. The tech stack is JSF 1.2, Richfaces 3.2.2GA, facelets 1.1.14, spring 2.5, acegi 1.0.6. I have lowered the acegi blocking so that the two servlet filter-mappings are not blocked (ServletTestRunner/ServletRedirector). Without this I am instantly redirected to login page.
I am simply attempting to get beyond this:public void setUp() throws IOException { WebClientSpec wcSpec = new WebClientSpec("/login.jsf");
in my test.
What I am finding is that the WebConversationFactory.makeWebClient() method throws an exception further down in the servlet API at:
org.apache.catalina.session.StandardSession.setAttribute(String, Object, boolean)
where value is a WebClientSpec object with a requestStrategy member of SimpleInitialRequestStrategy().
The failure is here:if (!isValidInternal()) throw new IllegalStateException (sm.getString("standardSession.setAttribute.ise")); if ((manager != null) && manager.getDistributable() && !(value instanceof Serializable)) throw new IllegalArgumentException (sm.getString("standardSession.setAttribute.iae"));
Here is the stack trace:<?xml version="1.0" encoding="UTF-8" ?> - <testsuites> - <testsuite name="org.jboss.jsfunit.test.richfaces.RichFileUploadTest" tests="1" failures="0" errors="1" time="373.092"> - <testcase name="testFilePresent" time="372.935"> <error message="setAttribute: Non-serializable attribute" type="org.apache.cactus.internal.client.ServletExceptionWrapper"> java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1293) at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:1254) at org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:130) at org.jboss.jsfunit.framework.WebConversationFactory.makeWebClient(WebConversationFactory.java:119) at org.jboss.jsfunit.framework.WebClientSpec.<init>(WebClientSpec.java:115) at org.jboss.jsfunit.framework.WebClientSpec.<init>(WebClientSpec.java:93) at org.jboss.jsfunit.framework.WebClientSpec.<init>(WebClientSpec.java:77) at org.jboss.jsfunit.test.richfaces.RichFileUploadTest.setUp(RichFileUploadTest.java:61) at
The suggestions you've made above are for the now deprecated httpunit methods. How do I circumvent this session setting issue within an htmlunit context?
Thanks,
Henry -
3. Re: No SessionId when using JSFUnit (request alway null)
ssilvert Dec 15, 2008 5:05 PM (in response to jadtn)Your servlet container is checking every attribute that it put into the session to see if it is Serializable. This is non-standard behavior, so I assume that there is some way to disable it?
I can change JSFUnit so that everything it puts into the session is Serializable. Perhaps I should do that, but I won't be able to get to it right away.
Also, please start a new thread whenever you have a new question. So if this thread needs to continue then please copy your question to it and I'll answer in the new thread.
Regards,
Stan -
4. Re: No SessionId when using JSFUnit (request alway null)
samssams Mar 28, 2011 12:56 PM (in response to ssilvert)hey Thanks a lot for your good work on JSF Unit. I need some help.
Below code is not compiling. Could you please post new version of this? Our application requires user to be logged in for any user request. we want to use login test step in each junit.
WebConversation webConv = WebConversationFactory.makeWebConversation();
WebRequest req = new GetMethodWebRequest(WebConversationFactory.getWARURL() + "/login.jsp");
WebResponse res = webConv.getResponse(req);
WebForm loginform = res.getWebResponse().getFormWithID("loginform");I am using below versions of jar.
htmlunit-2.8.jar
htmlunit-core-js-2.8.jar
httpclient-4.0.1.jar
httpcore-4.0.1.jar
httpmime-4.0.1.jar
jboss-jsfunit-core-1.3.0.Final.jar
jboss-jsfunit-richfaces-1.3.0.Final.jar
junit-3.8.1.jar
-
5. Re: No SessionId when using JSFUnit (request alway null)
ssilvert Mar 28, 2011 3:04 PM (in response to samssams)Please create a new discussion thread for a new question. Also post more information such as the error you get while compiling and the full source of what you are trying to compile. From what you have posted I can't tell why you would need a new version of something.
Stan