Java Reference
In-Depth Information
1
Retrieve the
PendingOrder
and restaurant by executing a
SQL
statement
that does an outer join between the
PENDING_ORDER
and
RESTAURANT
tables.
2
Retrieve the
PendingOrder
's line items by executing a
SQL
SELECT
state-
ment that queries the
PENDING_ORDER_LINE_ITEM
table.
3
If the
PendingOrder
has a restaurant, retrieve its menu items by executing
a
SQL
SELECT
statement that retrieves the menu items from the
MENU_ITEM
table.
The
findPendingOrder()
method can load a
PendingOrder
by calling
SqlMapCli-
entTemplate.queryForObject()
with the name of the
SELECT
statement that que-
ries the
PENDING_ORDER
table and the pending order
ID
arguments. Moreover,
because i
BATIS
can be configured to execute queries that retrieve related objects,
that call to
queryForObject()
can execute additional
SELECT
statements that
retrieve the line items and menu items. As a result,
findPendingOrder()
only
needs a single test.
The test shown in listing 9.5 uses a mock
SqlMapClientTemplate
. It calls
find-
PendingOrder()
with a pending order
ID
of
10
and verifies that it calls
queryForOb-
ject()
with
findPendingOrder
as the statement name and
10
as arguments. The
test also verifies that
findPendingOrder()
returns the object that was returned by
queryForObject()
.
Listing 9.5
PendingOrderDAOIBatisImplMockTests
public class PendingOrderDAOIBatisImplMockTests extends
MockObjectTestCase {
private Mock mockSqlMapClientTemplate;
private PendingOrderDAOIBatisImpl dao;
private PendingOrderDTO pendingOrder;
protected void setUp() throws Exception {
super.setUp();
mockSqlMapClientTemplate =
new Mock(SqlMapClientTemplate.class);
SqlMapClientTemplate sqlMapClientTemplate =
(SqlMapClientTemplate) mockSqlMapClientTemplate.proxy();
pendingOrder = new PendingOrderDTO();
B
Creates mock objects
dao = new PendingOrderDAOIBatisImpl(sqlMapClientTemplate);
}
public void testFindPendingOrder() {
Search WWH ::
Custom Search