Class AbstractObjectifyJUnit
java.lang.Object
net.officefloor.nosql.objectify.mock.AbstractObjectifyJUnit
- Direct Known Subclasses:
ObjectifyExtension,ObjectifyRule
Abstract JUnit functionality for running
Objectify with local
Datastore.- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceLoads the entity.static interfaceLoads the entity.static classIndicates timeout on obtaining entity. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<E> Econsistent(Supplier<E> getEntity, Function<E, Boolean> checkConsistency) Obtains consistent entity.<E> EObtains the first entity.<E> List<E>Obtains a list of entities.<E> List<E>get(Class<E> type, int expectedSize, AbstractObjectifyJUnit.QueryLoader<E> loader) Obtains a list of entities.<E> EObtains an entity.<E> Eget(Class<E> type, AbstractObjectifyJUnit.ResultLoader<E> loader) Obtains an entity.com.googlecode.objectify.Objectifyofy()Obtains theObjectify.protected voidSets up the local data store.<E> voidstore(E... entities) Stores the entities.protected voidTears down the local data store.
-
Constructor Details
-
AbstractObjectifyJUnit
public AbstractObjectifyJUnit()
-
-
Method Details
-
ofy
public com.googlecode.objectify.Objectify ofy()Obtains theObjectify.- Returns:
Objectify.
-
get
Obtains the first entity.
Note this obtains arbitrary entity. Typically this is useful in tests when only a single instance of the entity exists. However, if more than one entity exists, this can cause indeterminate test failures.
Will retry to obtain the entity or timeout.
- Type Parameters:
E- Entity type.- Parameters:
type- Type of entity.- Returns:
- First entity.
- Throws:
AbstractObjectifyJUnit.TimeoutException- If waited too long for the entity.
-
get
Obtains an entity.
Will retry to obtain the entity or timeout.
- Type Parameters:
E- Entity type.- Parameters:
type- Type of entity.id- Id of entity.- Returns:
- Entity.
- Throws:
AbstractObjectifyJUnit.TimeoutException- If waited too long for the entity.
-
get
public <E> E get(Class<E> type, AbstractObjectifyJUnit.ResultLoader<E> loader) throws AbstractObjectifyJUnit.TimeoutException Obtains an entity.
Will retry to obtain the entity or timeout.
- Type Parameters:
E- Entity type.- Parameters:
type- Type of entity.loader-AbstractObjectifyJUnit.QueryLoader.- Returns:
- Entity.
- Throws:
AbstractObjectifyJUnit.TimeoutException- If waited too long for the entity.
-
get
public <E> List<E> get(Class<E> type, int expectedSize, AbstractObjectifyJUnit.QueryLoader<E> loader) throws AbstractObjectifyJUnit.TimeoutException Obtains a list of entities.- Type Parameters:
E- Entity type.- Parameters:
type- Type of entity.expectedSize- Expected list size.loader-AbstractObjectifyJUnit.QueryLoader.- Returns:
- List of entity.
- Throws:
AbstractObjectifyJUnit.TimeoutException- If waited too long the list of entities.
-
get
public <E> List<E> get(Class<E> type, int expectedSize, Supplier<List<E>> loader) throws AbstractObjectifyJUnit.TimeoutException Obtains a list of entities.- Type Parameters:
E- Entity type.- Parameters:
type- Type of entity.expectedSize- Expected list size.loader- Loads the entities.- Returns:
- List of entities.
- Throws:
AbstractObjectifyJUnit.TimeoutException- If waited too long the list of entities.
-
consistent
public <E> E consistent(Supplier<E> getEntity, Function<E, Boolean> checkConsistency) throws AbstractObjectifyJUnit.TimeoutExceptionObtains consistent entity.- Type Parameters:
E- Type of entity.- Parameters:
getEntity- Obtains the entity.checkConsistency- Checks the consistency of the entity.- Returns:
- Entity (in consistent state).
- Throws:
AbstractObjectifyJUnit.TimeoutException- If times out waiting to become consistent.
-
store
Stores the entities.- Type Parameters:
E- Entity type.- Parameters:
entities- Entities to store.- Throws:
AbstractObjectifyJUnit.TimeoutException- If waited too long to store the entities in consistent exising state.
-
setupLocalDataStore
Sets up the local data store.- Throws:
Exception- If fails to setup.
-
tearDownLocalDataStore
protected void tearDownLocalDataStore()Tears down the local data store.
-