Class TestPersistenceContextBase
- java.lang.Object
-
- org.jbpm.test.persistence.scripts.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 Summary
Fields Modifier and Type Field Description protected HashMap<String,Object>
context
protected DatabaseType
databaseType
protected static String
DATASOURCE_PROPERTIES
protected Properties
dataSourceProperties
protected javax.persistence.EntityManagerFactory
entityManagerFactory
protected org.kie.api.runtime.Environment
environment
protected org.drools.persistence.jta.JtaTransactionManager
transactionManager
-
Constructor Summary
Constructors Constructor Description TestPersistenceContextBase()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clean()
Cleans up this persistence context.static TestPersistenceContextBase
createAndInitContext(PersistenceUnit persistenceUnit)
void
executeScripts(File scriptsRootFolder, ScriptFilter scriptFilter)
Executes SQL scripts from specified root SQL scripts folder.void
executeScripts(File scriptsRootFolder, ScriptFilter scriptFilter, DataSource dataSource, String defaultSchema)
Executes SQL scripts from specified root SQL scripts folder.DatabaseType
getDatabaseType()
int
getStoredProcessesCount()
Reads stored processes count from database.int
getStoredSessionsCount()
Reads stored sessions count from database.void
init(PersistenceUnit persistenceUnit)
Initializes persistence context from specified persistence unit.org.kie.internal.runtime.StatefulKnowledgeSession
loadPersistedSession(Long sessionId, String processIdForKieBase)
Loads persisted session from database.void
startAndPersistSomeProcess(String processId)
Starts and persists a basic simple process using current database entities.protected void
testIsInitialized()
Checks if this persistence context is initialized.
-
-
-
Field Detail
-
DATASOURCE_PROPERTIES
protected static final String DATASOURCE_PROPERTIES
- See Also:
- Constant Field Values
-
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
-
databaseType
protected final DatabaseType databaseType
-
-
Method Detail
-
createAndInitContext
public static TestPersistenceContextBase createAndInitContext(PersistenceUnit persistenceUnit)
-
getDatabaseType
public DatabaseType getDatabaseType()
-
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 scriptsdataSource
- 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.
-
-