Connection properties can also be specified in an external file. This is useful when the same tests should run in different environments against different databases. The properties are specified as the value of the extern attribute of the connection element. The property can be specified either as a relative or absolute file path, or as a resource in the application classpath. Property files can either contain properties to build a Connection using JDBC or look up a DataSource using JNDI. Here are some examples:
To set up an external JDBC connection, the properties file must contain the following:
#
# etc/external-jdbc-connection.properties
#
sqlunit.driver = net.sourceforge.sqlunit.test.mock.SQLUnitMockDriver
sqlunit.url = jdbc:mock:net.sourceforge.sqlunit.test.mock.SQLUnitMockDatabase
sqlunit.user =
sqlunit.password =
|
To set up an external JNDI connection, the properties file must contain the following name-value pairs:
#
# etc/external-jndi-connection.properties
#
sqlunit.datasource = jdbc/mockDSN
sqlunit.jndi.java.naming.factory.initial = net.sourceforge.sqlunit.test.mock.MockInitialContextFactory
|
The connection element to point to a properties file as a file name would look like this:
<connection connection-id="5" extern="etc/external-jdbc-connection.properties" />
|
To specify the properties file as a resource, it must be in the classpath and the connection element will look like this:
<connection connection-id="7" extern="external-jdbc-connection" />
|