use of org.eclipse.persistence.testing.models.aggregate.AggregateEventListener in project eclipselink by eclipse-ee4j.
the class AggregateEventTestCase method test.
@Override
public void test() {
DatabaseSession session = (DatabaseSession) getSession();
this.listener = new AggregateEventListener();
(session.getProject().getDescriptors().get(AddressDescription.class)).getEventManager().addListener(this.listener);
UnitOfWork uow = session.acquireUnitOfWork();
Employee emp = Employee.example1();
Employee empClone = (Employee) uow.registerObject(emp);
uow.commitAndResume();
Vector events = this.listener.getEvents();
if (events.size() != 3) {
// one for the preInsert and One for thePostInsert and postWrite
throw new TestErrorException("The aggregate events failed to fire");
} else {
if ((!(((DescriptorEvent) events.firstElement()).getEventCode() == DescriptorEventManager.PreInsertEvent)) || (!(((DescriptorEvent) events.elementAt(2)).getEventCode() == DescriptorEventManager.PostWriteEvent)) || (!(((DescriptorEvent) events.elementAt(1)).getEventCode() == DescriptorEventManager.PostInsertEvent))) {
throw new TestErrorException("The appropriate aggregate events failed to fire");
} else {
if (((DescriptorEvent) events.firstElement()).getSource().getClass() != AddressDescription.class) {
throw new TestErrorException("The wrong object was passed into the event");
}
}
}
events.removeAllElements();
empClone.setFirstName("Douglas");
empClone.getAddressDescription().getPeriodDescription().getPeriod().setEndDate(new java.sql.Date(System.currentTimeMillis()));
uow.commit();
events = this.listener.getEvents();
if (events.size() != 3) {
// one for the preUpdate and One for the PostUpdate and post Write
throw new TestErrorException("The appropriate aggregate events failed to fire");
} else {
if ((!(((DescriptorEvent) events.firstElement()).getEventCode() == DescriptorEventManager.PreUpdateEvent)) || (!(((DescriptorEvent) events.elementAt(2)).getEventCode() == DescriptorEventManager.PostWriteEvent)) || (!(((DescriptorEvent) events.elementAt(1)).getEventCode() == DescriptorEventManager.PostUpdateEvent))) {
throw new TestErrorException("The aggregate events failed to fire");
}
}
events.removeAllElements();
session.deleteObject(emp);
events = this.listener.getEvents();
if (events.size() != 2) {
// one for the preDelete and One for the Postdelete
throw new TestErrorException("The appropriate aggregate events failed to fire");
} else {
if ((!(((DescriptorEvent) events.firstElement()).getEventCode() == DescriptorEventManager.PreDeleteEvent)) || (!(((DescriptorEvent) events.elementAt(1)).getEventCode() == DescriptorEventManager.PostDeleteEvent))) {
throw new TestErrorException("The aggregate events failed to fire");
}
}
}
Aggregations