Package com.avoka.tm.test
Class MockPrincipal
java.lang.Object
com.avoka.tm.test.MockPrincipal
- All Implemented Interfaces:
Principal
Mock implementation of a user
principal
.
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
ConstructorDescriptionConstructs 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
-
Constructor Details
-
MockPrincipal
public MockPrincipal()Constructs a new MockPrincipal instance. -
MockPrincipal
Constructs a new MockPrincipal instance for the given name.- Parameters:
name
- the name of the principal
-
MockPrincipal
Constructs a new MockPrincipal instance for the given name and roles.- Parameters:
name
- the name of the principalroles
- the principal roles
-
MockPrincipal
Constructs a new MockPrincipal instance for the given name and roles.- Parameters:
name
- the name of the principalroles
- the principal roles
-
-
Method Details
-
getName
Returns the name of this principal. -
setName
Set the name of this principal.- Parameters:
name
- the name of the princpal
-
getRoles
Returns the roles of this principal.- Returns:
- the roles of this principal.
-
setRoles
Sets the roles of this principal.- Parameters:
roles
- set the roles of this principal.
-
addRoles
Add the roles of this principal.- Parameters:
roles
- set the roles of this principal.
-