public class

MockOfBizDelegator

extends Object
implements OfBizDelegator
java.lang.Object
   ↳ com.atlassian.jira.mock.ofbiz.MockOfBizDelegator

Class Overview

Provides a mock delegator with an in-memory database.

The constructor accepts two lists. The genericValues list can be used to pre-populate the in-memory database with GenericValue objects required for the test. It represents the initial state of the database.

The expectedGenericValues list represents the final state of the database. It can be used to verify the final contents of the in-memory database upon test completion.

It is possible to verify the final contents of the in-memory database with the expectedGenericValues list through the methods verify() (verify objects in expectedGenericValues exist in database) and verifyAll() (verify objects in expectedGenericValues and only those objects exist in database).

Summary

Constants
int STARTING_ID
[Expand]
Inherited Constants
From interface com.atlassian.jira.ofbiz.OfBizDelegator
Fields
public static final Comparator<GenericValue> GV_ENTITY_NAME_AND_ID_COMPARATOR
Public Constructors
MockOfBizDelegator()
MockOfBizDelegator(List<? extends GenericValue> genericValues, List<? extends GenericValue> expectedGenericValues)
Creates new instance of MockOfBizDelegator.
MockOfBizDelegator(DelegatorInterface delegatorInterface)
Public Methods
void addRelatedMap(String relationName, GenericValue gv, List<GenericValue> listToReturn)
void addRelatedMap(String relationName, GenericValue gv, GenericValue... gvsToReturns)
int bulkCopyColumnValuesByAnd(String entityName, Map updateColumns, Map criteria)
This can be used to perform an update on the entityName of all the rows identified by AND criteria of the fields specified by the criteria map.
int bulkUpdateByAnd(String entityName, Map<String, ?> updateValues, Map<String, ?> criteria)
This can be used to perform an update on the entityName of all the rows identified by AND criteria of the fields specified by the criteria map.
int bulkUpdateByPrimaryKey(String entityName, Map<String, ?> updateValues, List<Long> keys)
This can be used to perform an update on the entityName of all the rows identified by the keys with the values stored in the updateValues.
synchronized GenericValue createValue(String entity, Map<StringObject> params)
Creates a new GenericValue, and persists it.
void createValue(GenericValue entity)
void createValueWithoutId(String entityName, Map<StringObject> fields)
Creates a new GenericValue, and persists it without trying to automatically populate the ID column.
synchronized List<GenericValue> findAll(String s)
List<GenericValue> findAll(String s, List<String> sortOrder)
List<GenericValue> findByAnd(String s, List<EntityCondition> expressions)
List<GenericValue> findByAnd(String s, Map<String, ?> map, List<String> orderClause)
List<GenericValue> findByAnd(String s, Map<String, ?> map)
Finds GenericValue records by all of the specified fields (ie: combined using AND).
List<GenericValue> findByCondition(String entityName, EntityCondition entityCondition, Collection<String> fieldsToSelect)
Finds GenericValues by the conditions specified in the EntityCondition object with no specified order.
List<GenericValue> findByCondition(String entityName, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy)
Finds GenericValues by the conditions specified in the EntityCondition object.
List<GenericValue> findByField(String entityName, String fieldName, Object fieldValue)
Finds GenericValue records by the specified field value.
List<GenericValue> findByField(String entityName, String fieldName, Object fieldValue, String orderBy)
Finds GenericValue records by the specified field value.
GenericValue findById(String entityName, Long id)
Find a Generic Entity by its numeric ID.
List<GenericValue> findByLike(String entityName, Map<String, ?> map)
List<GenericValue> findByLike(String entityName, Map<String, ?> map, List<String> orderBy)
List<GenericValue> findByOr(String entityName, List<? extends EntityCondition> expressions, List<String> orderBy)
GenericValue findByPrimaryKey(String entityName, Long id)
Find a Generic Entity by its single numeric Primary Key.
GenericValue findByPrimaryKey(String s, Map<String, ?> map)
Find a Generic Entity by its Primary Key.
OfBizListIterator findListIteratorByCondition(String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions entityFindOptions)
Returns a new OfBizListIterator.
OfBizListIterator findListIteratorByCondition(String entityType, EntityCondition condition)
Returns a new OfBizListIterator.
long getCount(String entityName)
Runs a COUNT * query over the given entity.
long getCountByAnd(String entityName, Map<String, ?> fields)
Runs a COUNT * query over the given entity with some WHERE conditions.
DelegatorInterface getDelegatorInterface()
Returns the underlying raw Entity Engine DelegatorInterface.
ModelReader getModelReader()
Returns a model reader that can be used to retrieve all the different entitynames configured in the entitymodel.
List<GenericValue> getRelated(String relationName, GenericValue gv, List<String> orderBy)
List<GenericValue> getRelated(String relationName, GenericValue gv)
GenericValue makeValue(String entity)
Creates an Entity in the form of a GenericValue without persisting it.
GenericValue makeValue(String entityName, Map<StringObject> fields)
Creates an Entity in the form of a GenericValue without persisting it.
void refreshSequencer()
Refreshes the sequencer that is used to retrieve unique IDs in the database.
synchronized void removeAll(List<GenericValue> genericValues)
synchronized int removeByAnd(String s, Map<String, ?> map)
int removeByCondition(String entityName, EntityCondition condition)
int removeById(String entityName, Long id)
Remove the given entity from the DB.
int removeByOr(String entityName, String entityId, List<Long> ids)
This can be used to remove rows for a given entity based on entityName and where entityId
boolean removeRelated(String relationName, GenericValue schemeGv)
Remove all the entities related to the passed generic value via the passed relationship name.
int removeValue(GenericValue value)
synchronized void setGenericValues(List<? extends GenericValue> genericValues)
void setModelReader(ModelReader modelReader)
void store(GenericValue gv)
synchronized void storeAll(List<GenericValue> genericValues)
String toString()
synchronized List<GenericValue> transform(String entityName, EntityCondition entityCondition, List<String> orderBy, String lockField, Transformation transformation)
Applies the given transformation to any entities matching the given condition.
synchronized GenericValue transformOne(String entityName, EntityCondition entityCondition, String lockField, Transformation transformation)
Applies the given transformation to the entity matching the given condition.
void verify()
Look through all the fields that are expected, and checks that they have the correct values.
void verify(List<GenericValue> expectedGenericValues)
Look through all the fields that are expected, and checks that they have the correct values.
void verify(GenericValue... expectedGenericValues)
void verifyAll()
Look through all the fields that are expected, and checks that they have the correct values.
void verifyAll(List<GenericValue> expectedGenericValues)
Look through all the fields that are expected, and checks that they have the correct values.
void verifyAll(GenericValue... expectedGenericValues)
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.jira.ofbiz.OfBizDelegator

