Search in sources :

Example 1 with SuccessEvent

use of won.bot.framework.eventbot.event.impl.test.SuccessEvent in project webofneeds by researchstudio-sat.

the class DuplicateMessageURIFailureBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    EventListenerContext ctx = getEventListenerContext();
    EventBus bus = getEventBus();
    // create needs every trigger execution until 2 needs are created
    bus.subscribe(ActEvent.class, new ActionOnEventListener(ctx, new CreateNeedWithFacetsAction(// use a decorator that will cause the same need URI to be used in each create message
    new ConstantNewEventURIDecorator(ctx, "constantMsgURI" + System.currentTimeMillis()), getBotContextWrapper().getNeedCreateListName()), 2));
    // log error if we can create 2 needs
    bus.subscribe(NeedCreatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 2, new MultipleActions(ctx, new LogErrorAction(ctx, "Should not have been able to create 2 needs using message with identical URIs"), new PublishEventAction(ctx, new TestFailedEvent(this, "Should not have been able to create 2 needs with identical URI")))));
    // log success if we could create 1 need
    bus.subscribe(NeedCreatedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: could create one need"), new PublishEventAction(ctx, new SuccessEvent()))));
    // log success if we got an error for 2nd need
    bus.subscribe(NeedCreationFailedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: need creation failed for 2nd need."), new PublishEventAction(ctx, new SuccessEvent()))));
    // when we have 2 SuccessEvents, we're done. Deacivate the needs and signal we're finished
    bus.subscribe(SuccessEvent.class, new ActionOnceAfterNEventsListener(ctx, 2, new MultipleActions(ctx, new LogAction(ctx, "Test passed."), new PublishEventAction(ctx, new TestPassedEvent(this)), new DeactivateAllNeedsAction(ctx))));
    // when we have a FailureEvent, we're done, too. Deacivate the needs and signal we're finished
    bus.subscribe(TestFailedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Test failed."), new DeactivateAllNeedsAction(ctx))));
    // wait for the needDeactivated event, then say we're done.
    bus.subscribe(NeedDeactivatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new SignalWorkDoneAction(ctx, this)));
// TODO: fix: bot runs forever even if test fails.
// TODO: fix: need 1 is not deactivated if test fails.
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) ConstantNewEventURIDecorator(won.bot.integrationtest.failsim.ConstantNewEventURIDecorator) CreateNeedWithFacetsAction(won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction) EventBus(won.bot.framework.eventbot.bus.EventBus) SignalWorkDoneAction(won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction) TestFailedEvent(won.bot.framework.eventbot.event.impl.test.TestFailedEvent) ActionOnFirstNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstNEventsListener) TestPassedEvent(won.bot.framework.eventbot.event.impl.test.TestPassedEvent) SuccessEvent(won.bot.framework.eventbot.event.impl.test.SuccessEvent) DeactivateAllNeedsAction(won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsAction) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener)

Example 2 with SuccessEvent

use of won.bot.framework.eventbot.event.impl.test.SuccessEvent in project webofneeds by researchstudio-sat.

the class DuplicateNeedURIFailureBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    EventListenerContext ctx = getEventListenerContext();
    EventBus bus = getEventBus();
    // create needs every trigger execution until 2 needs are created
    bus.subscribe(ActEvent.class, new ActionOnEventListener(ctx, new CreateNeedWithFacetsAction(// use a decorator that will cause the same need URI to be used in each create message
    new ConstantNewNeedURIDecorator(ctx, "constantNeedURI" + System.currentTimeMillis()), getBotContextWrapper().getNeedCreateListName()), 2));
    // log error if we can create 2 needs
    bus.subscribe(NeedCreatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 2, new MultipleActions(ctx, new LogErrorAction(ctx, "Should not have been able to create 2 needs with identical URI"), new PublishEventAction(ctx, new TestFailedEvent(this, "Should not have been able to create 2 needs with identical URI")))));
    // log success if we could create 1 need
    bus.subscribe(NeedCreatedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: could create one need"), new PublishEventAction(ctx, new SuccessEvent()))));
    // log success if we got an error for 2nd need
    bus.subscribe(NeedCreationFailedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: need creation failed for 2nd need."), new PublishEventAction(ctx, new SuccessEvent()))));
    // when we have 2 SuccessEvents, we're done. Deacivate the needs and signal we're finished
    bus.subscribe(SuccessEvent.class, new ActionOnceAfterNEventsListener(ctx, 2, new MultipleActions(ctx, new LogAction(ctx, "Test passed."), new PublishEventAction(ctx, new TestPassedEvent(this)), new DeactivateAllNeedsAction(ctx))));
    // when we have a FailureEvent, we're done, too. Deacivate the needs and signal we're finished
    bus.subscribe(TestFailedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Test failed."), new DeactivateAllNeedsAction(ctx))));
    // wait for the needDeactivated event, then say we're done.
    bus.subscribe(NeedDeactivatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new SignalWorkDoneAction(ctx, this)));
// TODO: fix: bot runs forever even if test fails.
// TODO: fix: need 1 is not deactivated if test fails.
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) CreateNeedWithFacetsAction(won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction) EventBus(won.bot.framework.eventbot.bus.EventBus) SignalWorkDoneAction(won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction) TestFailedEvent(won.bot.framework.eventbot.event.impl.test.TestFailedEvent) ActionOnFirstNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstNEventsListener) TestPassedEvent(won.bot.framework.eventbot.event.impl.test.TestPassedEvent) ConstantNewNeedURIDecorator(won.bot.integrationtest.failsim.ConstantNewNeedURIDecorator) SuccessEvent(won.bot.framework.eventbot.event.impl.test.SuccessEvent) DeactivateAllNeedsAction(won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsAction) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener)

Aggregations

EventListenerContext (won.bot.framework.eventbot.EventListenerContext)2 SignalWorkDoneAction (won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction)2 CreateNeedWithFacetsAction (won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction)2 DeactivateAllNeedsAction (won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsAction)2 EventBus (won.bot.framework.eventbot.bus.EventBus)2 SuccessEvent (won.bot.framework.eventbot.event.impl.test.SuccessEvent)2 TestFailedEvent (won.bot.framework.eventbot.event.impl.test.TestFailedEvent)2 TestPassedEvent (won.bot.framework.eventbot.event.impl.test.TestPassedEvent)2 ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)2 ActionOnFirstNEventsListener (won.bot.framework.eventbot.listener.impl.ActionOnFirstNEventsListener)2 ActionOnceAfterNEventsListener (won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener)2 ConstantNewEventURIDecorator (won.bot.integrationtest.failsim.ConstantNewEventURIDecorator)1 ConstantNewNeedURIDecorator (won.bot.integrationtest.failsim.ConstantNewNeedURIDecorator)1