Class UserContext

java.lang.Object
io.ebean.test.UserContext

public class UserContext extends Object
Use in test code when the CurrentUserProvider and/or CurrentTenantProvider were configured by this ebean-test-config plugin.

This is not automatically available. If you wish to use this class in your Tenant testing, you must set the application.properties setting to:

ebean.test.registerTestTenantProvider=true
or application-test.yaml:
  ebean:
    test:
      registerTestTenantProvider: true
. If set to true, the ebean-test-config plugin will check if there is a CurrentUserProvider and if not automatically set one and that provider reads the 'current user' from this UserContext.

  // set the current userId which will be put
  // into 'WhoCreated' and 'WhoModified' properties

	 UserContext.setUserId("U1");

	 // persist bean that has ... a 'WhoModified' property
  Content content = new Content();
  content.setName("hello");

  content.save();

  • Method Details

    • currentUserId

      public static Object currentUserId()
      Return the current user.
    • currentTenantId

      public static Object currentTenantId()
      Return the current tenantId.
    • setUserId

      public static void setUserId(Object userId)
      Set the current userId - this value is put into 'WhoCreated' and 'WhoModified' properties.
    • setTenantId

      public static void setTenantId(Object tenantId)
      Set the current tenantId.
    • reset

      public static void reset()
      Clear both the current userId and tenantId.
    • set

      public static void set(Object userId, String tenantId)
      Set both the current userId and current tenantId.