Package io.ebean.test

Class UserContext


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

    That is, the ebean-test-config plugin will check if there ia 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 Detail

      • 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.