Constants

public static final int STARTING_ID

Constant Value: 1000 (0x000003e8)

Fields

public static final Comparator<GenericValue> GV_ENTITY_NAME_AND_ID_COMPARATOR

Public Constructors

public MockOfBizDelegator ()

public MockOfBizDelegator (List<? extends GenericValue> genericValues, List<? extends GenericValue> expectedGenericValues)

Creates new instance of MockOfBizDelegator. The genericValues list can be used to pre-populate the in-memory database with GenericValue objects required for the test. It represents the initial state of the database.

The expectedGenericValues list represents a list objects that should exist in the final state of the database. It can be used to verify the final contents of the in-memory database upon test completion.

Parameters
genericValues a list of GenericValue objects that represents the initial state of the database
expectedGenericValues a list of GenericValue objects that represents the objects that should exist in the final state of the database - it will be a complete list for verifyAll() verification and a subset for verify() method. It may help readability to specify this information directly in the verify(List) or verifyAll(List) instead of providing it here.

public MockOfBizDelegator (DelegatorInterface delegatorInterface)

Public Methods

public void addRelatedMap (String relationName, GenericValue gv, List<GenericValue> listToReturn)

public void addRelatedMap (String relationName, GenericValue gv, GenericValue... gvsToReturns)

public int bulkCopyColumnValuesByAnd (String entityName, Map updateColumns, Map criteria)

