public class TestContainer
extends org.junit.rules.ExternalResource
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
Usage of the common instance (time saving):
@RegisterExtension public static TestContainer cont = TestContainer.Common.INSTANCE; @Test public void testSomething() { try (Transaction tx = cont.persistence().createTransaction()) { ... } }
Usage of a specific instance:
@RegisterExtension public static TestContainer cont = new TestContainer() .setAppPropertiesFiles(Arrays.asList( "com/haulmont/cuba/app.properties", "com/haulmont/cuba/testsupport/test-app.properties", "com/company/sample/core/my-test-app.properties")); @Test public void testSomething() { try (Transaction tx = cont.persistence().createTransaction()) { ... } }
Modifier and Type | Class and Description |
---|---|
static class |
TestContainer.Common |
Modifier and Type | Field and Description |
---|---|
protected java.util.List<java.lang.String> |
appComponents |
protected java.util.List<java.lang.String> |
appPropertiesFiles |
protected java.lang.String |
dbDriver |
protected java.lang.String |
dbPassword |
protected java.lang.String |
dbUrl |
protected java.lang.String |
dbUser |
protected boolean |
isAutoConfigureDataSource |
protected java.lang.String |
springConfig |
Constructor and Description |
---|
TestContainer() |
Modifier and Type | Method and Description |
---|---|
TestContainer |
addAppPropertiesFile(java.lang.String name) |
protected void |
after() |
void |
afterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) |
TestContainer |
autoConfigureDataSource() |
protected void |
before() |
void |
beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) |
protected void |
cleanupContext() |
void |
deleteRecord(Entity... entities) |
void |
deleteRecord(java.lang.String table,
java.lang.Object... ids) |
void |
deleteRecord(java.lang.String table,
java.lang.String primaryKeyCol,
java.lang.Object... ids) |
EntityManager |
entityManager() |
java.util.List<java.lang.String> |
getAppComponents() |
java.util.Map<java.lang.String,java.lang.String> |
getAppProperties() |
java.util.List<java.lang.String> |
getAppPropertiesFiles() |
java.lang.String |
getDbDriver() |
java.lang.String |
getDbPassword() |
java.lang.String |
getDbUrl() |
java.lang.String |
getDbUser() |
org.springframework.context.support.ClassPathXmlApplicationContext |
getSpringAppContext() |
java.lang.String |
getSpringConfig()
Deprecated.
define the spring configuration file in the
cuba.springContextConfig application property
of the test-app.properties file. This method will be removed in one of future releases. |
protected void |
initAppComponents() |
protected void |
initAppContext() |
protected void |
initAppProperties() |
protected void |
initDataSources() |
protected void |
initPersistenceConfig() |
Metadata |
metadata() |
Persistence |
persistence() |
TestContainer |
setAppComponents(java.util.List<java.lang.String> appComponents) |
TestContainer |
setAppPropertiesFiles(java.util.List<java.lang.String> appPropertiesFiles) |
TestContainer |
setDbDriver(java.lang.String dbDriver) |
TestContainer |
setDbPassword(java.lang.String dbPassword) |
TestContainer |
setDbUrl(java.lang.String dbUrl) |
TestContainer |
setDbUser(java.lang.String dbUser) |
TestContainer |
setSpringConfig(java.lang.String springConfig)
Deprecated.
define the spring configuration file in the
cuba.springContextConfig application property
of the test-app.properties file. This method will be removed in one of future releases. |
protected void |
setupContext() |
void |
setupLogging(java.lang.String logger,
ch.qos.logback.classic.Level level) |
protected java.lang.String springConfig
protected java.util.List<java.lang.String> appComponents
protected java.util.List<java.lang.String> appPropertiesFiles
protected java.lang.String dbDriver
protected java.lang.String dbUrl
protected java.lang.String dbUser
protected java.lang.String dbPassword
protected boolean isAutoConfigureDataSource
public Persistence persistence()
public EntityManager entityManager()
public Metadata metadata()
public void deleteRecord(java.lang.String table, java.lang.Object... ids)
public void deleteRecord(java.lang.String table, java.lang.String primaryKeyCol, java.lang.Object... ids)
public void deleteRecord(Entity... entities)
public void setupLogging(java.lang.String logger, ch.qos.logback.classic.Level level)
public java.util.List<java.lang.String> getAppComponents()
public java.util.List<java.lang.String> getAppPropertiesFiles()
@Deprecated public java.lang.String getSpringConfig()
cuba.springContextConfig
application property
of the test-app.properties file. This method will be removed in one of future releases.@Deprecated public TestContainer setSpringConfig(java.lang.String springConfig)
cuba.springContextConfig
application property
of the test-app.properties file. This method will be removed in one of future releases.public TestContainer setAppComponents(java.util.List<java.lang.String> appComponents)
public TestContainer setAppPropertiesFiles(java.util.List<java.lang.String> appPropertiesFiles)
public TestContainer addAppPropertiesFile(java.lang.String name)
public java.lang.String getDbDriver()
public TestContainer setDbDriver(java.lang.String dbDriver)
public java.lang.String getDbUrl()
public TestContainer setDbUrl(java.lang.String dbUrl)
public java.lang.String getDbUser()
public TestContainer setDbUser(java.lang.String dbUser)
public java.lang.String getDbPassword()
public TestContainer setDbPassword(java.lang.String dbPassword)
public TestContainer autoConfigureDataSource()
public org.springframework.context.support.ClassPathXmlApplicationContext getSpringAppContext()
public java.util.Map<java.lang.String,java.lang.String> getAppProperties()
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Exception
afterAll
in interface org.junit.jupiter.api.extension.AfterAllCallback
java.lang.Exception
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.Exception
beforeAll
in interface org.junit.jupiter.api.extension.BeforeAllCallback
java.lang.Exception
protected void before() throws java.lang.Throwable
before
in class org.junit.rules.ExternalResource
java.lang.Throwable
protected void after()
after
in class org.junit.rules.ExternalResource
protected void initDataSources()
protected void initPersistenceConfig()
protected void initAppComponents()
protected void initAppProperties()
protected void initAppContext()
protected void cleanupContext()
protected void setupContext()