Awesome, thanks for the help -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Craig McClanahan Sent: Wednesday, February 15, 2006 5:46 PM To: Struts Users Mailing List Subject: Re: Shale Test Framework setting the remote User
On 2/15/06, Miller, John <[EMAIL PROTECTED]> wrote: > > Hi, > > I am new to shale and the concept of mock objects, I am trying to write > a unit test to test a JSF action. The action requires the > getRemoteUser() to return a valid user. Can anyone tell me the proper > way to set up a user in the Mock External context. Thank you in advance. The mock external context calls getRemoteUser() on the mock servlet request object, so that is where we really need to set it. If your unit test case is a subclass of AbstractJsfTestCase or AbstractViewControllerTestCase, the superclass will have set you up an instance variable called "request" for this, so all you need to do is: request.setUserPrincipal(new MyPrincipal("username")); where MyPrincipal is a class that implements the java.security.Principalinterface. (Obviously that's not very friendly ... I'll add a MockPrincipal class that should be available in tonight's nightly build.) Setting this propery will cause both request.getUserPrincipal() and request.getRemoteUser() to return non-null values, which can then be accessed via ExternalContext.getUserPrincipal() and ExternalContext.getRemoteUser() respectively. John Craig NOTICE: This message, including all attachments transmitted with it, is for the use of the addressee only. It may contain proprietary, confidential and/or legally privileged information belonging to Litle & Co. No confidentiality or privilege is waived or lost by any mistransmission. If you are not the intended recipient, you must not, directly or indirectly, use, disclose, distribute, print or copy any part of this message. If you believe you have received this message in error, please delete it and all copies of it from your system and notify the sender immediately by reply e-mail. Thank you. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]