You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tim Christopher <ti...@gmail.com> on 2005/04/05 12:16:37 UTC

Struts Unit Tests / Alternative getUserPrincipleCall

Hi,

Does anyone know how to code a response to request.getUserPrinciple().getName()?

I've used that call at the start of many of my Actions so that only
relevant content would be displayed, however I'm now trying to run
unit tests I'm getting no where as the User Principle is not in the
request.

Any help appreciated.

Tim Christopher

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts Unit Tests / Alternative getUserPrincipleCall

Posted by Tim Christopher <ti...@gmail.com>.
Just in case anyone else experiences the same problem this is how I solved it:

  TestPrincipal user = new TestPrincipal("tim");
  ServletContext context = getActionServlet().getServletContext();
  HttpServletRequestSimulator hsrs = new HttpServletRequestSimulator(context);
  hsrs.setUserPrincipal(user);

Note: TestPrincipal is a simple Java class that implements Principal
and contains one method called getName().

Tim Christopher

On Apr 5, 2005 11:16 AM, Tim Christopher <ti...@gmail.com> wrote:
> Hi,
> 
> Does anyone know how to code a response to request.getUserPrinciple().getName()?
> 
> I've used that call at the start of many of my Actions so that only
> relevant content would be displayed, however I'm now trying to run
> unit tests I'm getting no where as the User Principle is not in the
> request.
> 
> Any help appreciated.
> 
> Tim Christopher
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org