Package com.avoka.tm.test
Class MockPrincipal
- java.lang.Object
-
- com.avoka.tm.test.MockPrincipal
-
- All Implemented Interfaces:
Principal
public class MockPrincipal extends Object implements Principal
Mock implementation of a userprincipal. This class also provides convenient methods for specifying the user principal roles. Example usage with MockContext:MockContext mockContext = MockContext.initContext(); // Create a new user principal with the roles "user" and "manager" MockPrincipal principal = new MockPrincipal("Bob", "user", "manager"); // Set the user principal on the request object mockContext.getMockRequest().setUserPrincipal(principal);Example usage with MockContainer:MockContainer container = new MockContainer("c:/dev/myapp/web"); // Create a new user principal with the roles "user" and "manager" MockPrincipal principal = new MockPrincipal("Bob", "user", "manager"); // Set the user principal on the request object container.getRequest().setUserPrincipal(principal);- Since:
- 17.10.0
-
-
Constructor Summary
Constructors Constructor Description MockPrincipal()Constructs a new MockPrincipal instance.MockPrincipal(String name)Constructs a new MockPrincipal instance for the given name.MockPrincipal(String name, String... roles)Constructs a new MockPrincipal instance for the given name and roles.MockPrincipal(String name, Set<String> roles)Constructs a new MockPrincipal instance for the given name and roles.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRoles(String... roles)Add the roles of this principal.StringgetName()Returns the name of this principal.Set<String>getRoles()Returns the roles of this principal.voidsetName(String name)Set the name of this principal.voidsetRoles(Set<String> roles)Sets the roles of this principal.
-
-
-
Constructor Detail
-
MockPrincipal
public MockPrincipal()
Constructs a new MockPrincipal instance.
-
MockPrincipal
public MockPrincipal(String name)
Constructs a new MockPrincipal instance for the given name.- Parameters:
name- the name of the principal
-
MockPrincipal
public MockPrincipal(String name, Set<String> roles)
Constructs a new MockPrincipal instance for the given name and roles.- Parameters:
name- the name of the principalroles- the principal roles
-
-
Method Detail
-
getName
public String getName()
Returns the name of this principal.
-
setName
public void setName(String name)
Set the name of this principal.- Parameters:
name- the name of the princpal
-
getRoles
public Set<String> getRoles()
Returns the roles of this principal.- Returns:
- the roles of this principal.
-
setRoles
public void setRoles(Set<String> roles)
Sets the roles of this principal.- Parameters:
roles- set the roles of this principal.
-
addRoles
public void addRoles(String... roles)
Add the roles of this principal.- Parameters:
roles- set the roles of this principal.
-
-