org.nuiton.topia.persistence.util
Class TopiaEntityRefTester<T extends org.nuiton.topia.persistence.TopiaEntityEnum>

java.lang.Object
  extended by org.nuiton.topia.persistence.util.TopiaEntityRefTester<T>
Direct Known Subclasses:
TopiaEntityRefTesterTest

public abstract class TopiaEntityRefTester<T extends org.nuiton.topia.persistence.TopiaEntityEnum>
extends 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

Field Summary
protected  T[] contracts
           
protected  SortedMap<org.nuiton.topia.persistence.TopiaEntity,List<org.nuiton.topia.persistence.util.TopiaEntityRef>> detected
           
protected  Map.Entry<org.nuiton.topia.persistence.TopiaEntity,List<org.nuiton.topia.persistence.util.TopiaEntityRef>> entry
           
protected  int index
           
protected  Iterator<Map.Entry<org.nuiton.topia.persistence.TopiaEntity,List<org.nuiton.topia.persistence.util.TopiaEntityRef>>> itr
           
protected  List<org.nuiton.topia.persistence.util.TopiaEntityRef> refs
           
 
Constructor Summary
TopiaEntityRefTester()
           
 
Method Summary
 void after()
           
protected  void assertCurrentEntry(org.nuiton.topia.persistence.TopiaEntity expected, int nbPath)
          Asserts if the given expected entity is equals to the source of the internal state entry.
protected  void assertDetected(int size)
          Asserts that the number of detected entries (store in internal state detected) is ok.
protected  void assertEntityRef(int index, org.nuiton.topia.persistence.TopiaEntity invoker, String invokerProperty, org.nuiton.topia.persistence.TopiaEntity... expected)
          Asserts if the given entry definition is equals to the reference entry at position index on internal state entry.
