Search in sources :

Example 11 with Employee

use of org.eclipse.persistence.testing.models.aggregate.Employee 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");
        }
    }
}
Also used : Employee(org.eclipse.persistence.testing.models.aggregate.Employee) AggregateEventListener(org.eclipse.persistence.testing.models.aggregate.AggregateEventListener) AddressDescription(org.eclipse.persistence.testing.models.aggregate.AddressDescription) DescriptorEvent(org.eclipse.persistence.descriptors.DescriptorEvent) Vector(java.util.Vector)

Aggregations

Employee (org.eclipse.persistence.testing.models.aggregate.Employee)11 TestSuite (org.eclipse.persistence.testing.framework.TestSuite)6 PopulationManager (org.eclipse.persistence.tools.schemaframework.PopulationManager)6 Client (org.eclipse.persistence.testing.models.aggregate.Client)5 EvaluationClient (org.eclipse.persistence.testing.models.aggregate.EvaluationClient)5 AddressDescription (org.eclipse.persistence.testing.models.aggregate.AddressDescription)4 Language (org.eclipse.persistence.testing.models.aggregate.Language)4 ProjectDescription (org.eclipse.persistence.testing.models.aggregate.ProjectDescription)4 Agent (org.eclipse.persistence.testing.models.aggregate.Agent)3 Builder (org.eclipse.persistence.testing.models.aggregate.Builder)3 Responsibility (org.eclipse.persistence.testing.models.aggregate.Responsibility)3 Employee1 (org.eclipse.persistence.testing.models.aggregate.Employee1)2 Vector (java.util.Vector)1 DescriptorEvent (org.eclipse.persistence.descriptors.DescriptorEvent)1 DeleteObjectTest (org.eclipse.persistence.testing.framework.DeleteObjectTest)1 ReadObjectTest (org.eclipse.persistence.testing.framework.ReadObjectTest)1 UnitOfWorkBasicUpdateObjectTest (org.eclipse.persistence.testing.framework.UnitOfWorkBasicUpdateObjectTest)1 WriteObjectTest (org.eclipse.persistence.testing.framework.WriteObjectTest)1 AggregateEventListener (org.eclipse.persistence.testing.models.aggregate.AggregateEventListener)1 Computer (org.eclipse.persistence.testing.models.aggregate.Computer)1