Class AbstractObjectifyJUnit
- java.lang.Object
-
- net.officefloor.nosql.objectify.mock.AbstractObjectifyJUnit
-
- Direct Known Subclasses:
ObjectifyExtension
,ObjectifyRule
public abstract class AbstractObjectifyJUnit extends java.lang.Object
Abstract JUnit functionality for runningObjectify
with localDatastore
.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AbstractObjectifyJUnit.QueryLoader<E>
Loads the entity.static interface
AbstractObjectifyJUnit.ResultLoader<E>
Loads the entity.static class
AbstractObjectifyJUnit.TimeoutException
Indicates timeout on obtaining entity.
-
Constructor Summary
Constructors Constructor Description AbstractObjectifyJUnit()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <E> E
consistent(java.util.function.Supplier<E> getEntity, java.util.function.Function<E,java.lang.Boolean> checkConsistency)
Obtains consistent entity.<E> E
get(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> E
get(java.lang.Class<E> type, long id)
Obtains an entity.<E> E
get(java.lang.Class<E> type, AbstractObjectifyJUnit.ResultLoader<E> loader)
Obtains an entity.com.googlecode.objectify.Objectify
ofy()
Obtains theObjectify
.protected void
setupLocalDataStore()
Sets up the local data store.<E> void
store(E... entities)
Stores the entities.protected void
tearDownLocalDataStore()
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.TimeoutException
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.
- 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.TimeoutException
Obtains 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.TimeoutException
Obtains 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.TimeoutException
Obtains 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.TimeoutException
Obtains 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.TimeoutException
Obtains 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.TimeoutException
Stores 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.Exception
Sets up the local data store.- Throws:
java.lang.Exception
- If fails to setup.
-
tearDownLocalDataStore
protected void tearDownLocalDataStore()
Tears down the local data store.
-
-