click-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bob Schellink (JIRA)" <>
Subject [jira] Created: (CLK-585) Implement mock support for Principal and Roles
Date Thu, 15 Oct 2009 21:09:31 GMT
Implement mock support for Principal and Roles

                 Key: CLK-585
             Project: Click
          Issue Type: Improvement
          Components: mock
    Affects Versions: 2.1.0
            Reporter: Bob Schellink
            Assignee: Bob Schellink
             Fix For: 2.2.0

Currently there is no way to provide a Principal (user) and Roles for mock tests.

Sven Pfeiffer provided the following impl on the mainlig list which can be added to the Mock


public class AuthenticatedMockRequest extends MockRequest {

   MockPrincipal userPrincipal;

   public AuthenticatedMockRequest(MockPrincipal userPrincipal) {
       this.userPrincipal = userPrincipal;

   public boolean isUserInRole(String name) {
       return userPrincipal.getRoles().contains(name);

   public Principal getUserPrincipal() {
       return userPrincipal;

public class MockPrincipal implements Principal {

   private String name;
   private List<String> roles = new ArrayList<String>();

   public MockPrincipal(String userName) { = userName;

   public MockPrincipal(String userName, List<String> roles) { = userName;
       this.roles = roles;

   public String getName() {
       return name;

   public List<String> getRoles() {
       return roles;

   public void setRoles(String... newRoles) {
       for (String role : newRoles) {

And I added the following lines to my testcase:

MockPrincipal principal = new MockPrincipal("admin");
principal.setRoles("admin", "user");
container.setRequest(new AuthenticatedMockRequest(principal)); 

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message