use of com.haulmont.cuba.core.sys.listener.EntityListenerManager in project cuba by cuba-platform.
the class EntityListenerTest method setUp.
@Before
public void setUp() throws Exception {
persistence = cont.persistence();
metadata = cont.metadata();
QueryRunner runner = new QueryRunner(cont.persistence().getDataSource());
runner.update("delete from SYS_SERVER");
listenerBean = AppBeans.get("cuba_TestListenerBean");
listenerBean.events.clear();
detachAttachListener = AppBeans.get("cuba_TestDetachAttachListener");
detachAttachListener.events.clear();
TestListener.events.clear();
TestUserEntityListener.events.clear();
entityListenerManager = AppBeans.get(EntityListenerManager.class);
entityListenerManager.addListener(User.class, TestUserEntityListener.class);
entityListenerManager.addListener(Server.class, TestListener.class);
entityListenerManager.addListener(Server.class, "cuba_TestListenerBean");
entityListenerManager.addListener(Server.class, "cuba_TestDetachAttachListener");
entityListenerManager.addListener(Server.class, "cuba_TestListenerUsingEntityManager");
}
use of com.haulmont.cuba.core.sys.listener.EntityListenerManager in project cuba by cuba-platform.
the class CascadeDeleteTest method testEntityListenerOnCascadeDelete.
@Test
public void testEntityListenerOnCascadeDelete() throws Exception {
EntityListenerManager entityListenerManager = AppBeans.get(EntityListenerManager.class);
entityListenerManager.addListener(CascadeEntity.class, DeleteCascadeEntityListener.class);
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.persistence().getEntityManager();
CascadeEntity loadedSecond = em.find(CascadeEntity.class, second.getId());
em.find(CascadeEntity.class, third.getId());
em.remove(loadedSecond);
tx.commit();
}
entityListenerManager.removeListener(CascadeEntity.class, DeleteCascadeEntityListener.class);
assertEquals(2, DeleteCascadeEntityListener.deletedEvents.size());
assertTrue(DeleteCascadeEntityListener.deletedEvents.contains(second.getId().toString()));
assertTrue(DeleteCascadeEntityListener.deletedEvents.contains(third.getId().toString()));
}
use of com.haulmont.cuba.core.sys.listener.EntityListenerManager in project cuba by cuba-platform.
the class CascadeDeleteTest method testEntityListenerOnUpdate.
@Test
public void testEntityListenerOnUpdate() throws Exception {
EntityListenerManager entityListenerManager = AppBeans.get(EntityListenerManager.class);
entityListenerManager.addListener(CascadeEntity.class, UpdateCascadeEntityListener.class);
try (Transaction tx = cont.persistence().createTransaction()) {
EntityManager em = cont.persistence().getEntityManager();
CascadeEntity loadedThird = em.find(CascadeEntity.class, third.getId());
CascadeEntity loadedSecond = em.find(CascadeEntity.class, second.getId());
loadedThird.setName("third#1");
tx.commit();
}
entityListenerManager.removeListener(CascadeEntity.class, UpdateCascadeEntityListener.class);
assertEquals(2, UpdateCascadeEntityListener.updatedEvents.size());
assertTrue(UpdateCascadeEntityListener.updatedEvents.contains(second.getId().toString()));
assertTrue(UpdateCascadeEntityListener.updatedEvents.contains(third.getId().toString()));
}
Aggregations