use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class CallbacksTest method testPostUpdateCollection.
@Test
@FailureExpected(reason = "collection change does not trigger an event", jiraKey = "EJB-288")
public void testPostUpdateCollection(EntityManagerFactoryScope scope) {
scope.inEntityManager(entityManager -> {
try {
// create a cat
Cat cat = new Cat();
cat.setLength(23);
cat.setAge(2);
cat.setName("Beetle");
cat.setDateOfBirth(new Date());
entityManager.getTransaction().begin();
entityManager.persist(cat);
entityManager.getTransaction().commit();
// assert it is persisted
List ids = Cat.getIdList();
Object id = Cat.getIdList().get(ids.size() - 1);
assertNotNull(id);
// add a kitten to the cat - triggers PostCollectionRecreateEvent
int postVersion = Cat.postVersion;
entityManager.getTransaction().begin();
Kitten kitty = new Kitten();
kitty.setName("kitty");
List kittens = new ArrayList<Kitten>();
kittens.add(kitty);
cat.setKittens(kittens);
entityManager.getTransaction().commit();
assertEquals(postVersion + 1, Cat.postVersion, "Post version should have been incremented.");
Kitten tom = new Kitten();
tom.setName("Tom");
// add another kitten - triggers PostCollectionUpdateEvent.
postVersion = Cat.postVersion;
entityManager.getTransaction().begin();
cat.getKittens().add(tom);
entityManager.getTransaction().commit();
assertEquals(postVersion + 1, Cat.postVersion, "Post version should have been incremented.");
// delete a kitty - triggers PostCollectionUpdateEvent
postVersion = Cat.postVersion;
entityManager.getTransaction().begin();
cat.getKittens().remove(tom);
entityManager.getTransaction().commit();
assertEquals(postVersion + 1, Cat.postVersion, "Post version should have been incremented.");
} catch (Exception e) {
if (entityManager.getTransaction().isActive()) {
entityManager.getTransaction().rollback();
}
throw e;
}
});
}
use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class PersistentSetTest method testCompositeElementCollectionDirtyChecking.
@Test
@FailureExpected(jiraKey = "HHH-2485")
public void testCompositeElementCollectionDirtyChecking(SessionFactoryScope scope) {
Container c = new Container("p1");
scope.inTransaction(session -> {
Container.Content c1 = new Container.Content("c1");
c.getContents().add(c1);
session.save(c);
});
CollectionStatistics stats = scope.getSessionFactory().getStatistics().getCollectionStatistics(Container.class.getName() + ".contents");
long recreateCount = stats.getRecreateCount();
long updateCount = stats.getUpdateCount();
scope.inTransaction(session -> {
Container c1 = session.get(Container.class, c.getId());
assertEquals(1, c1.getContents().size());
});
assertEquals(1, c.getContents().size());
assertEquals(recreateCount, stats.getRecreateCount());
assertEquals(updateCount, stats.getUpdateCount());
scope.inTransaction(session -> {
Container c1 = session.get(Container.class, c.getId());
assertEquals(1, c1.getContents().size());
session.delete(c1);
});
}
use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class ComponentTest method testComponentQueryMethodNoParensFailureExpected.
@Test
@RequiresDialect(value = SybaseASEDialect.class)
@FailureExpected(jiraKey = "HHH-3150")
public void testComponentQueryMethodNoParensFailureExpected() {
// Sybase should translate "current_timestamp" in HQL to "getdate()";
// This fails currently due to HHH-3510. The following test should be
// deleted and testComponentQueries() should be updated (as noted
// in that test case) when HHH-3510 is fixed.
inTransaction(s -> {
Employee emp = new Employee();
emp.setHireDate(new Date());
emp.setPerson(new Person());
emp.getPerson().setName("steve");
emp.getPerson().setDob(new Date());
s.save(emp);
s.createQuery("from Employee e where e.person = (current_timestamp, 'steve')").list();
s.delete(emp);
});
}
use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class DeleteOneToManyOrphansTest method testOrphanedWhileManagedMergeOwner.
@Test
@TestForIssue(jiraKey = "HHH-9568")
@FailureExpected(jiraKey = "HHH-9568")
public void testOrphanedWhileManagedMergeOwner(EntityManagerFactoryScope scope) {
Long productId = scope.fromTransaction(entityManager -> {
List results = entityManager.createQuery("from Feature").getResultList();
assertEquals(1, results.size());
results = entityManager.createQuery("from Product").getResultList();
assertEquals(1, results.size());
Product product = (Product) results.get(0);
assertEquals(1, product.getFeatures().size());
product.getFeatures().clear();
entityManager.merge(product);
return product.getId();
});
scope.inTransaction(entityManager -> {
Product _product = entityManager.find(Product.class, productId);
assertEquals(0, _product.getFeatures().size());
List results = entityManager.createQuery("from Feature").getResultList();
assertEquals(0, results.size());
results = entityManager.createQuery("from Product").getResultList();
assertEquals(1, results.size());
});
}
use of org.hibernate.testing.orm.junit.FailureExpected in project hibernate-orm by hibernate.
the class DeleteOneToManyOrphansTest method testReplacedWhileManaged.
@Test
@TestForIssue(jiraKey = "HHH-9568")
@FailureExpected(jiraKey = "HHH-9568")
public void testReplacedWhileManaged(EntityManagerFactoryScope scope) {
Long featureNewId = scope.fromTransaction(entityManager -> {
List results = entityManager.createQuery("from Feature").getResultList();
assertEquals(1, results.size());
results = entityManager.createQuery("from Product").getResultList();
assertEquals(1, results.size());
Product product = (Product) results.get(0);
assertEquals(1, product.getFeatures().size());
// Replace with a new Feature instance
product.getFeatures().remove(0);
Feature featureNew = new Feature();
featureNew.setName("Feature 2");
featureNew.setProduct(product);
product.getFeatures().add(featureNew);
entityManager.persist(featureNew);
return featureNew.getId();
});
scope.inTransaction(entityManager -> {
List results = entityManager.createQuery("from Feature").getResultList();
assertEquals(1, results.size());
Feature featureQueried = (Feature) results.get(0);
assertEquals(featureNewId, featureQueried.getId());
results = entityManager.createQuery("from Product").getResultList();
assertEquals(1, results.size());
Product productQueried = (Product) results.get(0);
assertEquals(1, productQueried.getFeatures().size());
assertEquals(featureQueried, productQueried.getFeatures().get(0));
});
}
Aggregations