use of won.bot.IntegrationtestBot in project webofneeds by researchstudio-sat.
the class SecurityBotTests method runBot.
private void runBot(Class botClass) throws ExecutionException, InterruptedException {
IntegrationtestBot bot = null;
// create a bot instance and auto-wire it
AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
bot = (IntegrationtestBot) beanFactory.autowire(botClass, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
Object botBean = beanFactory.initializeBean(bot, "theBot");
bot = (IntegrationtestBot) botBean;
// the bot also needs a trigger so its act() method is called regularly.
// (there is no trigger bean in the context)
PeriodicTrigger trigger = new PeriodicTrigger(500, TimeUnit.MILLISECONDS);
trigger.setInitialDelay(100);
((TriggeredBot) bot).setTrigger(trigger);
// adding the bot to the bot manager will cause it to be initialized.
// at that point, the trigger starts.
botManager.addBot(bot);
final SettableListenableFuture<TestFinishedEvent> futureTestResult = new SettableListenableFuture();
final EventListenerContext ctx = bot.getExposedEventListenerContext();
// action for setting the future when we get a test result
EventBotAction setFutureAction = new SetFutureAction(ctx, futureTestResult);
// action for setting the future when an error occurs
EventBotAction setFutureFromErrorAction = new SetFutureFromErrorEventAction(ctx, futureTestResult, bot);
// add a listener for test success
ctx.getEventBus().subscribe(TestPassedEvent.class, new ActionOnEventListener(ctx, setFutureAction));
// add a listener for test failure
ctx.getEventBus().subscribe(TestFailedEvent.class, new ActionOnEventListener(ctx, setFutureAction));
// add a listener for errors
ctx.getEventBus().subscribe(ErrorEvent.class, new ActionOnEventListener(ctx, setFutureFromErrorAction));
// wait for the result
TestFinishedEvent result = futureTestResult.get();
if (result instanceof TestFailedEvent) {
Assert.fail(((TestFailedEvent) result).getMessage());
}
}
Aggregations