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[] contracts  
    protected java.util.SortedMap<org.nuiton.topia.persistence.TopiaEntity,​java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>> detected  
    protected java.util.Map.Entry<org.nuiton.topia.persistence.TopiaEntity,​java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>> entry  
    protected int index  
    protected java.util.Iterator<java.util.Map.Entry<org.nuiton.topia.persistence.TopiaEntity,​java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef>>> itr  
    protected java.util.List<org.nuiton.topia.persistence.util.TopiaEntityRef> refs  
  • Constructor Summary

    Constructors 
    Constructor Description
    TopiaEntityRefTester()  
  • Method Summary

    Modifier and Type Method Description
    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, java.lang.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, 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 state entry.
    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 state entry.
    protected void detectReferences​(java.util.Collection<? extends org.nuiton.topia.persistence.TopiaEntity> entity, int nb, java.lang.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, java.lang.String... ids)
    Detects the references from the given entity which have their topiaId in the given list of ids.
    protected void detectTypes​(java.lang.Class<?>[] expected, org.nuiton.topia.persistence.TopiaEntity... data)
    Detects the type of entities fro the given data.
    protected java.lang.String getAssociationRef​(java.lang.String associationName, java.lang.String e)
    Obtain the reference of an association for a given id.
    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.
    protected T[] getContracts()  
    protected abstract T[] getContracts0()  
    protected <T extends org.nuiton.topia.persistence.TopiaEntity>
    T
    newEntity​(org.nuiton.topia.persistence.TopiaEntityEnum constant, java.lang.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 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

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

      protected int index
  • Constructor Details

  • Method Details

    • 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, java.lang.String topiaId) throws java.lang.IllegalAccessException, java.lang.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:
      java.lang.IllegalAccessException - if can no access entity constructor
      java.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']
      invoke
      getAssociationRef('pet',pet);
      Parameters:
      associationName - the name of the association
      e - 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']
      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, java.lang.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​(java.util.Collection<? extends org.nuiton.topia.persistence.TopiaEntity> entity, int nb, java.lang.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​(java.lang.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, 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 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, 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 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, java.lang.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