Class TemporaryUser

java.lang.Object
org.junit.rules.ExternalResource
com.adobe.cq.testing.junit.rules.TemporaryUser
All Implemented Interfaces:
org.junit.rules.TestRule

public class TemporaryUser extends org.junit.rules.ExternalResource
TemporaryUser creates a user and deletes it at the end of the test. Whether the delete is successful or not is not checked. The create operation is retried until a timeout is reached. The total wait time in the before method can be up to 30s.
  • Constructor Details

    • TemporaryUser

      public TemporaryUser(Supplier<org.apache.sling.testing.clients.SlingClient> creatorSupplier, String... groups)
      Instantiate a new TemporaryUser rule, to be used with the @Rule annotation.
      Parameters:
      creatorSupplier - supplier for the client used to create the temporary user
      groups - groups to which the temporary user is assigned
  • Method Details

    • getClient

      public CQClient getClient()
      Returns:
      the CQClient matching the temporary user
    • getClientSupplier

      public Supplier<org.apache.sling.testing.clients.SlingClient> getClientSupplier()
      Returns:
      a SlingClient Supplier matching the temporary user
    • before

      protected void before() throws Throwable
      Overrides:
      before in class org.junit.rules.ExternalResource
      Throws:
      Throwable
    • after

      protected void after()
      Overrides:
      after in class org.junit.rules.ExternalResource
    • generateName

      protected String generateName()
      Generate a unique name for the user. Can be overridden if anther pattern is needed.
      Returns:
      a unique username
    • generatePassword

      protected String generatePassword()
      Generate a unique password for the user. Can be overridden if another pattern is needed.
      Returns:
      a unique, random password
    • deleteUsers

      protected void deleteUsers()
      Delete all the created users. The delete operation is not retried and exceptions are ignored.