|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.atlassian.jira.mock.ofbiz.MockOfBizDelegator
public class MockOfBizDelegator
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 methodsverify()
(verify objects in expectedGenericValues exist in database) and verifyAll()
(verify
objects in expectedGenericValues and only those objects exist in database).
Field Summary | |
---|---|
static int |
STARTING_ID
|
Fields inherited from interface com.atlassian.jira.ofbiz.OfBizDelegator |
---|
ISSUE_LINK, ISSUE_LINK_TYPE, PROJECT_COMPONENT, VERSION |
Constructor Summary | |
---|---|
MockOfBizDelegator()
|
|
MockOfBizDelegator(org.ofbiz.core.entity.DelegatorInterface delegatorInterface)
|
|
MockOfBizDelegator(List<? extends org.ofbiz.core.entity.GenericValue> genericValues,
List<? extends org.ofbiz.core.entity.GenericValue> expectedGenericValues)
Creates new instance of MockOfBizDelegator. |
Method Summary | |
---|---|
void |
addRelatedMap(String relationName,
org.ofbiz.core.entity.GenericValue gv,
org.ofbiz.core.entity.GenericValue... gvsToReturns)
|
void |
addRelatedMap(String relationName,
org.ofbiz.core.entity.GenericValue gv,
List<org.ofbiz.core.entity.GenericValue> listToReturn)
|
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. |
org.ofbiz.core.entity.GenericValue |
createValue(String entity,
Map<String,Object> params)
Creates a new GenericValue, and persists it. |
List<org.ofbiz.core.entity.GenericValue> |
findAll(String s)
|
List<org.ofbiz.core.entity.GenericValue> |
findAll(String s,
List<String> sortOrder)
|
List<org.ofbiz.core.entity.GenericValue> |
findByAnd(String s,
List<org.ofbiz.core.entity.EntityCondition> expressions)
|
List<org.ofbiz.core.entity.GenericValue> |
findByAnd(String s,
Map<String,?> map)
Finds GenericValue records by all of the specified fields (ie: combined using AND). |
List<org.ofbiz.core.entity.GenericValue> |
findByAnd(String s,
Map<String,?> map,
List<String> orderClause)
|
List<org.ofbiz.core.entity.GenericValue> |
findByCondition(String entityName,
org.ofbiz.core.entity.EntityCondition entityCondition,
Collection<String> fieldsToSelect)
Finds GenericValues by the conditions specified in the EntityCondition object with no specified order. |
List<org.ofbiz.core.entity.GenericValue> |
findByCondition(String entityName,
org.ofbiz.core.entity.EntityCondition entityCondition,
Collection<String> fieldsToSelect,
List<String> orderBy)
Finds GenericValues by the conditions specified in the EntityCondition object. |
List<org.ofbiz.core.entity.GenericValue> |
findByField(String entityName,
String fieldName,
Object fieldValue)
Finds GenericValue records by the specified field value. |
List<org.ofbiz.core.entity.GenericValue> |
findByField(String entityName,
String fieldName,
Object fieldValue,
String orderBy)
Finds GenericValue records by the specified field value. |
org.ofbiz.core.entity.GenericValue |
findById(String entityName,
Long id)
Find a Generic Entity by its numeric ID. |
List<org.ofbiz.core.entity.GenericValue> |
findByLike(String entityName,
Map<String,?> map)
|
List<org.ofbiz.core.entity.GenericValue> |
findByLike(String entityName,
Map<String,?> map,
List<String> orderBy)
|
List<org.ofbiz.core.entity.GenericValue> |
findByOr(String entityName,
List<? extends org.ofbiz.core.entity.EntityCondition> expressions,
List<String> orderBy)
|
org.ofbiz.core.entity.GenericValue |
findByPrimaryKey(String entityName,
Long id)
Find a Generic Entity by its single numeric Primary Key. |
org.ofbiz.core.entity.GenericValue |
findByPrimaryKey(String s,
Map<String,?> map)
Find a Generic Entity by its Primary Key. |
OfBizListIterator |
findListIteratorByCondition(String entityType,
org.ofbiz.core.entity.EntityCondition condition)
Returns a new OfBizListIterator. |
OfBizListIterator |
findListIteratorByCondition(String entityName,
org.ofbiz.core.entity.EntityCondition whereEntityCondition,
org.ofbiz.core.entity.EntityCondition havingEntityCondition,
Collection<String> fieldsToSelect,
List<String> orderBy,
org.ofbiz.core.entity.EntityFindOptions entityFindOptions)
Returns a new OfBizListIterator. |
long |
getCount(String entityName)
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. |
long |
getCountByAnd(String entityName,
Map<String,?> fields)
Runs a "COUNT *" query over the given entity with some WHERE conditions. |
org.ofbiz.core.entity.DelegatorInterface |
getDelegatorInterface()
Returns the underlying raw Entity Engine DelegatorInterface. |
org.ofbiz.core.entity.model.ModelReader |
getModelReader()
Returns a model reader that can be used to retrieve all the different entitynames configured in the entitymodel. |
List<org.ofbiz.core.entity.GenericValue> |
getRelated(String relationName,
org.ofbiz.core.entity.GenericValue gv)
|
List<org.ofbiz.core.entity.GenericValue> |
getRelated(String relationName,
org.ofbiz.core.entity.GenericValue gv,
List<String> orderBy)
|
org.ofbiz.core.entity.EntityCondition |
lastEntityCondition()
Returns the most recent EntityCondition passed to findByCondition(java.lang.String, org.ofbiz.core.entity.EntityCondition, java.util.Collection , to allow assertions. |
List<String> |
lastOrderBy()
Returns the most recent list of "order by" fields passed to findByCondition(java.lang.String, org.ofbiz.core.entity.EntityCondition, java.util.Collection , to allow assertions. |
org.ofbiz.core.entity.GenericValue |
makeValue(String entity)
Creates an Entity in the form of a GenericValue without persisting it. |
org.ofbiz.core.entity.GenericValue |
makeValue(String entityName,
Map<String,Object> 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. |
void |
removeAll(List genericValues)
|
int |
removeByAnd(String s,
Map<String,?> map)
|
int |
removeByCondition(String entityName,
org.ofbiz.core.entity.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,
org.ofbiz.core.entity.GenericValue schemeGv)
Remove all the entities related to the passed generic value via the passed relationship name. |
int |
removeValue(org.ofbiz.core.entity.GenericValue value)
|
void |
setGenericValues(List<? extends org.ofbiz.core.entity.GenericValue> genericValues)
|
void |
store(org.ofbiz.core.entity.GenericValue gv)
|
void |
storeAll(List<org.ofbiz.core.entity.GenericValue> genericValues)
|
List<org.ofbiz.core.entity.GenericValue> |
transform(String entityName,
org.ofbiz.core.entity.EntityCondition entityCondition,
List<String> orderBy,
String lockField,
org.ofbiz.core.entity.Transformation transformation)
Applies the given transformation to any entities matching the given condition. |
org.ofbiz.core.entity.GenericValue |
transformOne(String entityName,
org.ofbiz.core.entity.EntityCondition entityCondition,
String lockField,
org.ofbiz.core.entity.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<org.ofbiz.core.entity.GenericValue> expectedGenericValues)
Look through all the fields that are expected, and checks that they have the correct values. |
void |
verifyAll()
Look through all the fields that are expected, and checks that they have the correct values. |
void |
verifyAll(List<org.ofbiz.core.entity.GenericValue> expectedGenericValues)
Look through all the fields that are expected, and checks that they have the correct values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int STARTING_ID
Constructor Detail |
---|
public MockOfBizDelegator()
public MockOfBizDelegator(List<? extends org.ofbiz.core.entity.GenericValue> genericValues, List<? extends org.ofbiz.core.entity.GenericValue> expectedGenericValues)
genericValues
- a list of GenericValue objects that represents the initial state of the databaseexpectedGenericValues
- 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(org.ofbiz.core.entity.DelegatorInterface delegatorInterface)
Method Detail |
---|
public List<org.ofbiz.core.entity.GenericValue> findByField(String entityName, String fieldName, Object fieldValue)
OfBizDelegator
findByField
in interface OfBizDelegator
entityName
- The Name of the Entity as defined in the entity XML filefieldName
- The field to do filtering by.fieldValue
- The desired value for the filtering field.
public List<org.ofbiz.core.entity.GenericValue> findByField(String entityName, String fieldName, Object fieldValue, String orderBy)
OfBizDelegator
findByField
in interface OfBizDelegator
entityName
- The Name of the Entity as defined in the entity XML filefieldName
- The field to do filtering by.fieldValue
- The desired value for the filtering field.orderBy
- Single field to order by.
public void setGenericValues(List<? extends org.ofbiz.core.entity.GenericValue> genericValues)
public List<org.ofbiz.core.entity.GenericValue> findByAnd(String s, Map<String,?> map) throws DataAccessException
OfBizDelegator
findByAnd
in interface OfBizDelegator
s
- The Name of the Entity as defined in the entity XML filemap
- The fields of the named entity to query by with their corresponding values
DataAccessException
- If an error occurs in the persistence layer.public List<org.ofbiz.core.entity.GenericValue> findByAnd(String s, Map<String,?> map, List<String> orderClause) throws DataAccessException
findByAnd
in interface OfBizDelegator
DataAccessException
public List<org.ofbiz.core.entity.GenericValue> findByAnd(String s, List<org.ofbiz.core.entity.EntityCondition> expressions) throws DataAccessException
findByAnd
in interface OfBizDelegator
DataAccessException
public List<org.ofbiz.core.entity.GenericValue> findByOr(String entityName, List<? extends org.ofbiz.core.entity.EntityCondition> expressions, List<String> orderBy) throws DataAccessException
findByOr
in interface OfBizDelegator
DataAccessException
public List<org.ofbiz.core.entity.GenericValue> findByLike(String entityName, Map<String,?> map, List<String> orderBy) throws DataAccessException
findByLike
in interface OfBizDelegator
DataAccessException
public List<org.ofbiz.core.entity.GenericValue> findByLike(String entityName, Map<String,?> map) throws DataAccessException
findByLike
in interface OfBizDelegator
DataAccessException
public void removeAll(List genericValues) throws DataAccessException
removeAll
in interface OfBizDelegator
DataAccessException
public int removeByAnd(String s, Map<String,?> map) throws DataAccessException
removeByAnd
in interface OfBizDelegator
DataAccessException
public int removeByCondition(String entityName, org.ofbiz.core.entity.EntityCondition condition) throws DataAccessException
removeByCondition
in interface OfBizDelegator
DataAccessException
public int removeById(String entityName, Long id)
OfBizDelegator
removeById
in interface OfBizDelegator
entityName
- the entity type (ie TABLE)id
- the id of the row to delete.
public int removeValue(org.ofbiz.core.entity.GenericValue value) throws DataAccessException
removeValue
in interface OfBizDelegator
DataAccessException
public void storeAll(List<org.ofbiz.core.entity.GenericValue> genericValues) throws DataAccessException
storeAll
in interface OfBizDelegator
DataAccessException
public List<org.ofbiz.core.entity.GenericValue> findAll(String s)
findAll
in interface OfBizDelegator
public List<org.ofbiz.core.entity.GenericValue> findAll(String s, List<String> sortOrder) throws DataAccessException
findAll
in interface OfBizDelegator
DataAccessException
public void store(org.ofbiz.core.entity.GenericValue gv) throws DataAccessException
store
in interface OfBizDelegator
DataAccessException
public org.ofbiz.core.entity.GenericValue createValue(String entity, Map<String,Object> params) throws DataAccessException
OfBizDelegator
createValue
in interface OfBizDelegator
entity
- the entity name.params
- field values
DataAccessException
- if an error occurs in the Database layerOfBizDelegator.makeValue(String)
public org.ofbiz.core.entity.GenericValue makeValue(String entity)
OfBizDelegator
makeValue
in interface OfBizDelegator
entity
- the entity name.
OfBizDelegator.makeValue(String, java.util.Map)
,
OfBizDelegator.createValue(String, java.util.Map)
public org.ofbiz.core.entity.GenericValue makeValue(String entityName, Map<String,Object> fields)
OfBizDelegator
makeValue
in interface OfBizDelegator
entityName
- the entity name.fields
- initial field values
OfBizDelegator.makeValue(String)
,
OfBizDelegator.createValue(String, java.util.Map)
public org.ofbiz.core.entity.GenericValue findById(String entityName, Long id) throws DataAccessException
OfBizDelegator
This method is a synonym for OfBizDelegator.findByPrimaryKey(String, Long)
findById
in interface OfBizDelegator
entityName
- The Name of the Entity as defined in the entity XML fileid
- The numeric "id" field value that is the primary key of this entity.
DataAccessException
- DataAccessExceptionpublic org.ofbiz.core.entity.GenericValue findByPrimaryKey(String entityName, Long id)
OfBizDelegator
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.
findByPrimaryKey
in interface OfBizDelegator
entityName
- The Name of the Entity as defined in the entity XML fileid
- The numeric "id" field value that is the primary key of this entity.
OfBizDelegator.findByPrimaryKey(String, java.util.Map)
public org.ofbiz.core.entity.GenericValue findByPrimaryKey(String s, Map<String,?> map)
OfBizDelegator
findByPrimaryKey
in interface OfBizDelegator
s
- The Name of the Entity as defined in the entity XML filemap
- The field/value pairs of the primary key (in JIRA, mostly just a single field "id")
OfBizDelegator.findByPrimaryKey(String, Long)
public List<org.ofbiz.core.entity.GenericValue> getRelated(String relationName, org.ofbiz.core.entity.GenericValue gv)
getRelated
in interface OfBizDelegator
public List<org.ofbiz.core.entity.GenericValue> getRelated(String relationName, org.ofbiz.core.entity.GenericValue gv, List<String> orderBy)
getRelated
in interface OfBizDelegator
public long getCount(String entityName)
OfBizDelegator
getCount
in interface OfBizDelegator
entityName
- entity name
public long getCountByAnd(String entityName, Map<String,?> fields)
OfBizDelegator
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. In addition, the view-entity will need to define any columns that you wish to use in the where clause.
getCountByAnd
in interface OfBizDelegator
entityName
- entity namefields
- The fields of the named entity to query by with their corresponding values
public OfBizListIterator findListIteratorByCondition(String entityType, org.ofbiz.core.entity.EntityCondition condition)
OfBizDelegator
finally
block to avoid connection
leaks.
findListIteratorByCondition
in interface OfBizDelegator
public OfBizListIterator findListIteratorByCondition(String entityName, org.ofbiz.core.entity.EntityCondition whereEntityCondition, org.ofbiz.core.entity.EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, org.ofbiz.core.entity.EntityFindOptions entityFindOptions)
OfBizDelegator
finally
block to avoid connection
leaks.
findListIteratorByCondition
in interface OfBizDelegator
public int bulkUpdateByPrimaryKey(String entityName, Map<String,?> updateValues, List<Long> keys)
OfBizDelegator
bulkUpdateByPrimaryKey
in interface OfBizDelegator
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.
public int bulkUpdateByAnd(String entityName, Map<String,?> updateValues, Map<String,?> criteria)
OfBizDelegator
bulkUpdateByAnd
in interface OfBizDelegator
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.
public void verifyAll() throws junit.framework.AssertionFailedError
junit.framework.AssertionFailedError
- if does not matchpublic void verifyAll(List<org.ofbiz.core.entity.GenericValue> expectedGenericValues) throws junit.framework.AssertionFailedError
junit.framework.AssertionFailedError
- if does not matchpublic void verify() throws junit.framework.AssertionFailedError
junit.framework.AssertionFailedError
- if does not matchpublic void verify(List<org.ofbiz.core.entity.GenericValue> expectedGenericValues) throws junit.framework.AssertionFailedError
expectedGenericValues
- overrides anything set during construction
junit.framework.AssertionFailedError
- if does not matchpublic void addRelatedMap(String relationName, org.ofbiz.core.entity.GenericValue gv, List<org.ofbiz.core.entity.GenericValue> listToReturn)
public void addRelatedMap(String relationName, org.ofbiz.core.entity.GenericValue gv, org.ofbiz.core.entity.GenericValue... gvsToReturns)
public int removeByOr(String entityName, String entityId, List<Long> ids)
OfBizDelegator
entityName
and where entityId
- Specified by:
removeByOr
in interface OfBizDelegator
- 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 List<org.ofbiz.core.entity.GenericValue> findByCondition(String entityName, org.ofbiz.core.entity.EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy) throws DataAccessException
OfBizDelegator
findByCondition
in interface OfBizDelegator
entityName
- The Name of the Entity as defined in the entity model XML fileentityCondition
- The EntityCondition object that specifies how to constrain this queryfieldsToSelect
- The fields of the named entity to get from the database; if empty or null all fields will be retreivedorderBy
- The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
DataAccessException
- If an error occurs in the persistence layer.public org.ofbiz.core.entity.EntityCondition lastEntityCondition()
findByCondition(java.lang.String, org.ofbiz.core.entity.EntityCondition, java.util.Collection, java.util.List)
, to allow assertions.
public List<String> lastOrderBy()
findByCondition(java.lang.String, org.ofbiz.core.entity.EntityCondition, java.util.Collection, java.util.List)
, to allow assertions.
public List<org.ofbiz.core.entity.GenericValue> findByCondition(String entityName, org.ofbiz.core.entity.EntityCondition entityCondition, Collection<String> fieldsToSelect)
OfBizDelegator
Convenience method for calling OfBizDelegator.findByCondition(String, EntityCondition, Collection, List)
with
an empty orderBy list.
findByCondition
in interface OfBizDelegator
entityName
- The Name of the Entity as defined in the entity model XML fileentityCondition
- The EntityCondition object that specifies how to constrain this queryfieldsToSelect
- The fields of the named entity to get from the database; if empty or null all fields will be retreived
public org.ofbiz.core.entity.model.ModelReader getModelReader()
OfBizDelegator
getModelReader
in interface OfBizDelegator
ModelReader
public void refreshSequencer()
OfBizDelegator
refreshSequencer
in interface OfBizDelegator
public org.ofbiz.core.entity.DelegatorInterface getDelegatorInterface()
OfBizDelegator
getDelegatorInterface
in interface OfBizDelegator
public boolean removeRelated(String relationName, org.ofbiz.core.entity.GenericValue schemeGv)
OfBizDelegator
removeRelated
in interface OfBizDelegator
relationName
- the name of the relationship.schemeGv
- the gv at the start of the relationship.
public int bulkCopyColumnValuesByAnd(String entityName, Map updateColumns, Map criteria)
OfBizDelegator
bulkCopyColumnValuesByAnd
in interface OfBizDelegator
entityName
- table na,eupdateColumns
- map of update to - update from columnscriteria
- map of column names and their values that will create WHERE clause
public List<org.ofbiz.core.entity.GenericValue> transform(String entityName, org.ofbiz.core.entity.EntityCondition entityCondition, List<String> orderBy, String lockField, org.ofbiz.core.entity.Transformation transformation)
OfBizDelegator
transform
in interface OfBizDelegator
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 attemptedtransformation
- the transformation to apply (required)
public org.ofbiz.core.entity.GenericValue transformOne(String entityName, org.ofbiz.core.entity.EntityCondition entityCondition, String lockField, org.ofbiz.core.entity.Transformation transformation)
OfBizDelegator
transformOne
in interface OfBizDelegator
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 attemptedtransformation
- the transformation to apply (required)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |