use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class C3P0ConnectionProviderTest method testIsolationPropertyCouldBeEmpty.
@Test
@TestForIssue(jiraKey = "HHH-9498")
public void testIsolationPropertyCouldBeEmpty() {
C3P0ConnectionProvider provider = new C3P0ConnectionProvider();
try {
Properties configuration = new Properties();
configuration.setProperty(Environment.ISOLATION, "");
provider.configure(configuration);
} finally {
provider.stop();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class JdbcCompatibilityTest method testJdbc42.
@Test
@TestForIssue(jiraKey = "HHH-11308")
public void testJdbc42() {
doInHibernate(this::sessionFactory, session -> {
for (int i = 0; i < 5; i++) {
IrrelevantEntity entity = new IrrelevantEntity();
entity.setName(getClass().getName());
session.persist(entity);
}
session.flush();
session.doWork(connection -> {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("DELETE FROM IrrelevantEntity");
assertEquals(5, statement.getLargeUpdateCount());
}
});
});
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class StatementCacheTest method testStatementCaching.
@Test
@TestForIssue(jiraKey = "HHH-7193")
public void testStatementCaching() {
Session session = openSession();
session.beginTransaction();
//save 2 new entities, one valid, one invalid (neither should be persisted)
IrrelevantEntity irrelevantEntity = new IrrelevantEntity();
irrelevantEntity.setName("valid 1");
session.save(irrelevantEntity);
//name is required
irrelevantEntity = new IrrelevantEntity();
session.save(irrelevantEntity);
try {
session.flush();
Assert.fail("Validation exception did not occur");
} catch (Exception e) {
//this is expected roll the transaction back
session.getTransaction().rollback();
}
session.close();
session = openSession();
session.beginTransaction();
//save a new entity and commit it
irrelevantEntity = new IrrelevantEntity();
irrelevantEntity.setName("valid 2");
session.save(irrelevantEntity);
session.flush();
session.getTransaction().commit();
session.close();
//only one entity should have been inserted to the database (if the statement in the cache wasn't cleared then it would have inserted both entities)
session = openSession();
session.beginTransaction();
Criteria criteria = session.createCriteria(IrrelevantEntity.class);
List results = criteria.list();
session.getTransaction().commit();
session.close();
Assert.assertEquals(1, results.size());
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class CollectionBinderTest method testAssociatedClassException.
@Test
@TestForIssue(jiraKey = "HHH-10106")
public void testAssociatedClassException() throws SQLException {
final Collection collection = mock(Collection.class);
final Map persistentClasses = mock(Map.class);
final XClass collectionType = mock(XClass.class);
final MetadataBuildingContext buildingContext = mock(MetadataBuildingContext.class);
final InFlightMetadataCollector inFly = mock(InFlightMetadataCollector.class);
final PersistentClass persistentClass = mock(PersistentClass.class);
final Table table = mock(Table.class);
when(buildingContext.getMetadataCollector()).thenReturn(inFly);
when(persistentClasses.get(null)).thenReturn(null);
when(collection.getOwner()).thenReturn(persistentClass);
when(collectionType.getName()).thenReturn("List");
when(persistentClass.getTable()).thenReturn(table);
when(table.getName()).thenReturn("Hibernate");
CollectionBinder collectionBinder = new CollectionBinder(false) {
@Override
protected Collection createCollection(PersistentClass persistentClass) {
return null;
}
{
final PropertyHolder propertyHolder = Mockito.mock(PropertyHolder.class);
when(propertyHolder.getClassName()).thenReturn(CollectionBinderTest.class.getSimpleName());
this.propertyName = "abc";
this.propertyHolder = propertyHolder;
}
};
String expectMessage = "Association [abc] for entity [CollectionBinderTest] references unmapped class [List]";
try {
collectionBinder.bindOneToManySecondPass(collection, persistentClasses, null, collectionType, false, false, buildingContext, null);
} catch (MappingException e) {
assertEquals(expectMessage, e.getMessage());
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class ConnectionCreatorTest method testBadUrl.
@Test
@TestForIssue(jiraKey = "HHH-8621")
public void testBadUrl() throws Exception {
DriverConnectionCreator connectionCreator = new DriverConnectionCreator((Driver) Class.forName("org.h2.Driver").newInstance(), new StandardServiceRegistryImpl(true, new BootstrapServiceRegistryImpl(), Collections.<StandardServiceInitiator>emptyList(), Collections.<ProvidedService>emptyList(), Collections.emptyMap()) {
@Override
@SuppressWarnings("unchecked")
public <R extends Service> R getService(Class<R> serviceRole) {
if (JdbcServices.class.equals(serviceRole)) {
// return a new, not fully initialized JdbcServicesImpl
return (R) new JdbcServicesImpl();
}
return super.getService(serviceRole);
}
}, "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat", new Properties(), false, null);
try {
Connection conn = connectionCreator.createConnection();
conn.close();
fail("Expecting the bad Connection URL to cause an exception");
} catch (JDBCConnectionException expected) {
}
}
Aggregations