OpenJPAPersistence.createEntityManagerFactory("TestConv2", "")))
.
getConfiguration().getMetaDataRepositoryInstance();
ClassMetaData meta = repos.getMetaData(RuntimeTest2.class, null, true);
LifecycleEventManager mgr = new LifecycleEventManager();
RuntimeTest2 pc = new RuntimeTest2();
Listener listener = new Listener();
assertFalse(mgr.hasLoadListeners(pc, meta));
assertFalse(mgr.hasStoreListeners(pc, meta));
mgr.addListener(listener, new Class[]{ RuntimeTest1.class });
assertEquals(0, listener.load);
assertEquals(0, listener.store);
assertTrue(mgr.hasLoadListeners(pc, meta));
assertTrue(mgr.hasStoreListeners(pc, meta));
assertFalse(mgr.hasDirtyListeners(pc, meta));
assertFalse(mgr.hasLoadListeners(new RuntimeTest4("foo"), meta));
assertEquals(0, listener.load);
assertEquals(0, listener.store);
Listener listener2 = new Listener();
mgr.addListener(listener2, new Class[]{ RuntimeTest2.class });
assertTrue(mgr.hasLoadListeners(pc, meta));
assertTrue(mgr.hasStoreListeners(pc, meta));
assertFalse(mgr.hasDirtyListeners(pc, meta));
assertFalse(mgr.hasLoadListeners(new RuntimeTest4("foo"), meta));
mgr.fireEvent(pc, meta, LifecycleEvent.AFTER_LOAD);
assertEquals(1, listener.load);
assertEquals(0, listener.store);
assertEquals(1, listener2.load);
assertEquals(0, listener2.store);
mgr.fireEvent(pc, meta, LifecycleEvent.AFTER_LOAD);
assertEquals(2, listener.load);
assertEquals(0, listener.store);
assertEquals(2, listener2.load);
assertEquals(0, listener2.store);
mgr.fireEvent(new RuntimeTest1(), meta, LifecycleEvent.AFTER_LOAD);
assertEquals(3, listener.load);
assertEquals(0, listener.store);
assertEquals(2, listener2.load);
assertEquals(0, listener2.store);
mgr.removeListener(listener2);
assertTrue(mgr.hasLoadListeners(pc, meta));
assertTrue(mgr.hasStoreListeners(pc, meta));
mgr.fireEvent(pc, meta, LifecycleEvent.AFTER_STORE);
assertEquals(3, listener.load);
assertEquals(1, listener.store);
assertEquals(2, listener2.load);
assertEquals(0, listener2.store);
mgr.fireEvent(pc, meta, LifecycleEvent.AFTER_DIRTY);
assertEquals(3, listener.load);
assertEquals(1, listener.store);
mgr.fireEvent(new RuntimeTest4("foo"), meta,
LifecycleEvent.AFTER_STORE);
assertEquals(3, listener.load);
assertEquals(1, listener.store);
mgr.removeListener(listener);
assertFalse(mgr.hasLoadListeners(pc, meta));
assertFalse(mgr.hasStoreListeners(pc, meta));
mgr.fireEvent(pc, meta, LifecycleEvent.AFTER_STORE);
assertEquals(3, listener.load);
assertEquals(1, listener.store);
}