01: /*
02: * User: Michael Rettig
03: * Date: Sep 16, 2002
04: * Time: 10:28:42 PM
05: */
06: package net.sourceforge.jaxor.example.tests;
07:
08: import net.sourceforge.jaxor.EntityRow;
09: import net.sourceforge.jaxor.JaxorContextImpl;
10: import net.sourceforge.jaxor.MetaRow;
11: import net.sourceforge.jaxor.api.FieldAdapter;
12: import net.sourceforge.jaxor.api.JaxorContext;
13: import net.sourceforge.jaxor.example.Money;
14: import net.sourceforge.jaxor.example.domain.*;
15:
16: import java.util.List;
17:
18: public class OrdersFinderTest extends TableTestCase {
19:
20: protected MetaRow getRow() {
21: return new OrdersMetaRow();
22: }
23:
24: public void testDefaultValue() {
25: assertEquals(Money.ZERO, OrdersFinder.newInstance(new Long(1),
26: new Long(2)).getSalesTax());
27: }
28:
29: public void testInsertAndFind() {
30: assertFalse(OrdersFinder.entityExists(new Long(1), new Long(1)));
31: OrdersEntity ent = ObjectFactory.createOrder(new Long(1),
32: new Long(1));
33: assertTrue(OrdersFinder.entityExists(new Long(1), new Long(1)));
34: commit();
35: assertTrue(OrdersFinder.entityExists(new Long(1), new Long(1)));
36: OrderListImpl orderList = OrdersFinder.selectAll();
37: assertEquals(1, orderList.size());
38: assertEquals(1, OrdersFinder
39: .selectByCustomerIdList(new Long(1)).size());
40: assertEquals(ent.getOrderTotal(), orderList.getOrdersTotal());
41: }
42:
43: public void testFindByMoney() {
44: OrdersEntity ent = ObjectFactory.createOrder(new Long(1),
45: new Long(1));
46: Money money = new Money("5.00");
47: ent.setSalesTax(money);
48: commit();
49: assertEquals(1, OrdersFinder.selectBySalesTaxList(money).size());
50: }
51:
52: public void testEntityRow() {
53: OrdersEntity ent = ObjectFactory.createOrder(new Long(1),
54: new Long(1));
55: commit();
56: OrdersEntity order = OrdersFinder.selectByPrimaryKey(
57: new Long(1), new Long(1));
58: EntityRow row = order.getFields();
59: FieldAdapter field = row.getField(new OrdersMetaRow()
60: .getDescription().getColumn());
61: assertEquals(order.getDescription(), field.getValue());
62: }
63:
64: public void testNoSession() {
65: ObjectFactory.createOrder(new Long(1), new Long(1));
66: commit();
67: JaxorContext context = new JaxorContextImpl(getJaxor()
68: .getConnection());
69: OrdersFinderBase finder = new OrdersFinderBase(context);
70: OrdersEntity order = finder.selectByCustomerId(new Long(1));
71: Money orderTotal = order.getOrderTotal();
72: }
73:
74: public void testResultSet() {
75: checkResults(OrdersFinder.selectByCustomerIdResultSet(new Long(
76: 1)), 0);
77: ObjectFactory.createOrder(new Long(1), new Long(1));
78: ObjectFactory.createOrder(new Long(2), new Long(1));
79: commit();
80: checkResults(OrdersFinder.selectByCustomerIdResultSet(new Long(
81: 1)), 2);
82: }
83:
84: private void checkResults(OrdersResultSet rs, int count) {
85: int c = 0;
86: while (rs.hasNext()) {
87: assertNotNull(rs.next());
88: c++;
89: }
90: rs.close();
91: assertEquals(count, c);
92: }
93: }
|