This can be used to perform an update on the entityName of all the rows identified by AND criteria of the fields specified by the criteria map.

Parameters
entityName table na,e
updateColumns map of update to - update from columns
criteria map of column names and their values that will create WHERE clause
Returns
  • the number of rows updated

public int bulkUpdateByAnd (String entityName, Map<String, ?> updateValues, Map<String, ?> criteria)

This can be used to perform an update on the entityName of all the rows identified by AND criteria of the fields specified by the criteria map.

Parameters
entityName identifies the table to perform the update on.
updateValues is a map where the key is the fieldName and the value is the value to update the column to.
criteria map of field to value mapping that will be used to generate the where clause of the update SQL statement. Multiple entries in the map are joined using the AND operator.
Returns
  • the number of rows updated

public int bulkUpdateByPrimaryKey (String entityName, Map<String, ?> updateValues, List<Long> keys)

This can be used to perform an update on the entityName of all the rows identified by the keys with the values stored in the updateValues.

Parameters
entityName identifies the table to perform the update on.
updateValues is a map where the key is the fieldName and the value is the value to update the column to.
keys is a list of Long values that represent the primary keys of the the where clause.
Returns
  • the number of rows updated

public synchronized GenericValue createValue (String entity, Map<StringObject> params)

Creates a new GenericValue, and persists it.

If there is no "id" in the field values, one is created using the entity sequence.

Parameters
entity the entity name.
params field values
Returns
  • The new GenericValue.

public void createValue (GenericValue entity)

public void createValueWithoutId (String entityName, Map<StringObject> fields)

Creates a new GenericValue, and persists it without trying to automatically populate the ID column.

Use this for entities that don't have a numeric ID column.

Parameters
entityName the entity name.
fields field values

public synchronized List<GenericValue> findAll (String s)

public List<GenericValue> findAll (String s, List<String> sortOrder)

public List<GenericValue> findByAnd (String s, List<EntityCondition> expressions)

public List<GenericValue> findByAnd (String s, Map<String, ?> map, List<String> orderClause)

public List<GenericValue> findByAnd (String s, Map<String, ?> map)

Finds GenericValue records by all of the specified fields (ie: combined using AND).

Parameters
s The Name of the Entity as defined in the entity XML file
map The fields of the named entity to query by with their corresponding values
Returns
  • List of GenericValue instances that match the query

public List<GenericValue> findByCondition (String entityName, EntityCondition entityCondition, Collection<String> fieldsToSelect)

Finds GenericValues by the conditions specified in the EntityCondition object with no specified order.

Convenience method for calling findByCondition(String, EntityCondition, Collection, List) with an empty orderBy list.

Parameters
entityName The Name of the Entity as defined in the entity model XML file
entityCondition The EntityCondition object that specifies how to constrain this query
fieldsToSelect The fields of the named entity to get from the database; if empty or null all fields will be retreived
Returns
  • List of GenericValue objects representing the search results

public List<GenericValue> findByCondition (String entityName, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy)

Finds GenericValues by the conditions specified in the EntityCondition object.

Parameters
entityName The Name of the Entity as defined in the entity model XML file
entityCondition The EntityCondition object that specifies how to constrain this query
fieldsToSelect The fields of the named entity to get from the database; if empty or null all fields will be retreived
orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
Returns
  • List of GenericValue objects representing the search results

public List<GenericValue> findByField (String entityName, String fieldName, Object fieldValue)

Finds GenericValue records by the specified field value.

