01: package net.sourceforge.jaxor.example.domain.tests;
02:
03: import net.sourceforge.jaxor.example.tests.MultiTableTestCase;
04: import net.sourceforge.jaxor.example.domain.*;
05:
06: import java.util.List;
07: import java.util.ArrayList;
08:
09: /**
10: * Created By: Mike
11: * Date: Mar 2, 2004
12: * Time: 10:33:10 PM
13: *
14: * Last Checkin: $Author: mrettig $
15: * Date: $Date: 2004/03/07 05:06:03 $
16: * Revision: $Revision: 1.3 $
17: */
18: public class CascadingDeleteTest extends MultiTableTestCase {
19:
20: protected List getRows() {
21: List result = new ArrayList();
22: result.add(new OrdersMetaRow());
23: result.add(new CustomerMetaRow());
24: result.add(new AddressMetaRow());
25: return result;
26: }
27:
28: public void testCascadingDelete() {
29: Long addressId = new Long(111);
30: Long customerId = new Long(222);
31: Long orderId = new Long(333);
32:
33: AddressEntity address = ObjectFactory.createAddress(addressId);
34: CustomerEntity customer = ObjectFactory
35: .createCustomer(customerId);
36: customer.setAddressEntity(address);
37: ObjectFactory.createOrder(orderId, customerId);
38: commit();
39: OrdersEntity order = OrdersFinder.selectByPrimaryKey(orderId,
40: customerId);
41: assertEquals(addressId, order.getCustomerEntity()
42: .getAddressEntity().getAddressId());
43: order.registerCascadingDelete();
44: commit();
45: assertFalse(AddressFinder.entityExists(addressId));
46: assertFalse(CustomerFinder.entityExists(customerId));
47: assertFalse(OrdersFinder.entityExists(orderId, customerId));
48: }
49:
50: public void testRegisteringDeletionTwice() {
51: Long addressId = new Long(111);
52: AddressEntity address = ObjectFactory.createAddress(addressId);
53: commit();
54: address = AddressFinder.selectByAddressId(addressId);
55: assertEquals(0, getJaxor().getUnitOfWork().size());
56: address.registerCascadingDelete();
57: assertEquals(1, getJaxor().getUnitOfWork().size());
58: address.registerCascadingDelete();
59: assertEquals(1, getJaxor().getUnitOfWork().size());
60: commit();
61: assertFalse(AddressFinder.entityExists(addressId));
62: }
63:
64: public void testDeletionBatching() {
65: ObjectFactory.createAddress(new Long(1));
66: ObjectFactory.createAddress(new Long(2));
67: commit();
68: AddressList addressList = AddressFinder.selectAll();
69: assertEquals(2, addressList.size());
70: addressList.deleteAll();
71: commit();
72: assertEquals(0, AddressFinder.selectAll().size());
73: }
74: }
|