public void asyncListenerFailTest() throws InvalidProcessStateException {
TestProcessComponentListener listener = new TestProcessComponentListener();
// test fail
AsyncComponent failProcess = new AsyncComponent(new FailingSequentialProcess());
failProcess.attachListener(listener);
failProcess.start();
UseCaseTestUtil.waitTillFailed(listener, MAX_ASYNC_WAIT);
assertFalse(listener.hasSucceeded());
assertTrue(listener.hasFailed());
assertTrue(listener.hasFinished());
listener.reset();
// test fail (1-layer, steps only)
SequentialProcess failProcess2 = new SequentialProcess();
failProcess2.add(new SucceedingProcessStep());
failProcess2.add(new FailingProcessStep());
AsyncComponent asyncProcess2 = new AsyncComponent(failProcess2);
asyncProcess2.attachListener(listener);
asyncProcess2.start();
UseCaseTestUtil.waitTillFailed(listener, MAX_ASYNC_WAIT);
assertFalse(listener.hasSucceeded());
assertTrue(listener.hasFailed());
assertTrue(listener.hasFinished());
listener.reset();
// test fail (1-layer, step and sub-process (failing) without children)
SequentialProcess failProcess3 = new SequentialProcess();
failProcess3.add(new SucceedingProcessStep());
failProcess3.add(new FailingSequentialProcess());
AsyncComponent asyncProcess3 = new AsyncComponent(failProcess3);
asyncProcess3.attachListener(listener);
asyncProcess3.start();
UseCaseTestUtil.waitTillFailed(listener, MAX_ASYNC_WAIT);
assertFalse(listener.hasSucceeded());
assertTrue(listener.hasFailed());
assertTrue(listener.hasFinished());
listener.reset();
// test fail (2-layer, steps (failing) and sub-process with children)
SequentialProcess failProcess4 = new SequentialProcess();
SequentialProcess successSubProcess = new SequentialProcess();
successSubProcess.add(new SucceedingProcessStep());
successSubProcess.add(new SucceedingProcessStep());
failProcess4.add(new SucceedingProcessStep());
failProcess4.add(successSubProcess);
failProcess4.add(new FailingProcessStep());
AsyncComponent asyncProcess4 = new AsyncComponent(failProcess4);
asyncProcess4.attachListener(listener);
asyncProcess4.start();
UseCaseTestUtil.waitTillFailed(listener, MAX_ASYNC_WAIT);
assertFalse(listener.hasSucceeded());
assertTrue(listener.hasFailed());
assertTrue(listener.hasFinished());
listener.reset();
// test fail (2-layer, steps and sub-process (failing) with children)
SequentialProcess failProcess5 = new SequentialProcess();
SequentialProcess failSubProcess = new FailingSequentialProcess();
failProcess5.add(new SucceedingProcessStep());
failProcess5.add(failSubProcess);
failProcess5.add(new SucceedingProcessStep());