Parameters
entityName The Name of the Entity as defined in the entity XML file
fieldName The field to do filtering by.
fieldValue The desired value for the filtering field.
Returns
  • List of GenericValue instances that match the query

public List<GenericValue> findByField (String entityName, String fieldName, Object fieldValue, String orderBy)

Finds GenericValue records by the specified field value.

Parameters
entityName The Name of the Entity as defined in the entity XML file
fieldName The field to do filtering by.
fieldValue The desired value for the filtering field.
orderBy Single field to order by.
Returns
  • List of GenericValue instances that match the query

public GenericValue findById (String entityName, Long id)

Find a Generic Entity by its numeric ID.

This method is a synonym for findByPrimaryKey(String, Long)

Parameters
entityName The Name of the Entity as defined in the entity XML file
id The numeric "id" field value that is the primary key of this entity.
Returns
  • The GenericValue corresponding to the ID

public List<GenericValue> findByLike (String entityName, Map<String, ?> map)

public List<GenericValue> findByLike (String entityName, Map<String, ?> map, List<String> orderBy)

public List<GenericValue> findByOr (String entityName, List<? extends EntityCondition> expressions, List<String> orderBy)

public GenericValue findByPrimaryKey (String entityName, Long id)

Find a Generic Entity by its single numeric Primary Key.

This method is a convenience for entities with a numeric primary key on single field called "id". This is the case for most JIRA entities.

Parameters
entityName The Name of the Entity as defined in the entity XML file
id The numeric "id" field value that is the primary key of this entity.
Returns
  • The GenericValue corresponding to the primary key

public GenericValue findByPrimaryKey (String s, Map<String, ?> map)

Find a Generic Entity by its Primary Key.

Parameters
s The Name of the Entity as defined in the entity XML file
map The field/value pairs of the primary key (in JIRA, mostly just a single field "id")
Returns
  • The GenericValue corresponding to the primary key

public OfBizListIterator findListIteratorByCondition (String entityName, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions entityFindOptions)

Returns a new OfBizListIterator.

IMPORTANT: the returned iterator needs to be properly closed in a finally block to avoid connection leaks.

public OfBizListIterator findListIteratorByCondition (String entityType, EntityCondition condition)

Returns a new OfBizListIterator.

IMPORTANT: the returned iterator needs to be properly closed in a finally block to avoid connection leaks.

public long getCount (String entityName)

Runs a COUNT * query over the given entity.

Ensure that there is a view-entity defined in entitymodel.xml and entitygroup.xml for the entity you are calling this method with, and that the view-entity is named correctly! The view-entity must be named the name of the normal entity with "Count" appended. For example, for the "Issue" entity, the view-entity must be called "IssueCount". Otherwise an exception will be thrown.

For JIRA core developers, see EntityEngine's Select factory for a more flexible alternative, including the ability to terminate queries with .count() instead of .asList() to accomplish a count without creating a special view entity for that purpose. For add-on developers, this can only be done directly through the lower level DelegatorInterface at this time.

Parameters
entityName entity name
Returns
  • count

public long getCountByAnd (String entityName, Map<String, ?> fields)

Runs a COUNT * query over the given entity with some WHERE conditions.

In addition to the restrictions given for getCount(String), the view-entity will need to define any columns that you wish to use in the where clause.

Parameters
entityName entity name
fields The fields of the named entity to query by with their corresponding values
Returns
  • count

public DelegatorInterface getDelegatorInterface ()

Returns the underlying raw Entity Engine DelegatorInterface.

Returns
  • the underlying raw Entity Engine DelegatorInterface.

public ModelReader getModelReader ()

Returns a model reader that can be used to retrieve all the different entitynames configured in the entitymodel.

Returns
  • a ModelReader

public List<GenericValue> getRelated (String relationName, GenericValue gv, List<String> orderBy)

public List<GenericValue> getRelated (String relationName, GenericValue gv)

public GenericValue makeValue (String entity)