protected  void assertNextAssociationEntityRef(org.nuiton.topia.persistence.TopiaEntity invoker, String association, 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 state entry.
protected  void assertNextEntityRef(org.nuiton.topia.persistence.TopiaEntity invoker, String invokerProperty, org.nuiton.topia.persistence.TopiaEntity... expected)
          Asserts if the given entry definition is equals to the next entry references on internal state state entry.
protected  void detectReferences(Collection<? extends org.nuiton.topia.persistence.TopiaEntity> entity, int nb, String... ids)
          Detects the references from the given entity which have their topiaId in the given list of ids.
protected  void detectReferences(org.nuiton.topia.persistence.TopiaEntity entity, int nb, String... ids)
          Detects the references from the given entity which have their topiaId in the given list of ids.
protected  void detectTypes(Class<?>[] expected, org.nuiton.topia.persistence.TopiaEntity... data)
          Detects the type of entities fro the given data.
protected  String getAssociationRef(String associationName, String e)
          Obtain the reference of an association for a given id.
protected  String getAssociationRef(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>
T
newEntity(org.nuiton.topia.persistence.TopiaEntityEnum constant, String topiaId)
          Creates a new entity with the given topiaId (will use the TopiaEntityEnum.getImplementation() class).
protected  void nextEntry()
          Obtain the next entry from the iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

detected

protected SortedMap<org.nuiton.topia.persistence.TopiaEntity,List<org.nuiton.topia.persistence.util.TopiaEntityRef>> detected

itr

protected Iterator<Map.Entry<org.nuiton.topia.persistence.TopiaEntity,List<org.nuiton.topia.persistence.util.TopiaEntityRef>>> itr

entry

protected Map.Entry<org.nuiton.topia.persistence.TopiaEntity,List<org.nuiton.topia.persistence.util.TopiaEntityRef>> entry

refs

protected List<org.nuiton.topia.persistence.util.TopiaEntityRef> refs

contracts

protected T extends org.nuiton.topia.persistence.TopiaEntityEnum[] contracts

index

protected int index
Constructor Detail

TopiaEntityRefTester

public TopiaEntityRefTester()
Method Detail

getContracts

protected T[] getContracts()

getContracts0

protected abstract T[] getContracts0()
Returns:
all the TopiaEntityEnum to be used

after

public void after()

newEntity

protected <T extends org.nuiton.topia.persistence.TopiaEntity> T newEntity(org.nuiton.topia.persistence.TopiaEntityEnum constant,
                                                                           String topiaId)
                                                                throws IllegalAccessException,
                                                                       InstantiationException
Creates a new entity with the given topiaId (will use the TopiaEntityEnum.getImplementation() class).

Type Parameters:
T - the type of entity
Parameters:
constant - the constant defining the entity
topiaId - the topia to assign
Returns:
the new entity
Throws:
IllegalAccessException - if can no access entity constructor
InstantiationException - if can no instanciate the entity

getAssociationRef

protected String getAssociationRef(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']
invoke
getAssociationRef('pet',pet);

Parameters:
associationName - the name of the association
e - the required entity
Returns:
the reference of the association

getAssociationRef

protected String getAssociationRef(String associationName,
                                   String e)
Obtain the reference of an association for a given id.

Example to obtain the Pet 'pudding' on a Person :

pet[@topiaId='pudding']
invoke
getAssociationRef('pet','pudding');

Parameters:
associationName - the name of the association
e - 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 state index.


detectReferences

protected void detectReferences(org.nuiton.topia.persistence.TopiaEntity entity,
                                int nb,
                                String... ids)
                         throws org.nuiton.topia.TopiaException
Detects the references from the given entity which have their topiaId in the given list of ids.

As a side-effect, it will update the states detected and set the iterator itr to the first position on detected entries.

Parameters:
entity - the entity to seek
nb - the required number of entries
ids - the ids to seek
Throws:
org.nuiton.topia.TopiaException - if any pb while visiting entities

detectReferences

protected void detectReferences(Collection<? extends org.nuiton.topia.persistence.TopiaEntity> entity,
                                int nb,
                                String... ids)
                         throws org.nuiton.topia.TopiaException
Detects the references from the given entity which have their topiaId in the given list of ids.

As a side-effect, it will update the states detected and set the iterator itr to the first position on detected entries.

Parameters:
entity - the entity to seek
nb - the required number of entries
ids - the ids to seek
Throws:
org.nuiton.topia.TopiaException - if any pb while visiting entities

detectTypes

protected void detectTypes(Class<?>[] expected,
                           org.nuiton.topia.persistence.TopiaEntity... data)
                    throws org.nuiton.topia.TopiaException
Detects the type of entities fro the given data.

Parameters:
expected - the array of expected types
data - 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,
                                   String invokerProperty,
                                   org.nuiton.topia.persistence.TopiaEntity... expected)
Asserts if the given entry definition is equals to the next entry references on internal state state entry.

Parameters:
invoker - the invoker of the reference
invokerProperty - the access path of the reference
expected - the expected topia entities path to access reference target

assertNextAssociationEntityRef

protected void assertNextAssociationEntityRef(org.nuiton.topia.persistence.TopiaEntity invoker,
                                              String association,
                                              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 state entry.

Parameters:
invoker - the invoker of the reference
association - the association name
id - the id of the association ( see getAssociationRef(String, TopiaEntity)
expected - the expected topia entities path to access reference target

assertEntityRef

protected void assertEntityRef(int index,
                               org.nuiton.topia.persistence.TopiaEntity invoker,
                               String invokerProperty,
                               org.nuiton.topia.persistence.TopiaEntity... expected)
Asserts if the given entry definition is equals to the reference entry at position index on internal state entry.

Parameters:
index - the index of the reference to test in entry
invoker - the invoker of the reference
invokerProperty - the path of the reference
expected - th expected topia entities path to access reference target

assertCurrentEntry

protected void assertCurrentEntry(org.nuiton.topia.persistence.TopiaEntity expected,
                                  int nbPath)
Asserts if the given expected entity is equals to the source of the internal state entry.

Parameters:
expected - the required source of the entry
nbPath - 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 state detected) is ok.

As a side-effect, it will reset the internal state itr on the first entry of the detected list.

Parameters:
size - the expected number of detected entries


Copyright © 2004-2010 CodeLutin. All Rights Reserved.