#16 Allow multiple roles in HttpServletRequestSimulator

open
nobody
None
5
2005-11-21
2005-11-21
Larry Meadors
No

I needed to have multiple roles for a test.

The existing role mechanism only allows one.

This change adds a Map to store role names, and
preserves the existing behavior by adding the following
methods:

public void addUserRole(String role)
public void removeUserRole(String role)
public void addUserRole(String[] role)
public void addUserRole(Map role)

The setUserRole method does the same thing it used to
do, but uses the map instead:

public void setUserRole(String role) {
userRoleMap.clear();
addUserRole(role);
}

The isUserInRole method then uses the map to determine
role membership:

public boolean isUserInRole(String s){
return userRoleMap.containsKey(s);
}

Larry

Discussion

  • Larry Meadors
    Larry Meadors
    2005-11-21

    Logged In: YES
    user_id=245903

    Oops, forgot the unit test...

    public void testIsUserInRole() {
    request.setUserRole("role1");
    assertTrue(request.isUserInRole("role1"));

    request.setUserRole("role2");
    assertFalse(request.isUserInRole("role1"));
    assertTrue(request.isUserInRole("role2"));

    request.addUserRole("role1");
    assertTrue(request.isUserInRole("role1"));

    request.removeUserRole("role1");
    assertFalse(request.isUserInRole("role1"));

    request.removeUserRole("role2");
    // make sure it does not fail removing
    // a role that does not exist
    request.removeUserRole("role2");
    assertFalse(request.isUserInRole("role2"));
    }