01: package net.sourceforge.jaxor.example.domain.tests;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.jaxor.api.JaxorContext;
05: import net.sourceforge.jaxor.example.db.JaxorContextTestingFactory;
06: import net.sourceforge.jaxor.example.domain.AddressFinder;
07: import net.sourceforge.jaxor.example.domain.AddressFinderBase;
08: import net.sourceforge.jaxor.example.domain.AddressList;
09: import net.sourceforge.jaxor.example.domain.AddressMetaRow;
10: import net.sourceforge.jaxor.example.tests.MultiTableTestCase;
11: import net.sourceforge.jaxor.example.tests.TableMaker;
12:
13: import java.sql.Connection;
14: import java.sql.SQLException;
15:
16: /**
17: * Created By: Mike
18: * Date: Dec 10, 2003
19: * Time: 9:05:03 PM
20: *
21: * Last Checkin: $Author: mrettig $
22: * Date: $Date: 2004/01/21 04:09:51 $
23: * Revision: $Revision: 1.5 $
24: */
25: public class FinderTest extends TestCase {
26:
27: public void testNoContext() {
28: try {
29: AddressFinder.selectAll();
30: } catch (NullPointerException e) {
31: assertEquals(
32: "JaxorContext is not defined. Please set it with JaxorSession.begin",
33: e.getMessage());
34: }
35: }
36:
37: public void testNoContextFindAndUpdate() throws SQLException {
38: JaxorContext context = MultiTableTestCase.JAXOR_Factory
39: .create();
40: Connection connectin = context.getConnection();
41: createIfNeeded(connectin, MultiTableTestCase.JAXOR_Factory);
42: AddressFinderBase finder = new AddressFinderBase(context);
43: AddressList list = finder.findAll();
44: //update values in list
45: context.commit();
46: context.end();
47: //assertTrue(connectin.isClosed());
48: }
49:
50: private void createIfNeeded(Connection connection,
51: JaxorContextTestingFactory fact) {
52: try {
53: TableMaker.createTable(new AddressMetaRow(), connection,
54: fact);
55: } catch (Exception e) {
56: //okay.
57: }
58: }
59: }
|