use of org.datanucleus.metadata.EventListenerMetaData in project tests by datanucleus.
the class AnnotationPlusXMLTest method testEventListeners.
/**
* Test of Event Listeners
*/
public void testEventListeners() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(WebSite.class.getName(), clr);
// Example callbacks
EventListenerMetaData elmd = cmd1.getListenerForClass(cmd1.getFullClassName());
assertNotNull("Site didnt have its own class registered as an EventListener!", elmd);
assertEquals("Site EventListener has incorrect method for prePersist callback", elmd.getClassName() + ".prePersist", elmd.getMethodNameForCallbackClass(PrePersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".postPersist", elmd.getMethodNameForCallbackClass(PostPersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".load", elmd.getMethodNameForCallbackClass(PostLoad.class.getName()));
assertNull(elmd.getMethodNameForCallbackClass(PreRemove.class.getName()));
// Example listener
elmd = cmd1.getListenerForClass(MyListener.class.getName());
assertNotNull("Site didnt have MyListener registered as an EventListener!", elmd);
assertEquals("Site EventListener has incorrect method for prePersist callback", elmd.getClassName() + ".register", elmd.getMethodNameForCallbackClass(PostPersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".deregister", elmd.getMethodNameForCallbackClass(PreRemove.class.getName()));
assertNull(elmd.getMethodNameForCallbackClass(PrePersist.class.getName()));
}
use of org.datanucleus.metadata.EventListenerMetaData in project tests by datanucleus.
the class AnnotationTest method testEventListeners.
/**
* Test of EventListeners
*/
public void testEventListeners() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(WebSite.class.getName(), clr);
// Example callbacks
EventListenerMetaData elmd = cmd1.getListenerForClass(cmd1.getFullClassName());
assertNotNull("Site didnt have its own class registered as an EventListener!", elmd);
assertEquals("Site EventListener has incorrect method for prePersist callback", elmd.getClassName() + ".prePersist", elmd.getMethodNameForCallbackClass(PrePersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".postPersist", elmd.getMethodNameForCallbackClass(PostPersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".load", elmd.getMethodNameForCallbackClass(PostLoad.class.getName()));
assertNull(elmd.getMethodNameForCallbackClass(PreRemove.class.getName()));
// Example listener
elmd = cmd1.getListenerForClass(MyListener.class.getName());
assertNotNull("Site didnt have MyListener registered as an EventListener!", elmd);
assertEquals("Site EventListener has incorrect method for prePersist callback", elmd.getClassName() + ".register", elmd.getMethodNameForCallbackClass(PostPersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".deregister", elmd.getMethodNameForCallbackClass(PreRemove.class.getName()));
assertNull(elmd.getMethodNameForCallbackClass(PrePersist.class.getName()));
}
use of org.datanucleus.metadata.EventListenerMetaData in project tests by datanucleus.
the class XMLTest method testEventListeners.
/**
* Test of Event Listeners
*/
public void testEventListeners() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(WebSite.class.getName(), clr);
// Example callbacks
EventListenerMetaData elmd = cmd1.getListenerForClass(cmd1.getFullClassName());
assertNotNull("Site didnt have its own class registered as an EventListener!", elmd);
assertEquals("Site EventListener has incorrect method for prePersist callback", elmd.getClassName() + ".prePersist", elmd.getMethodNameForCallbackClass(PrePersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".postPersist", elmd.getMethodNameForCallbackClass(PostPersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".load", elmd.getMethodNameForCallbackClass(PostLoad.class.getName()));
assertNull(elmd.getMethodNameForCallbackClass(PreRemove.class.getName()));
// Example listener
elmd = cmd1.getListenerForClass(MyListener.class.getName());
assertNotNull("Site didnt have MyListener registered as an EventListener!", elmd);
assertEquals("Site EventListener has incorrect method for prePersist callback", elmd.getClassName() + ".register", elmd.getMethodNameForCallbackClass(PostPersist.class.getName()));
assertEquals("Site EventListener has incorrect method for postPersist callback", elmd.getClassName() + ".deregister", elmd.getMethodNameForCallbackClass(PreRemove.class.getName()));
assertNull(elmd.getMethodNameForCallbackClass(PrePersist.class.getName()));
}
Aggregations