Yeah but then this would be specific to each testcase. Can I have a authentication done only once for all the testcases (beginXXX methods for different test cases) for a single component being tested?
I want to know if i can avoid writing/ checking authentication in each beginXXX() method. Is there any function such that cactus executes it just once and not when every testcase is encountered. Regards, Tejaswini Feliks Shvartsburd wrote: > > User authentication is maintained by the current http session, which is > maintained by passing cookies back and forth between client and server. > Cactus maintains this http session making sure that server doesn't ask > you for authentication again. > So, what you need to do is this: > > In you client side code: > > public void beginXXX(WebRequest wr){ > > HttpSessionCookie sessionCookie = wr.getSessionCookie(); > > //build your http request > wr.addParameter("userName","foo"); > wr.addParameter("userPassword","password"); > > //we don't need to create a new session for each request > wr.setAutomaticSession(false); > wr.addCookie(sessionCookie); > > > } > > > > In you server side code: > > public void testXXX(){ > > > HttpSession mySession = request.getOriginalRequest().getSession(); > > //check if user already authenticated > if(mySession.getAttribute("authentication") != null) && > mySession.getAttribute("authentication").equals("ok"){ > > //run your test > } else { > > String username = (String)request.getParameter("userName"); > String password = (String)request.getParameter("userPassword"); > > //call server side code that does user authentication > > > //in addition get http session and if authentication is OK indicate > this //by inserting new value in session > mySession.setAttribute("authentication","ok"); > > } > > } > > > -----Original Message----- > From: Shay Thompson [mailto:[EMAIL PROTECTED] > Sent: Friday, February 09, 2007 11:07 AM > To: Cactus Users List > Subject: Re: Where do I put code to be executed only once for entire > testclass > > > For JUnit I do the following.. I think it would work with Cactus.. not > positive as I haven't tried it. There's probably something similar if > not. > > public static Test suite() { > > TestSuite suite = new TestSuite(); > suite.addTestSuite(MyTestClass.class); > > TestSetup wrapper = new TestSetup(suite) { > > public void setUp() throws Exception { > init(); > } > > public void tearDown() throws Exception { > cleanUp(); > } > }; > > return wrapper; > } > > Then in your init() you do the authentication. > > > Tejaswini Yardi wrote: >> Hi >> >> I need to put a code to authenticate the user into the application > which >> loads user cache and should be executed only once for the entire > testclass >> instead of executing once for each testcase. Can anyone tell me where > can i >> put this code in my test class. >> Please let me know this as soon as possible. >> > > -- > > If you apply Ohms Law, e=mc2, to the hypotenuse and add to that a > catalyst consisting of a set of struts and a gigahertz, you will > theoretically arrive at an answer yesterday... > > Shay Thompson - Lead Computer Scientist > Adobe Systems, Inc. - Titan Core QE > Voice: x34728 or 612.251.5415 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- View this message in context: http://www.nabble.com/Where-do-I-put-code-to-be-executed-only-once-for-entire-testclass-tf3200579.html#a8898072 Sent from the Cactus - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]