01: /*
02: * User: Michael Rettig
03: * Date: Sep 1, 2002
04: * Time: 10:55:22 PM
05: */
06: package net.sourceforge.jaxor.example.tests;
07:
08: import net.sourceforge.jaxor.MetaRow;
09: import net.sourceforge.jaxor.example.Money;
10: import net.sourceforge.jaxor.example.MoneyWithCurrency;
11: import net.sourceforge.jaxor.example.domain.ObjectFactory;
12: import net.sourceforge.jaxor.example.domain.OrdersEntity;
13: import net.sourceforge.jaxor.example.domain.OrdersFinder;
14: import net.sourceforge.jaxor.example.domain.OrdersMetaRow;
15:
16: public class AggregateTest extends TableTestCase {
17:
18: protected MetaRow getRow() {
19: return new OrdersMetaRow();
20: }
21:
22: public void testOrder() {
23: OrdersEntity ent = ObjectFactory.createOrder(new Long(123),
24: new Long(1));
25: ent.setEquipmentCost(new MoneyWithCurrency("5.00", "US"));
26: assertEquals("US", ent.getEquipmentCost().getCurrency());
27: assertEquals(new Money("5.00"), ent.getEquipmentCost());
28: ent.setEquipmentCost(new MoneyWithCurrency("6.00", "GBP"));
29: commit();
30: ent = OrdersFinder.selectByPrimaryKey(new Long(123),
31: new Long(1));
32: assertEquals("GBP", ent.getEquipmentCost().getCurrency());
33: assertEquals(new Money("6.00"), ent.getEquipmentCost());
34: }
35:
36: public void testMoneyNull() {
37: OrdersEntity ent = OrdersFinder.newInstance(new Long(234),
38: new Long(1));
39: ent.setOrderNo(new Integer(34));
40: ent.setDescription("desc");
41: ent.setOrderDate(new java.sql.Date(System.currentTimeMillis()));
42: commit();
43: ent = OrdersFinder.selectByPrimaryKey(new Long(234),
44: new Long(1));
45: assertEquals(null, ent.getEquipmentCost());
46: try {
47: assertEquals(null, ent.getEquipmentCost().getCurrency());
48: } catch (NullPointerException e) { /* expected */
49: }
50: assertEquals(Money.ZERO, ent.getSalesTax());
51: }
52:
53: public void testMoneyUpdateNull() {
54: OrdersEntity ent = ObjectFactory.createOrder(new Long(345),
55: new Long(1));
56: commit();
57: ent = OrdersFinder.selectByPrimaryKey(new Long(345),
58: new Long(1));
59: assertEquals("US", ent.getEquipmentCost().getCurrency());
60: assertEquals(new Money("5.00"), ent.getEquipmentCost());
61: ent.setEquipmentCost(null);
62: commit();
63: ent = OrdersFinder.selectByPrimaryKey(new Long(345),
64: new Long(1));
65: assertEquals(null, ent.getEquipmentCost());
66: }
67: }
|