@FailureExpected(message = "collection change does not trigger an event", jiraKey = "EJB-288")
public void testPostUpdateCollection() throws Exception {
// create a cat
EntityManager em = getOrCreateEntityManager();
Cat cat = new Cat();
em.getTransaction().begin();
cat.setLength( 23 );
cat.setAge( 2 );
cat.setName( "Beetle" );
cat.setDateOfBirth( new Date() );
em.persist( cat );
em.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;
em.getTransaction().begin();
Kitten kitty = new Kitten();
kitty.setName("kitty");
List kittens = new ArrayList<Kitten>();
kittens.add(kitty);
cat.setKittens(kittens);
em.getTransaction().commit();
assertEquals("Post version should have been incremented.", postVersion + 1, Cat.postVersion);
// add another kitten - triggers PostCollectionUpdateEvent.
postVersion = Cat.postVersion;
em.getTransaction().begin();
Kitten tom = new Kitten();
tom.setName("Tom");
cat.getKittens().add(tom);
em.getTransaction().commit();
assertEquals("Post version should have been incremented.", postVersion + 1, Cat.postVersion);
// delete a kitty - triggers PostCollectionUpdateEvent
postVersion = Cat.postVersion;
em.getTransaction().begin();
cat.getKittens().remove(tom);
em.getTransaction().commit();
assertEquals("Post version should have been incremented.", postVersion + 1, Cat.postVersion);
// delete and recreate kittens - triggers PostCollectionRemoveEvent and PostCollectionRecreateEvent)
postVersion = Cat.postVersion;
em.getTransaction().begin();
cat.setKittens(new ArrayList<Kitten>());
em.getTransaction().commit();
assertEquals("Post version should have been incremented.", postVersion + 2, Cat.postVersion);
em.close();
}