Java Reference
In-Depth Information
List differences = new ArrayList();
for (int i = 0; i < script.length; i++) {
String line = script[i];
if (line.indexOf("add constraint")
== -1)
differences.add(line);
}
return differences;
}
Removes unimportant
commands
protected Configuration getConfiguration()
throws HibernateException {
…
return cfg;
}
}
The
assertDatabaseSchema()
method first calls
Configuration.generateSchema-
UpdateScript()
to generate the script. It then finds any significant differences by
ignoring
DDL
commands to add constraints. It fails if it encounters any
DDL
com-
mands that add tables or columns.
HibernatePersistenceTests
In addition to
HibernateMappingTests
and
HibernateSchemaTests
,
ORMU
nit
defines the
HibernatePersistenceTests
class, which extends
JU
nit
TestCase
and
makes it easier to write tests for persistent objects. It defines
setUp()
and
tear-
Down()
methods that implement the boilerplate code of a Hibernate persistence
test and provides methods for manipulating persistent data and managing trans-
actions, including:
■
doInTransaction()
: Executes the callback method within a Hibernate trans-
action and ensures that the same
Session
is used throughout. It does this
using a Spring
TransactionTemplate
that is configured to use a
Hibernate-
TransactionManager
.
■
save()
: Saves an object by calling
HibernateTemplate.save()
.
■
load()
: Loads a persistent object by calling
HibernateTemplate.load()
.
delete()
: Deletes a persistent object by calling
HibernateTemplate.delete()
.
■
See this topic's online source code for the details of the class. Let's now look at
some tests that use
ORMU
nit.
Search WWH ::
Custom Search