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 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 Details

    • 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 principal
      roles - the principal roles
    • MockPrincipal

      public MockPrincipal(String name, String... roles)
      Constructs a new MockPrincipal instance for the given name and roles.
      Parameters:
      name - the name of the principal
      roles - the principal roles
  • Method Details

    • getName

      public String getName()
      Returns the name of this principal.
      Specified by:
      getName in interface Principal
      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.