use of org.hibernate.testing.util.jpa.PersistenceUnitInfoAdapter in project hibernate-orm by hibernate.
the class PersistenceUnitOverridesTests method testPassingIntegrationJpaJdbcOverridesForJtaDataSourceElement.
@Test
public // )
void testPassingIntegrationJpaJdbcOverridesForJtaDataSourceElement() {
PersistenceProvider provider = new HibernatePersistenceProvider() {
@Override
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map integrationOverrides) {
return super.createContainerEntityManagerFactory(new DelegatingPersistenceUnitInfo(info) {
// inject a JPA JTA DataSource setting into the PU
final DataSource puDataSource = new DataSourceStub("puDataSource");
@Override
public DataSource getJtaDataSource() {
return puDataSource;
}
}, integrationOverrides);
}
};
final EntityManagerFactory emf = provider.createContainerEntityManagerFactory(new PersistenceUnitInfoAdapter(), // a JTA DataSource (nor the reverse). However, that is a useful thing to support
ConnectionProviderBuilder.getJpaConnectionProviderProperties("db2"));
try {
final Map<String, Object> properties = emf.getProperties();
final Object hibernateJdbcDriver = properties.get(AvailableSettings.URL);
assertThat(hibernateJdbcDriver, notNullValue());
final Object jpaJdbcDriver = properties.get(AvailableSettings.JPA_JDBC_URL);
assertThat((String) jpaJdbcDriver, containsString("db2"));
// see if the values had the affect to adjust the `ConnectionProvider` used
final ConnectionProvider connectionProvider = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(ConnectionProvider.class);
assertThat(connectionProvider, instanceOf(DriverManagerConnectionProviderImpl.class));
} finally {
emf.close();
}
}
use of org.hibernate.testing.util.jpa.PersistenceUnitInfoAdapter in project hibernate-orm by hibernate.
the class PersistenceUnitInfoTests method testJtaDataExposedAsProperty.
@Test
@TestForIssue(jiraKey = "HHH-13432")
public void testJtaDataExposedAsProperty() {
final DataSource puDataSource = new DataSourceStub("puDataSource");
final PersistenceUnitInfoAdapter info = new PersistenceUnitInfoAdapter() {
@Override
public DataSource getJtaDataSource() {
return puDataSource;
}
};
final PersistenceProvider provider = new HibernatePersistenceProvider();
final EntityManagerFactory emf = provider.createContainerEntityManagerFactory(info, Collections.emptyMap());
// first let's check the DataSource used in the EMF...
final ConnectionProvider connectionProvider = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(ConnectionProvider.class);
assertThat(connectionProvider, instanceOf(DatasourceConnectionProviderImpl.class));
final DatasourceConnectionProviderImpl dsCp = (DatasourceConnectionProviderImpl) connectionProvider;
assertThat(dsCp.getDataSource(), is(puDataSource));
// now let's check that it is exposed via the EMF properties
// - again, the spec does not indicate that this should work, but
// it worked this way in previous versions
final Map<String, Object> properties = emf.getProperties();
final Object o = properties.get(AvailableSettings.JPA_JTA_DATASOURCE);
assertEquals(puDataSource, o);
}
use of org.hibernate.testing.util.jpa.PersistenceUnitInfoAdapter in project hibernate-orm by hibernate.
the class PersistenceUnitInfoTests method testNonJtaDataExposedAsProperty.
@Test
@TestForIssue(jiraKey = "HHH-13432")
public void testNonJtaDataExposedAsProperty() {
final DataSource puDataSource = new DataSourceStub("puDataSource");
final PersistenceUnitInfoAdapter info = new PersistenceUnitInfoAdapter() {
@Override
public DataSource getNonJtaDataSource() {
return puDataSource;
}
};
final PersistenceProvider provider = new HibernatePersistenceProvider();
final EntityManagerFactory emf = provider.createContainerEntityManagerFactory(info, Collections.emptyMap());
// first let's check the DataSource used in the EMF...
final ConnectionProvider connectionProvider = emf.unwrap(SessionFactoryImplementor.class).getServiceRegistry().getService(ConnectionProvider.class);
assertThat(connectionProvider, instanceOf(DatasourceConnectionProviderImpl.class));
final DatasourceConnectionProviderImpl dsCp = (DatasourceConnectionProviderImpl) connectionProvider;
assertThat(dsCp.getDataSource(), is(puDataSource));
// now let's check that it is exposed via the EMF properties
// - note : the spec does not indicate that this should work, but
// it worked this way in previous versions
final Object o = emf.getProperties().get(AvailableSettings.JPA_NON_JTA_DATASOURCE);
assertThat(o, is(puDataSource));
}
Aggregations