01: package net.sourceforge.jaxor.generator.tests;
02:
03: import net.sourceforge.jaxor.example.tests.TableTestCase;
04: import net.sourceforge.jaxor.example.domain.AddressMetaRow;
05: import net.sourceforge.jaxor.example.db.HypersonicContextTestingFactory;
06: import net.sourceforge.jaxor.MetaRow;
07: import net.sourceforge.jaxor.parser.Jaxor;
08: import net.sourceforge.jaxor.parser.Entity;
09: import net.sourceforge.jaxor.parser.Attribute;
10: import net.sourceforge.jaxor.generator.MappingMetaData;
11: import net.sourceforge.jaxor.generator.Sql2JavaMapping;
12:
13: import java.sql.Connection;
14:
15: import org.apache.regexp.RESyntaxException;
16:
17: /**
18: * Created By: Mike
19: * Date: Feb 7, 2004
20: * Time: 2:39:06 PM
21: *
22: * Last Checkin: $Author: mrettig $
23: * Date: $Date: 2004/02/13 05:23:06 $
24: * Revision: $Revision: 1.5 $
25: */
26: public class MappingMetaDataTest extends TableTestCase {
27:
28: protected MetaRow getRow() {
29: return new AddressMetaRow();
30: }
31:
32: public void testCreatingMappedObjects() throws RESyntaxException {
33: //this only works for hypersonic right now, need to figure out schema/catalog for other db's
34: //todo test with other db's
35: if (getTestingContext().getClass() != HypersonicContextTestingFactory.class)
36: return;
37: Connection conn = getConnection();
38: Sql2JavaMapping mappings = new Sql2JavaMapping();
39: MappingMetaData meta = new MappingMetaData(conn, "", "",
40: mappings, "ADDRESS") {
41: protected void log(String msg) {
42: //System.out.println(msg);
43: }
44: };
45: Jaxor[] mappedObjects = meta.getMapped();
46: assertNotNull(mappedObjects);
47: assertEquals(1, mappedObjects.length);
48: final Entity entity = mappedObjects[0].getEntity();
49: assertEquals("Address", entity.getJavaName());
50: assertEquals(1, entity.getPrimaryKey().getKeys().size());
51: final Attribute attribute = (Attribute) entity.getPrimaryKey()
52: .getKeys().get(0);
53: assertEquals("ADDRESS_ID", attribute.getName());
54: assertEquals("Long", attribute.getTypeName());
55: assertFalse(attribute.isNullable());
56: assertTrue(attribute.isPrimaryKey());
57: }
58: }
|