Package com.adobe.cq.testing.junit.rules
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 thebefore
method can be up to 30s.
-
-
Constructor Summary
Constructors Constructor Description TemporaryUser(Supplier<org.apache.sling.testing.clients.SlingClient> creatorSupplier, String... groups)
Instantiate a new TemporaryUser rule, to be used with the@Rule
annotation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
after()
protected void
before()
protected void
deleteUsers()
Delete all the created users.protected String
generateName()
Generate a unique name for the user.protected String
generatePassword()
Generate a unique password for the user.CQClient
getClient()
Supplier<org.apache.sling.testing.clients.SlingClient>
getClientSupplier()
-
-
-
Constructor Detail
-
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 usergroups
- groups to which the temporary user is assigned
-
-
Method Detail
-
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 classorg.junit.rules.ExternalResource
- Throws:
Throwable
-
after
protected void after()
- Overrides:
after
in classorg.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.
-
-