Class AbstractObjectifyJUnit
- java.lang.Object
-
- net.officefloor.nosql.objectify.mock.AbstractObjectifyJUnit
-
- Direct Known Subclasses:
ObjectifyExtension,ObjectifyRule
public abstract class AbstractObjectifyJUnit extends java.lang.ObjectAbstract JUnit functionality for runningObjectifywith localDatastore.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractObjectifyJUnit.QueryLoader<E>Loads the entity.static interfaceAbstractObjectifyJUnit.ResultLoader<E>Loads the entity.static classAbstractObjectifyJUnit.TimeoutExceptionIndicates timeout on obtaining entity.
-
Constructor Summary
Constructors Constructor Description AbstractObjectifyJUnit()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <E> Econsistent(java.util.function.Supplier<E> getEntity, java.util.function.Function<E,java.lang.Boolean> checkConsistency)Obtains consistent entity.<E> Eget(java.lang.Class<E> type)Obtains the first entity.<E> java.util.List<E>get(java.lang.Class<E> type, int expectedSize, java.util.function.Supplier<java.util.List<E>> loader)Obtains a list of entities.<E> java.util.List<E>get(java.lang.Class<E> type, int expectedSize, AbstractObjectifyJUnit.QueryLoader<E> loader)Obtains a list of entities.<E> Eget(java.lang.Class<E> type, long id)Obtains an entity.<E> Eget(java.lang.Class<E> type, AbstractObjectifyJUnit.ResultLoader<E> loader)Obtains an entity.com.googlecode.objectify.Objectifyofy()Obtains theObjectify.protected voidsetupLocalDataStore()Sets up the local data store.<E> voidstore(E... entities)Stores the entities.protected voidtearDownLocalDataStore()Tears down the local data store.
-
-
-
Method Detail
-
ofy
public com.googlecode.objectify.Objectify ofy()
Obtains theObjectify.- Returns:
Objectify.
-
get
public <E> E get(java.lang.Class<E> type) throws AbstractObjectifyJUnit.TimeoutExceptionObtains 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.
- Parameters:
type- Type of entity.- Returns:
- First entity.
- Throws:
AbstractObjectifyJUnit.TimeoutException- If waited too long for the entity.
-
get
public <E> E get(java.lang.Class<E> type, long id) throws AbstractObjectifyJUnit.TimeoutExceptionObtains an entity.
Will retry to obtain the entity or timeout.
- 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(java.lang.Class<E> type, AbstractObjectifyJUnit.ResultLoader<E> loader) throws AbstractObjectifyJUnit.TimeoutExceptionObtains an entity.
Will retry to obtain the entity or timeout.
- Parameters:
type- Type of entity.loader-AbstractObjectifyJUnit.QueryLoader.- Returns:
- Entity.
- Throws:
AbstractObjectifyJUnit.TimeoutException- If waited too long for the entity.
-
get
public <E> java.util.List<E> get(java.lang.Class<E> type, int expectedSize, AbstractObjectifyJUnit.QueryLoader<E> loader) throws AbstractObjectifyJUnit.TimeoutExceptionObtains a list of entities.- 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> java.util.List<E> get(java.lang.Class<E> type, int expectedSize, java.util.function.Supplier<java.util.List<E>> loader) throws AbstractObjectifyJUnit.TimeoutExceptionObtains a list of entities.- Parameters:
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(java.util.function.Supplier<E> getEntity, java.util.function.Function<E,java.lang.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
public <E> void store(E... entities) throws AbstractObjectifyJUnit.TimeoutExceptionStores the entities.- Parameters:
entities- Entities to store.- Throws:
AbstractObjectifyJUnit.TimeoutException- If waited too long to store the entities in consistent exising state.
-
setupLocalDataStore
protected void setupLocalDataStore() throws java.lang.ExceptionSets up the local data store.- Throws:
java.lang.Exception- If fails to setup.
-
tearDownLocalDataStore
protected void tearDownLocalDataStore()
Tears down the local data store.
-
-