Java Reference
In-Depth Information
getObjectById()
: Loads a persistent object by calling
JdoTemplate
.getObjectById()
.
■
deletePersistent()
: Deletes a persistent object by calling
JdoTemplate
.deletePersistent().
■
These methods make it easier to write tests for persistent objects. See this topic's
online source code for the details of the class.
5.2.2
Testing persistent JDO objects
Now that you have seen an overview of
ORMU
nit's
JDO
classes, we'll look at writing
tests for the
JDO
persistence layer using the testing strategy described in earlier
chapter 4. There are three different sets of tests. The first set of tests verifies we
have correctly implemented the
O/R
mapping, an excerpt of which is shown in
figure 5.3. These tests verify, for example, that the
PendingOrder
class is mapped
to the
PENDING_ORDER
table and that each of its fields is mapped to a column of
that table.
The second set of tests verifies that the database schema matches the
O/R
map-
ping. The tests verify that every table and column referenced by the mapping
exists in the database schema. The third set of tests verifies that persistent pend-
ing orders can be saved, queried, updated, and deleted. The next section explains
how to implement these tests for the
PendingOrder
class.
Verifying the O/R mapping
The first test we must write is one that verifies that the
PendingOrder
class is
mapped correctly to the database. Here is a simple test for the
PendingOrder
class:
public class FoodToGoDomainMappingTests extends JDOMappingTests {
public void testSimple() throws Exception {
assertClassMapped(PendingOrder.class, "PENDING_ORDER");
assertAllFieldsMapped();
}
The test extends the
ORMU
nit class
JDOMappingTests
. It calls
assertClass-
Mapped()
to verify that
PendingOrder
is mapped to the
PENDING_ORDER
table
and then calls
assertAllFields()
to verify that all of
PendingOrder
's fields are
mapped to the database.
This test only verifies that each field is mapped to the database. If you need to
verify that each field is mapped to the correct column, then you can write a more
elaborate test that calls methods such as
assertField()
. Here's an example:
Search WWH ::
Custom Search