Search in sources :

Example 6 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testSetNamingStrategy.

@Test
public void testSetNamingStrategy() {
    INamingStrategy namingStrategy = FACADE_FACTORY.createNamingStrategy(new DefaultNamingStrategy());
    ConfigurationFacadeImpl facade = (ConfigurationFacadeImpl) configurationFacade;
    assertNotSame(namingStrategy, facade.namingStrategy);
    configurationFacade.setNamingStrategy(namingStrategy);
    assertSame(namingStrategy, facade.namingStrategy);
}
Also used : INamingStrategy(org.jboss.tools.hibernate.runtime.spi.INamingStrategy) DefaultNamingStrategy(org.hibernate.cfg.DefaultNamingStrategy) Test(org.junit.jupiter.api.Test) MetadataHelperTest(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)

Example 7 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testGetMetadata.

@Test
public void testGetMetadata() {
    NativeTestConfiguration nativeConfiguration = new NativeTestConfiguration();
    ConfigurationFacadeImpl nativeFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, nativeConfiguration);
    assertNull(nativeFacade.metadata);
    Metadata nativeMetadata = nativeFacade.getMetadata();
    assertNotNull(nativeMetadata);
    assertSame(nativeMetadata, NativeTestConfiguration.METADATA);
    assertNotNull(nativeFacade.metadata);
    assertSame(nativeFacade.metadata, NativeTestConfiguration.METADATA);
    JdbcMetadataTestConfiguration jdbcConfiguration = new JdbcMetadataTestConfiguration();
    ConfigurationFacadeImpl jdbcFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, jdbcConfiguration);
    assertNull(jdbcFacade.metadata);
    Metadata jdbcMetadata = jdbcFacade.getMetadata();
    assertNotNull(jdbcMetadata);
    assertSame(jdbcMetadata, JdbcMetadataTestConfiguration.METADATA);
    assertNotNull(jdbcFacade.metadata);
    assertSame(jdbcFacade.metadata, JdbcMetadataTestConfiguration.METADATA);
}
Also used : Metadata(org.hibernate.boot.Metadata) Test(org.junit.jupiter.api.Test) MetadataHelperTest(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)

Example 8 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testSetPreferBasicCompositeIds.

@Test
public void testSetPreferBasicCompositeIds() {
    JdbcMetadataConfiguration configuration = new JdbcMetadataConfiguration();
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    // the default is true
    assertTrue(configuration.preferBasicCompositeIds());
    configurationFacade.setPreferBasicCompositeIds(false);
    assertFalse(configuration.preferBasicCompositeIds());
}
Also used : JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.JdbcMetadataConfiguration) Test(org.junit.jupiter.api.Test) MetadataHelperTest(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)

Example 9 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl 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 = new ConfigurationFacadeImpl(FACADE_FACTORY, jdbcMdCfg);
    Iterator<ITable> iterator = configurationFacade.getTableMappings();
    assertFalse(iterator.hasNext());
    jdbcMdCfg.readFromJdbc();
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, jdbcMdCfg);
    iterator = configurationFacade.getTableMappings();
    IFacade facade = (IFacade) iterator.next();
    Table table = (Table) facade.getTarget();
    assertEquals("FOO", table.getName());
    statement.execute("DROP TABLE FOO");
    connection.close();
}
Also used : ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.JdbcMetadataConfiguration) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Test(org.junit.jupiter.api.Test) MetadataHelperTest(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)

Example 10 with ConfigurationFacadeImpl

use of org.jboss.tools.hibernate.runtime.v_6_0.internal.ConfigurationFacadeImpl in project jbosstools-hibernate by jbosstools.

the class ExporterFacadeTest method testSetConfiguration.

@Test
public void testSetConfiguration() throws Exception {
    exporterTarget = new CfgExporter();
    exporterFacade = new ExporterFacadeImpl(FACADE_FACTORY, exporterTarget);
    Properties properties = new Properties();
    Configuration configurationTarget = new Configuration();
    configurationTarget.setProperties(properties);
    ConfigurationFacadeImpl configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configurationTarget);
    exporterFacade.setConfiguration(configurationFacade);
    assertSame(properties, ((CfgExporter) exporterTarget).getCustomProperties());
    Object object = exporterTarget.getProperties().get(ExporterConstants.METADATA_DESCRIPTOR);
    assertNotNull(object);
    assertTrue(object instanceof ConfigurationMetadataDescriptor);
    ConfigurationMetadataDescriptor configurationMetadataDescriptor = (ConfigurationMetadataDescriptor) object;
    Field field = ConfigurationMetadataDescriptor.class.getDeclaredField("configurationFacade");
    field.setAccessible(true);
    object = field.get(configurationMetadataDescriptor);
    assertNotNull(object);
    assertTrue(object instanceof ConfigurationFacadeImpl);
    assertSame(object, configurationFacade);
}
Also used : Field(java.lang.reflect.Field) ConfigurationMetadataDescriptor(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.ConfigurationMetadataDescriptor) Configuration(org.hibernate.cfg.Configuration) CfgExporter(org.hibernate.tool.internal.export.cfg.CfgExporter) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)20 Configuration (org.hibernate.cfg.Configuration)13 PersistentClass (org.hibernate.mapping.PersistentClass)13 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)13 MetadataHelperTest (org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)12 Metadata (org.hibernate.boot.Metadata)8 RootClass (org.hibernate.mapping.RootClass)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Field (java.lang.reflect.Field)5 MetadataSources (org.hibernate.boot.MetadataSources)5 JdbcMetadataConfiguration (org.jboss.tools.hibernate.runtime.v_6_0.internal.util.JdbcMetadataConfiguration)5 HashMap (java.util.HashMap)4 MetadataImpl (org.hibernate.boot.internal.MetadataImpl)4 ConfigurationFacadeImpl (org.jboss.tools.hibernate.runtime.v_5_3.internal.ConfigurationFacadeImpl)3 ConfigurationFacadeImpl (org.jboss.tools.hibernate.runtime.v_5_4.internal.ConfigurationFacadeImpl)3 ConfigurationFacadeImpl (org.jboss.tools.hibernate.runtime.v_5_5.internal.ConfigurationFacadeImpl)3 ConfigurationFacadeImpl (org.jboss.tools.hibernate.runtime.v_5_6.internal.ConfigurationFacadeImpl)3 MockConnectionProvider (org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MockConnectionProvider)3 MockDialect (org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MockDialect)3