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