MappingMetaDataTest.java :  » Database-ORM » jaxor-3.5 » net » sourceforge » jaxor » generator » tests » Java Open Source

Java Open Source » Database ORM » jaxor 3.5 
jaxor 3.5 » net » sourceforge » jaxor » generator » tests » MappingMetaDataTest.java
package net.sourceforge.jaxor.generator.tests;

import net.sourceforge.jaxor.example.tests.TableTestCase;
import net.sourceforge.jaxor.example.domain.AddressMetaRow;
import net.sourceforge.jaxor.example.db.HypersonicContextTestingFactory;
import net.sourceforge.jaxor.MetaRow;
import net.sourceforge.jaxor.parser.Jaxor;
import net.sourceforge.jaxor.parser.Entity;
import net.sourceforge.jaxor.parser.Attribute;
import net.sourceforge.jaxor.generator.MappingMetaData;
import net.sourceforge.jaxor.generator.Sql2JavaMapping;

import java.sql.Connection;

import org.apache.regexp.RESyntaxException;

/**
 * Created By:   Mike
 * Date:         Feb 7, 2004
 * Time:         2:39:06 PM
 *
 * Last Checkin: $Author: mrettig $
 * Date:         $Date: 2004/02/13 05:23:06 $
 * Revision:     $Revision: 1.5 $
 */
public class MappingMetaDataTest extends TableTestCase {

    protected MetaRow getRow() {
        return new AddressMetaRow();
    }

    public void testCreatingMappedObjects() throws RESyntaxException {
        //this only works for hypersonic right now, need to figure out schema/catalog for other db's
        //todo test with other db's
        if(getTestingContext().getClass() != HypersonicContextTestingFactory.class)
            return;
        Connection conn = getConnection();
        Sql2JavaMapping mappings = new Sql2JavaMapping();
        MappingMetaData meta = new MappingMetaData(conn, "", "", mappings, "ADDRESS") {
            protected void log(String msg) {
                //System.out.println(msg);
            }
        };
        Jaxor[] mappedObjects = meta.getMapped();
        assertNotNull(mappedObjects);
        assertEquals(1, mappedObjects.length);
        final Entity entity = mappedObjects[0].getEntity();
        assertEquals("Address", entity.getJavaName());
        assertEquals(1, entity.getPrimaryKey().getKeys().size());
        final Attribute attribute = (Attribute) entity.getPrimaryKey().getKeys().get(0);
        assertEquals("ADDRESS_ID", attribute.getName());
        assertEquals("Long", attribute.getTypeName());
        assertFalse(attribute.isNullable());
        assertTrue(attribute.isPrimaryKey());
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.