Search in sources :

Example 1 with ModelServiceEventNotifier

use of com.openmeap.model.event.notifier.ModelServiceEventNotifier in project OpenMEAP by OpenMEAP.

the class ModelManagerImplTest method testFireEventHandlers.

@Test
public void testFireEventHandlers() throws InvalidPropertiesException, PersistenceException {
    List<ModelServiceEventNotifier> handlers = new ArrayList<ModelServiceEventNotifier>();
    class MockUpdateNotifier extends AbstractModelServiceEventNotifier<ModelEntity> {

        public Boolean eventFired = false;

        public Boolean getEventFired() {
            return eventFired;
        }

        @Override
        public Boolean notifiesFor(ModelServiceOperation operation, ModelEntity payload) {
            return true;
        }

        @Override
        public <E extends Event<ModelEntity>> void onInCommitAfterCommit(E event, List<ProcessingEvent> events) throws EventNotificationException {
            eventFired = true;
        }
    }
    ;
    handlers.add(new MockUpdateNotifier());
    modelManager.setEventNotifiers(handlers);
    Application app = modelManager.getModelService().findByPrimaryKey(Application.class, 1L);
    try {
        modelManager.begin().addModify(app, null);
        modelManager.commit();
    } catch (Exception e) {
        modelManager.rollback();
    }
    Assert.assertTrue(((MockUpdateNotifier) modelManager.getEventNotifiers().toArray()[0]).getEventFired());
}
Also used : ArrayList(java.util.ArrayList) AbstractModelServiceEventNotifier(com.openmeap.model.event.notifier.AbstractModelServiceEventNotifier) ModelServiceEventNotifier(com.openmeap.model.event.notifier.ModelServiceEventNotifier) PersistenceException(javax.persistence.PersistenceException) EventNotificationException(com.openmeap.event.EventNotificationException) AbstractModelServiceEventNotifier(com.openmeap.model.event.notifier.AbstractModelServiceEventNotifier) ProcessingEvent(com.openmeap.event.ProcessingEvent) Event(com.openmeap.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) Application(com.openmeap.model.dto.Application) Test(org.junit.Test)

Aggregations

Event (com.openmeap.event.Event)1 EventNotificationException (com.openmeap.event.EventNotificationException)1 ProcessingEvent (com.openmeap.event.ProcessingEvent)1 Application (com.openmeap.model.dto.Application)1 AbstractModelServiceEventNotifier (com.openmeap.model.event.notifier.AbstractModelServiceEventNotifier)1 ModelServiceEventNotifier (com.openmeap.model.event.notifier.ModelServiceEventNotifier)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PersistenceException (javax.persistence.PersistenceException)1 Test (org.junit.Test)1