Class TestPersistenceContextBase


  • public class TestPersistenceContextBase
    extends Object
    Central context class that hides persistence from tests, so there is no need to work with persistence in the tests (transactions etc).
    • Field Detail

      • entityManagerFactory

        protected javax.persistence.EntityManagerFactory entityManagerFactory
      • transactionManager

        protected org.drools.persistence.jta.JtaTransactionManager transactionManager
      • environment

        protected org.kie.api.runtime.Environment environment
      • dataSourceProperties

        protected Properties dataSourceProperties
    • Constructor Detail

      • TestPersistenceContextBase

        public TestPersistenceContextBase()
    • Method Detail

      • init

        public void init​(PersistenceUnit persistenceUnit)
        Initializes persistence context from specified persistence unit.
        Parameters:
        persistenceUnit - Persistence unit which is used to initialize this persistence context.
      • clean

        public void clean()
        Cleans up this persistence context. Closes all instances that need to be closed.
      • executeScripts

        public void executeScripts​(File scriptsRootFolder,
                                   ScriptFilter scriptFilter)
                            throws IOException,
                                   SQLException
        Executes SQL scripts from specified root SQL scripts folder. Selects appropriate scripts from root folder by using dialect that is defined in datasource.properties file.
        Parameters:
        scriptsRootFolder - Root folder containing folders with SQL scripts for all supported database systems.
        scriptFilter - indicates the filter to apply, including springboot or not scripts and create/drop scripts
        Throws:
        IOException
        SQLException
      • executeScripts

        public void executeScripts​(File scriptsRootFolder,
                                   ScriptFilter scriptFilter,
                                   DataSource dataSource,
                                   String defaultSchema)
                            throws IOException,
                                   SQLException
        Executes SQL scripts from specified root SQL scripts folder. Selects appropriate scripts from root folder by using dialect that is defined in datasource.properties file.
        Parameters:
        scriptsRootFolder - Root folder containing folders with SQL scripts for all supported database systems.
        scriptFilter - indicates the filter to apply, including springboot or not scripts and create/drop scripts
        dataSource - Datasource where scripts will be executed.
        defaultSchema - Default database schema to be set prior to running scripts
        Throws:
        IOException
        SQLException
      • startAndPersistSomeProcess

        public void startAndPersistSomeProcess​(String processId)
        Starts and persists a basic simple process using current database entities.
        Parameters:
        processId - Process identifier. This identifier is also used to generate KieBase (process with this identifier is part of generated KieBase).
      • loadPersistedSession

        public org.kie.internal.runtime.StatefulKnowledgeSession loadPersistedSession​(Long sessionId,
                                                                                      String processIdForKieBase)
        Loads persisted session from database.
        Parameters:
        sessionId - Unique identifier of the session.
        processIdForKieBase - Process identifier for KieBase generation. A KieBase is generated for loaded session and this KieBase contains process with this identifier.
        Returns:
        Session that is stored in database.
      • getStoredProcessesCount

        public int getStoredProcessesCount()
        Reads stored processes count from database.
        Returns:
        Stored processes count.
      • getStoredSessionsCount

        public int getStoredSessionsCount()
        Reads stored sessions count from database.
        Returns:
        Stored sessions count.
      • testIsInitialized

        protected void testIsInitialized()
        Checks if this persistence context is initialized.