public abstract class CdmIntegrationTest
extends org.unitils.UnitilsJUnit4
The H2 can be monitored during the test execution if the system property h2Server
is given as
java virtual machine argument:
-Dh2Server
.
An internal h2 database application will be started and listens at port 8082.
The port to listen on can be specified by passing a second argument, e.g.: -Dh2Server 8083
.
writeDbUnitDataSetFile(String[])
method.
From http://www.unitils.org/tutorial-database.html
, by default every test is executed in a transaction,
which is committed at the end of the test. This can be disabled using @Transactional(TransactionMode.DISABLED)Modifier and Type | Field and Description |
---|---|
protected javax.sql.DataSource |
dataSource |
protected static Logger |
logger |
static java.lang.String[] |
termLoadingTables
List of the tables which are initially being populated during term loading.
|
protected org.springframework.transaction.support.DefaultTransactionDefinition |
txDefinition |
Constructor and Description |
---|
CdmIntegrationTest() |
Modifier and Type | Method and Description |
---|---|
abstract void |
createTestDataSet()
This is the common method to create test data xml files for integration tests.
|
protected boolean |
existsInCollection(java.util.Collection<? extends CdmBase> cdmBases,
java.util.UUID uuid) |
protected org.dbunit.database.IDatabaseConnection |
getConnection() |
protected <T extends CdmBase> |
getEntityFromCollection(java.util.Collection<T> cdmBases,
java.util.UUID uuid) |
void |
printDataSet(java.io.OutputStream out)
Prints the data set to an output stream, using the
FlatXmlDataSet . |
void |
printDataSet(java.io.OutputStream out,
org.dbunit.dataset.filter.ITableFilterSimple filter)
Prints the named tables to an output stream, using dbunit's
FlatXmlWriter . |
void |
printDataSet(java.io.OutputStream out,
java.lang.String... includeTableNames)
Prints the named tables to an output stream, using dbunit's
FlatXmlDataSet . |
void |
printDataSetWithNull(java.io.OutputStream out)
Prints the data set to an output stream, using the
FlatFullXmlWriter . |
void |
printDataSetWithNull(java.io.OutputStream out,
java.lang.Boolean excludeTermLoadingTables,
org.dbunit.dataset.filter.ITableFilterSimple excludeFilterOrig,
java.lang.String[] includeTableNames) |
void |
printDataSetWithNull(java.io.OutputStream out,
java.lang.String[] includeTableNames)
Prints the data set to an output stream, using the
FlatFullXmlWriter . |
void |
printDtd(java.io.OutputStream out)
Prints a dtd to an output stream, using dbunit's
FlatDtdDataSet . |
void |
printTableNames(java.io.OutputStream out,
java.lang.String formatString) |
void |
setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager) |
void |
startH2Server()
How to use:
Add
-Dh2Server as jvm argument to activate.
uncomment database.url= jdbc:h2:tcp://localhost/~/cdm in /cdmlib-test/src/main/resources/unitils.properties |
protected java.lang.String |
transformSourceToString(javax.xml.transform.Source source)
see {@link DataBaseTablePrinter#transformSourceToString(Source)
|
void |
writeDbUnitDataSetFile(java.lang.String[] includeTableNames)
WARNING read this doc before using this method.
|
void |
writeDbUnitDataSetFile(java.lang.String[] includeTableNames,
java.lang.String fileAppendix,
boolean withNullValues)
Extension of method mentioned in "see also" where you can specify an appendix for the
generated DbUnit data set file.
|
protected static final Logger logger
public static final java.lang.String[] termLoadingTables
PersistentTermInitializer
protected javax.sql.DataSource dataSource
protected org.springframework.transaction.support.DefaultTransactionDefinition txDefinition
public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
protected org.dbunit.database.IDatabaseConnection getConnection()
public void startH2Server() throws java.lang.Exception
-Dh2Server
as jvm argument to activate.database.url= jdbc:h2:tcp://localhost/~/cdm
in /cdmlib-test/src/main/resources/unitils.properties
java.lang.Exception
public void printDataSet(java.io.OutputStream out)
FlatXmlDataSet
.
printDataSetWithNull(OutputStream)
method instead.
Remember, if you've just called save() or
update(), the data isn't written to the database until the
transaction is committed, and that isn't until after the
method exits. Consequently, if you want to test writing to
the database, either use the @ExpectedDataSet
annotation (that executes after the test is run), or use
CdmTransactionalIntegrationTest
.
out
- The OutputStream to write to.DataBaseTablePrinter}
,
FlatFullXmlWriter
public void printDataSetWithNull(java.io.OutputStream out, java.lang.String[] includeTableNames)
FlatFullXmlWriter
.
which is a variant of the FlatXmlWriter
. It
inserts '[null]' place holders for null values instead of skipping them.
This was necessary to make this xml database export compatible to the
MultiSchemaXmlDataSetReader
which is used in Unitils since version 3.x
out
- out The OutputStream to write to.includeTableNames
- DataBaseTablePrinter}
public void printDataSetWithNull(java.io.OutputStream out)
FlatFullXmlWriter
.
which is a variant of the FlatXmlWriter
. It
inserts '[null]' place holders for null values instead of skipping them.
This was necessary to make this xml database export compatible to the
MultiSchemaXmlDataSetReader
which is used in Unitils since version 3.x
Remember, if you've just called save() or
update(), the data isn't written to the database until the
transaction is committed, and that isn't until after the
method exits. Consequently, if you want to test writing to
the database, either use the @ExpectedDataSet
annotation (that executes after the test is run), or use
CdmTransactionalIntegrationTest
.
out
- The OutputStream to write to.DataBaseTablePrinter}
,
FlatFullXmlWriter
public void printDataSetWithNull(java.io.OutputStream out, java.lang.Boolean excludeTermLoadingTables, org.dbunit.dataset.filter.ITableFilterSimple excludeFilterOrig, java.lang.String[] includeTableNames)
out
- excludeTermLoadingTables
- excludeFilter
- the tables to be excludedpublic void printTableNames(java.io.OutputStream out, java.lang.String formatString)
out
- formatString
- can be null, otherwise a format string like eg. "< %1$s />" see also String.format(String, Object...)
public void printDataSet(java.io.OutputStream out, java.lang.String... includeTableNames)
FlatXmlDataSet
.
printDataSetWithNull(OutputStream)
method instead.
Remember, if you've just called save() or
update(), the data isn't written to the database until the
transaction is committed, and that isn't until after the
method exits. Consequently, if you want to test writing to
the database, either use the @ExpectedDataSet
annotation (that executes after the test is run), or use
CdmTransactionalIntegrationTest
.
out
- the OutputStream to write the XML toincludeTableNames
- the names of tables to print (should be in upper case letters)DataBaseTablePrinter}
,
#printDataSet(OutputStream)}
,
FlatFullXmlWriter
public void printDataSet(java.io.OutputStream out, org.dbunit.dataset.filter.ITableFilterSimple filter)
FlatXmlWriter
.
printDataSetWithNull(OutputStream)
method instead.
Remember, if you've just called save() or
update(), the data isn't written to the database until the
transaction is committed, and that isn't until after the
method exits. Consequently, if you want to test writing to
the database, either use the @ExpectedDataSet
annotation (that executes after the test is run), or use
CdmTransactionalIntegrationTest
.
out
- filter
- DataBaseTablePrinter}
,
#printDataSet(OutputStream)}
,
FlatFullXmlWriter
public void printDtd(java.io.OutputStream out)
FlatDtdDataSet
.out
- The OutputStream to write to.FlatDtdDataSet
public void writeDbUnitDataSetFile(java.lang.String[] includeTableNames) throws java.io.FileNotFoundException
This is the recommended method to create DbUnit data set for integration tests.
This method will create the DbUnit data set file for the specific test class
it has been called from. This happens in full compliance with the DbUnit conventions,
so that the test class will immediately be able to use the
newly created file during the next run.
This also means that using writeDbUnitDataSetFile()
in a test class will overwrite the existing data set file. This is not
considered to be harmful since we expect that any development always is
backed up by a VCS like git, svn and therefore recovery of overwritten
data source files should not cause any problems.
Writes a DbUnit dataset file from the current data base connection using the
FlatFullXmlWriter
which is a variant of the
FlatXmlWriter
. It
inserts '[null]'
place holders for null values instead of skipping them.
see DataBaseTablePrinter
includeTableNames
- java.io.FileNotFoundException
public void writeDbUnitDataSetFile(java.lang.String[] includeTableNames, java.lang.String fileAppendix, boolean withNullValues) throws java.io.FileNotFoundException
DataBaseTablePrinter
includeTableNames
- fileAppendix
- the appendix of the generated DbUnit dataset filejava.io.FileNotFoundException
writeDbUnitDataSetFile(String[])
protected java.lang.String transformSourceToString(javax.xml.transform.Source source) throws javax.xml.transform.TransformerException
javax.xml.transform.TransformerException
protected <T extends CdmBase> T getEntityFromCollection(java.util.Collection<T> cdmBases, java.util.UUID uuid)
protected boolean existsInCollection(java.util.Collection<? extends CdmBase> cdmBases, java.util.UUID uuid)
public abstract void createTestDataSet() throws java.io.FileNotFoundException
CdmTransactionalIntegrationTestExample.createTestDataSet()
an example
implementation of this method is provided.java.io.FileNotFoundException
Copyright © 2007-2020 EDIT. All Rights Reserved.