use of org.jboss.tools.hibernate.runtime.v_5_3.internal.test.Foo in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testReadFromJDBC.
@Test
public void testReadFromJDBC() throws Exception {
Connection connection = DriverManager.getConnection("jdbc:h2:mem:test");
Statement statement = connection.createStatement();
statement.execute("CREATE TABLE FOO(id int primary key, bar varchar(255))");
JdbcMetadataConfiguration jdbcMdCfg = new JdbcMetadataConfiguration();
jdbcMdCfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
Metadata metadata = jdbcMdCfg.getMetadata();
Assert.assertNull(metadata);
jdbcMdCfg = new JdbcMetadataConfiguration();
jdbcMdCfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
configurationFacade.readFromJDBC();
metadata = jdbcMdCfg.getMetadata();
Iterator<PersistentClass> iterator = metadata.getEntityBindings().iterator();
PersistentClass persistentClass = (PersistentClass) iterator.next();
Assert.assertEquals("Foo", persistentClass.getClassName());
statement.execute("DROP TABLE FOO");
connection.close();
}
use of org.jboss.tools.hibernate.runtime.v_5_3.internal.test.Foo in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testGetTableMappings.
@Test
public void testGetTableMappings() throws Exception {
Connection connection = DriverManager.getConnection("jdbc:h2:mem:test");
Statement statement = connection.createStatement();
statement.execute("CREATE TABLE FOO(id int primary key, bar varchar(255))");
JdbcMetadataConfiguration jdbcMdCfg = new JdbcMetadataConfiguration();
jdbcMdCfg.setProperty("hibernate.connection.url", "jdbc:h2:mem:test");
configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
Iterator<ITable> iterator = configurationFacade.getTableMappings();
Assert.assertFalse(iterator.hasNext());
jdbcMdCfg.readFromJDBC();
configurationFacade = FACADE_FACTORY.createConfiguration(jdbcMdCfg);
iterator = configurationFacade.getTableMappings();
Table table = (Table) ((IFacade) iterator.next()).getTarget();
Assert.assertEquals("FOO", table.getName());
statement.execute("DROP TABLE FOO");
connection.close();
}
Aggregations