Java Reference
In-Depth Information
JDO does not define a standard way to access the
O/R
mapping, and so each method
delegates to a vendor-specific implementation of
JDOMappingTestsStrategy
:
public abstract class JDOMappingTests extends TestCase {
JDOMappingTestsStrategy strategy;
protected void assertClassMapped(Class type, String table) {
strategy.assertClassMapping(type, table);
}
protected void assertAllFieldsMapped() {
strategy.assertAllFieldsMapped();
}
…
}
Let's now look at
JDOSchemaTests
, which also delegates to a
JDOMappingTests-
Strategy
.
Overview of JDOSchemaTests
In addition to testing the
O/R
mapping, you must verify that the database schema
matches the mapping.
JDOSchemaTests
is a base class for writing this kind of test.
It defines an
assertDatabaseSchema()
method, which fails if the mapping refer-
ences tables or columns that are missing from the database schema. Because the
JDO
specification does not provide a standard
API
for doing this,
JDOSchemaTests
delegates to vendor-specific implementation of the
JDOMappingTestsStrategy
:
public class JDOSchemaTests extends TestCase {
JDOMappingTestsStrategy strategy;
protected void assertDatabaseSchema() throws Exception {
strategy.assertDatabaseSchema();
}
…
}
The
assertDatabaseSchema()
method simply delegates to the corresponding
method defined by the
JDOMappingTestsStrategy
. Let's see how this works.
JPOXMappingStrategy
ORMU
nit encapsulates the vendor-specific
API
s behind the
JDOMappingTests-
Strategy
interface. There is a separate implementation of this interface for
each
JDO
implementation. Listing 5.1 shows an excerpt from the
JPOX
implemen-
tation of
JDOMappingStrategy
. The methods that make assertions about the
O/R
mapping use
JPOX'
s metadata classes. They call the
JPOX
MetaDataParser
, which
Search WWH ::
Custom Search