01: /*
02: * User: mrettig
03: * Date: Aug 1, 2002
04: * Time: 12:02:49 PM
05: */
06: package net.sourceforge.jaxor.tests;
07:
08: import net.sourceforge.jaxor.EntityNotFoundException;
09: import net.sourceforge.jaxor.example.domain.*;
10: import net.sourceforge.jaxor.example.tests.MultiTableTestCase;
11:
12: import java.util.ArrayList;
13: import java.util.List;
14:
15: public class GeneratedCodeTest extends MultiTableTestCase {
16:
17: protected List getRows() {
18: List all = new ArrayList();
19: all.add(new AddressMetaRow());
20: all.add(new CustomerMetaRow());
21: all.add(new OrdersMetaRow());
22: return all;
23: }
24:
25: public void testEntityNotFound() {
26: try {
27: CustomerFinder.selectByPrimaryKey(new Long(1), false);
28: fail("Should not find entity");
29: } catch (EntityNotFoundException expected) {
30: }
31: }
32:
33: public void testFindById() {
34: ObjectFactory.create(new Long(1));
35: commit();
36: CustomerEntity entity = CustomerFinder.selectByPrimaryKey(
37: new Long(1), false);
38: assertEquals(new Long(1), entity.getCustomerId());
39: assertNotNull(entity.getEmail());
40: assertNotNull(entity.getNameFirst());
41: assertNotNull(entity.getNameLast());
42: assertNotNull(entity.getAddressEntity());
43: assertNotNull(entity.getAddressEntity());
44: assertEquals(0, entity.getOrdersList().size());
45: ObjectFactory.createOrder(new Long(1), entity.getCustomerId());
46: commit();
47: entity = CustomerFinder.selectByPrimaryKey(new Long(1), false);
48: assertEquals(1, entity.getOrdersList().size());
49: OrdersEntity order = entity.getOrdersList().get(0);
50: assertEquals(entity, order.getCustomerEntity());
51: }
52:
53: /**
54: * When the address id hasn't been set on the customer, then the getAddressEntity should return null
55: */
56: public void testNullAddress() {
57: ObjectFactory.createCustomer(new Long(1));
58: commit();
59: CustomerEntity entity = CustomerFinder.selectByCustomerId(
60: new Long(1), false);
61: assertNull(entity.getAddressEntity());
62: }
63: }
|