Class TopiaEntityRefTester<T extends org.nuiton.topia.persistence.TopiaEntityEnum>
java.lang.Object
org.nuiton.topia.persistence.util.TopiaEntityRefTester<T>
- Direct Known Subclasses:
TopiaEntityRefTesterTest
public abstract class TopiaEntityRefTester<T extends org.nuiton.topia.persistence.TopiaEntityEnum>
extends java.lang.Object
A abstract class to help testing
TopiaEntityRef as detectes types, or
detects or references.
An example of use if given in the test TopiaEntityRefTesterTest.- Since:
- 2.3.1
- Author:
- tchemit <chemit@codelutin.com>
-
Field Summary
Fields Modifier and Type Field Description protected T[]contractsprotected java.util.SortedMap<org.nuiton.topia.persistence.TopiaEntity,java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>>detectedprotected java.util.Map.Entry<org.nuiton.topia.persistence.TopiaEntity,java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>>entryprotected intindexprotected java.util.Iterator<java.util.Map.Entry<org.nuiton.topia.persistence.TopiaEntity,java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>>>itrprotected java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>refs -
Constructor Summary
Constructors Constructor Description TopiaEntityRefTester() -
Method Summary
Modifier and Type Method Description voidafter()protected voidassertCurrentEntry(org.nuiton.topia.persistence.TopiaEntity expected, int nbPath)Asserts if the givenexpectedentity is equals to the source of the internal stateentry.protected voidassertDetected(int size)Asserts that the number of detected entries (store in internal statedetected) is ok.protected voidassertEntityRef(int index, org.nuiton.topia.persistence.TopiaEntity invoker, java.lang.String invokerProperty, org.nuiton.topia.persistence.TopiaEntity... expected)Asserts if the given entry definition is equals to the reference entry at positionindexon internal stateentry.protected voidassertNextAssociationEntityRef(org.nuiton.topia.persistence.TopiaEntity invoker, java.lang.String association, java.lang.String id, org.nuiton.topia.persistence.TopiaEntity... expected)Asserts if the given entry definition (of an association) is equals to the next entry reference on internal stateentry.protected voidassertNextEntityRef(org.nuiton.topia.persistence.TopiaEntity invoker, java.lang.String invokerProperty, org.nuiton.topia.persistence.TopiaEntity... expected)Asserts if the given entry definition is equals to the next entry references on internal state stateentry.protected voiddetectReferences(java.util.Collection<? extends org.nuiton.topia.persistence.TopiaEntity> entity, int nb, java.lang.String... ids)Detects the references from the givenentitywhich have their topiaId in the given list ofids.protected voiddetectReferences(org.nuiton.topia.persistence.TopiaEntity entity, int nb, java.lang.String... ids)Detects the references from the givenentitywhich have their topiaId in the given list ofids.protected voiddetectTypes(java.lang.Class<?>[] expected, org.nuiton.topia.persistence.TopiaEntity... data)Detects the type of entities fro the givendata.protected java.lang.StringgetAssociationRef(java.lang.String associationName, java.lang.String e)Obtain the reference of an association for a given id.protected java.lang.StringgetAssociationRef(java.lang.String associationName, org.nuiton.topia.persistence.TopiaEntity e)Obtain the reference of an association for a given entity.protected T[]getContracts()protected abstract T[]getContracts0()protected <T extends org.nuiton.topia.persistence.TopiaEntity>
TnewEntity(org.nuiton.topia.persistence.TopiaEntityEnum constant, java.lang.String topiaId)Creates a new entity with the giventopiaId(will use theTopiaEntityEnum.getImplementation()class).protected voidnextEntry()Obtain the next entry from the iterator.
-
Field Details
-
detected
protected java.util.SortedMap<org.nuiton.topia.persistence.TopiaEntity,java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>> detected -
itr
protected java.util.Iterator<java.util.Map.Entry<org.nuiton.topia.persistence.TopiaEntity,java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>>> itr -
entry
protected java.util.Map.Entry<org.nuiton.topia.persistence.TopiaEntity,java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>> entry -
refs
protected java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef> refs -
contracts
-
index
protected int index
-
-
Constructor Details
-
TopiaEntityRefTester
public TopiaEntityRefTester()
-
-
Method Details
-
getContracts
-
getContracts0
- Returns:
- all the
TopiaEntityEnumto be used
-
after
public void after() -
newEntity
protected <T extends org.nuiton.topia.persistence.TopiaEntity> T newEntity(org.nuiton.topia.persistence.TopiaEntityEnum constant, java.lang.String topiaId) throws java.lang.IllegalAccessException, java.lang.InstantiationExceptionCreates a new entity with the giventopiaId(will use theTopiaEntityEnum.getImplementation()class).- Type Parameters:
T- the type of entity- Parameters:
constant- the constant defining the entitytopiaId- the topia to assign- Returns:
- the new entity
- Throws:
java.lang.IllegalAccessException- if can no access entity constructorjava.lang.InstantiationException- if can no instanciate the entity
-
getAssociationRef
protected java.lang.String getAssociationRef(java.lang.String associationName, org.nuiton.topia.persistence.TopiaEntity e)Obtain the reference of an association for a given entity. Example, to obtain the Pet 'pudding' on a Person :pet[@topiaId='pudding']
invokegetAssociationRef('pet',pet);- Parameters:
associationName- the name of the associatione- the required entity- Returns:
- the reference of the association
-
getAssociationRef
protected java.lang.String getAssociationRef(java.lang.String associationName, java.lang.String e)Obtain the reference of an association for a given id. Example to obtain the Pet 'pudding' on a Person :pet[@topiaId='pudding']
invokegetAssociationRef('pet','pudding');- Parameters:
associationName- the name of the associatione- the id- Returns:
- the reference of the association
-
nextEntry
protected void nextEntry()Obtain the next entry from the iterator. As a side-effect, it will increment the stateindex. -
detectReferences
protected void detectReferences(org.nuiton.topia.persistence.TopiaEntity entity, int nb, java.lang.String... ids) throws org.nuiton.topia.TopiaExceptionDetects the references from the givenentitywhich have their topiaId in the given list ofids. As a side-effect, it will update the statesdetectedand set the iteratoritrto the first position on detected entries.- Parameters:
entity- the entity to seeknb- the required number of entriesids- the ids to seek- Throws:
org.nuiton.topia.TopiaException- if any pb while visiting entities
-
detectReferences
protected void detectReferences(java.util.Collection<? extends org.nuiton.topia.persistence.TopiaEntity> entity, int nb, java.lang.String... ids) throws org.nuiton.topia.TopiaExceptionDetects the references from the givenentitywhich have their topiaId in the given list ofids. As a side-effect, it will update the statesdetectedand set the iteratoritrto the first position on detected entries.- Parameters:
entity- the entity to seeknb- the required number of entriesids- the ids to seek- Throws:
org.nuiton.topia.TopiaException- if any pb while visiting entities
-
detectTypes
protected void detectTypes(java.lang.Class<?>[] expected, org.nuiton.topia.persistence.TopiaEntity... data) throws org.nuiton.topia.TopiaExceptionDetects the type of entities fro the givendata.- Parameters:
expected- the array of expected typesdata- the data to seek- Throws:
org.nuiton.topia.TopiaException- if any pb while visiting data
-
assertNextEntityRef
protected void assertNextEntityRef(org.nuiton.topia.persistence.TopiaEntity invoker, java.lang.String invokerProperty, org.nuiton.topia.persistence.TopiaEntity... expected)Asserts if the given entry definition is equals to the next entry references on internal state stateentry.- Parameters:
invoker- the invoker of the referenceinvokerProperty- the access path of the referenceexpected- the expected topia entities path to access reference target
-
assertNextAssociationEntityRef
protected void assertNextAssociationEntityRef(org.nuiton.topia.persistence.TopiaEntity invoker, java.lang.String association, java.lang.String id, org.nuiton.topia.persistence.TopiaEntity... expected)Asserts if the given entry definition (of an association) is equals to the next entry reference on internal stateentry.- Parameters:
invoker- the invoker of the referenceassociation- the association nameid- the id of the association ( seegetAssociationRef(String, TopiaEntity)expected- the expected topia entities path to access reference target
-
assertEntityRef
protected void assertEntityRef(int index, org.nuiton.topia.persistence.TopiaEntity invoker, java.lang.String invokerProperty, org.nuiton.topia.persistence.TopiaEntity... expected)Asserts if the given entry definition is equals to the reference entry at positionindexon internal stateentry.- Parameters:
index- the index of the reference to test inentryinvoker- the invoker of the referenceinvokerProperty- the path of the referenceexpected- th expected topia entities path to access reference target
-
assertCurrentEntry
protected void assertCurrentEntry(org.nuiton.topia.persistence.TopiaEntity expected, int nbPath)Asserts if the givenexpectedentity is equals to the source of the internal stateentry.- Parameters:
expected- the required source of the entrynbPath- the expected number of references of the given entry
-
assertDetected
protected void assertDetected(int size)Asserts that the number of detected entries (store in internal statedetected) is ok. As a side-effect, it will reset the internal stateitron the first entry of thedetectedlist.- Parameters:
size- the expected number of detected entries
-