Java Reference
In-Depth Information
new FileInputStream(jdoProperties);
System.getProperties().load(fis);
fis.close();
String[] args = metadataFiles;
SchemaTool.validateSchemaTables(args, false);
}
D Verifies the
database schema
}
Let's take a closer look at this listing:
B
The constructor calls createMetaDataManager() , which creates a MetaData-
Manager and iterates through the list of JDO metadata files, calling the Meta-
DataParser on each one.
The assertClassMapping() method gets the class's metadata from the Meta-
DataManager and verifies that it is mapped to the expected table.
The assertDatabaseSchema() method loads the JDO properties file into Sys-
tem.getProperties() . It then calls SchemaTool.validateSchemaTables() ,
passing the list of JDO metadata files. SchemaTool.validateSchemaTables()
uses the system properties to open a database connection and verifies that the
database schema matches the JDO metadata files.
C
D
Now that we have seen how these test classes work, let's look at JDOPersistence-
Tests .
Overview of JDOPersistenceTests
ORMU nit also defines the JDOPersistenceTests class, which extends JU nit
TestCase and makes it easier to write tests for persistent objects. It defines
setUp() and tearDown() methods that implement the boilerplate code of a JDO
persistence test such as configuring a PersistenceManagerFactory and open-
ing and closing a PersistenceManager . It also provides convenience methods
for manipulating persistent data and managing transactions, such as:
doInTransaction() : Executes the callback method within a JDO transac-
tion and ensures that the same PersistenceManager is used throughout. It
does this using a Spring TransactionTemplate that is configured to use a
JdoTransactionManager .
makePersistent() : Saves an object by calling JdoTemplate.makePersis-
tent() .
 
 
 
Search WWH ::




Custom Search