Java Reference
In-Depth Information
BasicResultMapping idMapping =
findBasicResultMapping(
bbbbbbb
b
➥
"pendingOrderId");
assertEquals("PENDING_ORDER_ID",
idMapping
.getColumnName());
Verifies
pendingOrderId
property
BasicResultMapping lineItemsMapping =
findBasicResultMapping("lineItems");
assertEquals("PENDING_ORDER_ID",
lineItemsMapping.getColumnName());
assertEquals("findLineItems",
lineItemsMapping
.getStatementName());
}
Verifies lineItems
property
private BasicResultMapping findBasicResultMapping(
String propertyName) {
for (int i = 0; i < resultMappings.length; i++) {
ResultMapping mapping = resultMappings[i];
if (mapping.getPropertyName().equals(
bbbb
propertyName)) {
return (BasicResultMapping) mapping;
}
}
fail("no mapping for property: "
+ propertyName);
return null;
}
…
}
This test verifies that the
findOrders
mapped statement takes a string parameter,
and then verifies that the result map creates a
PendingOrderDTO
. Next, it checks
that the
pendingOrderId
property is set to the
PENDING_ORDER
column, and that the
lineItems
property is set to the result of executing a nested statement called
findLineItems
.
These kinds of tests are easy to write and are a good way of testing the result
maps. You still need to test the
SQL
statements and verify that the parameters are
substituted correctly into the
SQL
statement.
Each one of these testing strategies makes different trade-offs between devel-
opment time, execution time, and effectiveness. Which option you should choose
depends primarily on how much time you are willing to invest in testing and the
likelihood of bugs. Unfortunately, I've found that writing database-level tests for
DAO
s that use
SQL
to be significantly more difficult and time consuming than
writing tests for repositories that use an
ORM
framework. You need to write much
Search WWH ::
Custom Search