Creates an Entity in the form of a GenericValue without persisting it.

Parameters
entity the entity name.
Returns
  • The new GenericValue.

public GenericValue makeValue (String entityName, Map<StringObject> fields)

Creates an Entity in the form of a GenericValue without persisting it.

Parameters
entityName the entity name.
fields initial field values
Returns
  • The new GenericValue.

public void refreshSequencer ()

Refreshes the sequencer that is used to retrieve unique IDs in the database.

public synchronized void removeAll (List<GenericValue> genericValues)

public synchronized int removeByAnd (String s, Map<String, ?> map)

public int removeByCondition (String entityName, EntityCondition condition)

public int removeById (String entityName, Long id)

Remove the given entity from the DB.

Parameters
entityName the entity type (ie TABLE)
id the id of the row to delete.
Returns
  • number of rows effected by this operation

public int removeByOr (String entityName, String entityId, List<Long> ids)

This can be used to remove rows for a given entity based on entityName and where entityId

Parameters
entityName identifies the table to perform the remove on.
entityId the Ofbiz fieldName to be used for the identifier, eg WHERE fieldName IN (...). Must be the same case as that found in entitymodel.xml.
ids a list of entity IDs of the rows to be removed
Returns
  • number of rows removed

public boolean removeRelated (String relationName, GenericValue schemeGv)

Remove all the entities related to the passed generic value via the passed relationship name.

Parameters
relationName the name of the relationship.
schemeGv the gv at the start of the relationship.
Returns
  • true the database was changed, false otherwise.

public int removeValue (GenericValue value)

public synchronized void setGenericValues (List<? extends GenericValue> genericValues)

public void setModelReader (ModelReader modelReader)

public void store (GenericValue gv)

public synchronized void storeAll (List<GenericValue> genericValues)

public String toString ()

public synchronized List<GenericValue> transform (String entityName, EntityCondition entityCondition, List<String> orderBy, String lockField, Transformation transformation)

Applies the given transformation to any entities matching the given condition.

Parameters
entityName the type of entity to transform (required)
entityCondition the condition that selects the entities to transform (null means transform all)
orderBy the order in which the entities should be selected for updating (null means no ordering)
lockField the entity field to use for optimistic locking; the value of this field will be read between the SELECT and the UPDATE to determine whether another process has updated one of the target records in the meantime; if so, the transformation will be reapplied and another UPDATE attempted
transformation the transformation to apply (required)
Returns
  • the transformed entities in the order they were selected (never null)

public synchronized GenericValue transformOne (String entityName, EntityCondition entityCondition, String lockField, Transformation transformation)

Applies the given transformation to the entity matching the given condition.

Parameters
entityName the type of entity to transform (required)
entityCondition the condition that selects the entity to transform (must select one entity)
lockField the entity field to use for optimistic locking; the value of this field will be read between the SELECT and the UPDATE to determine whether another process has updated one of the target records in the meantime; if so, the transformation will be reapplied and another UPDATE attempted
transformation the transformation to apply (required)
Returns
  • the transformed entity (never null)

public void verify ()

Look through all the fields that are expected, and checks that they have the correct values. Ignores values that are not in the expected GenericValue.

Throws
AssertionFailedError if does not match

public void verify (List<GenericValue> expectedGenericValues)

Look through all the fields that are expected, and checks that they have the correct values. Ignores values that are not in the expected GenericValue.

Parameters
expectedGenericValues overrides anything set during construction
Throws
AssertionFailedError if does not match

public void verify (GenericValue... expectedGenericValues)

public void verifyAll ()

Look through all the fields that are expected, and checks that they have the correct values.

Throws
AssertionFailedError if does not match

public void verifyAll (List<GenericValue> expectedGenericValues)

Look through all the fields that are expected, and checks that they have the correct values.

Throws
AssertionFailedError if does not match

public void verifyAll (GenericValue... expectedGenericValues)