@Test public void testPostInterceptorHappyCase() { postExecutionInterceptorList.add(epp); InterceptingExecutableWrapper executableWrapper = new InterceptingExecutableWrapper(new Executable() { @Override public void execute(ExecutionContext ctx, OperationKey key, Object[] args, ExecutionObserver observer, ExecutionVenue executionVenue, TimeConstraints timeConstraints) { assertTrue("Observer should be wrapped by PostProcessorInterceptorWrapper", observer instanceof PostProcessingInterceptorWrapper); PostProcessingInterceptorWrapper ppiw = (PostProcessingInterceptorWrapper) observer; ppiw.onResult(new ExecutionResult()); } }, preExecutionInterceptorList, postExecutionInterceptorList); executableWrapper.execute(ctx, key, new Object[]{Boolean.TRUE}, observer, ev, DefaultTimeConstraints.NO_CONSTRAINTS); ArgumentCaptor<ExecutionResult> executionResultArgumentCaptor = ArgumentCaptor.forClass(ExecutionResult.class); verify(observer).onResult(executionResultArgumentCaptor.capture()); ExecutionResult executionResult = executionResultArgumentCaptor.getValue(); assertNotNull(executionResult); assertFalse(executionResult.isFault()); }
@Override public void execute(final ExecutionContext ctx, final OperationKey key, final Object[] args, final ExecutionObserver observer, final ExecutionVenue executionVenue, final TimeConstraints timeConstraints) { final Runnable execution = new Runnable() { @Override public void run() { ExecutionObserver newObserver = new PostProcessingInterceptorWrapper(observer, postExecutionInterceptorList, ctx, key, args); try { exec.execute( ctx, key, args, newObserver, executionVenue, timeConstraints); } catch (CougarException e) { newObserver.onResult(new ExecutionResult(e)); } catch (Exception e) { newObserver.onResult(new ExecutionResult( new CougarFrameworkException(ServerFaultCode.ServiceRuntimeException, "Exception thrown by service method", e))); } } }; List<ExecutionPreProcessor> unexecuted = unexecutedPreProcessorsByThread.get(Thread.currentThread()); if (unexecuted == null) { unexecuted = new ArrayList<>(preExecutionInterceptorList); } try { InterceptionUtils.execute(preExecutionInterceptorList, unexecuted, ExecutionRequirement.PRE_EXECUTE, execution, ctx, key, args, observer); } finally { unexecutedPreProcessorsByThread.remove(Thread.currentThread()); } }
InterceptingExecutableWrapper implements ExecutableWrapper { @Override public void execute(final ExecutionContext ctx, final OperationKey key, final Object[] args, final ExecutionObserver observer, final ExecutionVenue executionVenue, final TimeConstraints timeConstraints) { final Runnable execution = new Runnable() { @Override public void run() { ExecutionObserver newObserver = new PostProcessingInterceptorWrapper(observer, postExecutionInterceptorList, ctx, key, args); try { exec.execute( ctx, key, args, newObserver, executionVenue, timeConstraints); } catch (CougarException e) { newObserver.onResult(new ExecutionResult(e)); } catch (Exception e) { newObserver.onResult(new ExecutionResult( new CougarFrameworkException(ServerFaultCode.ServiceRuntimeException, "Exception thrown by service method", e))); } } }; List<ExecutionPreProcessor> unexecuted = unexecutedPreProcessorsByThread.get(Thread.currentThread()); if (unexecuted == null) { unexecuted = new ArrayList<>(preExecutionInterceptorList); } try { InterceptionUtils.execute(preExecutionInterceptorList, unexecuted, ExecutionRequirement.PRE_EXECUTE, execution, ctx, key, args, observer); } finally { unexecutedPreProcessorsByThread.remove(Thread.currentThread()); } } }
InterceptingExecutableWrapper implements ExecutableWrapper { @Override public void execute(final ExecutionContext ctx, final OperationKey key, final Object[] args, final ExecutionObserver observer, final ExecutionVenue executionVenue, final TimeConstraints timeConstraints) { final Runnable execution = new Runnable() { @Override public void run() { ExecutionObserver newObserver = new PostProcessingInterceptorWrapper(observer, postExecutionInterceptorList, ctx, key, args); try { exec.execute( ctx, key, args, newObserver, executionVenue, timeConstraints); } catch (CougarException e) { newObserver.onResult(new ExecutionResult(e)); } catch (Exception e) { newObserver.onResult(new ExecutionResult( new CougarFrameworkException(ServerFaultCode.ServiceRuntimeException, "Exception thrown by service method", e))); } } }; List<ExecutionPreProcessor> unexecuted = unexecutedPreProcessorsByThread.get(Thread.currentThread()); if (unexecuted == null) { unexecuted = new ArrayList<>(preExecutionInterceptorList); } try { InterceptionUtils.execute(preExecutionInterceptorList, unexecuted, ExecutionRequirement.PRE_EXECUTE, execution, ctx, key, args, observer); } finally { unexecutedPreProcessorsByThread.remove(Thread.currentThread()); } } InterceptingExecutableWrapper(Executable exec, List<ExecutionPreProcessor> preExecutionInterceptorList, List<ExecutionPostProcessor> postExecutionInterceptorList); }
InterceptingExecutableWrapper implements ExecutableWrapper { @Override public void execute(final ExecutionContext ctx, final OperationKey key, final Object[] args, final ExecutionObserver observer, final ExecutionVenue executionVenue, final TimeConstraints timeConstraints) { final Runnable execution = new Runnable() { @Override public void run() { ExecutionObserver newObserver = new PostProcessingInterceptorWrapper(observer, postExecutionInterceptorList, ctx, key, args); try { exec.execute( ctx, key, args, newObserver, executionVenue, timeConstraints); } catch (CougarException e) { newObserver.onResult(new ExecutionResult(e)); } catch (Exception e) { newObserver.onResult(new ExecutionResult( new CougarFrameworkException(ServerFaultCode.ServiceRuntimeException, "Exception thrown by service method", e))); } } }; List<ExecutionPreProcessor> unexecuted = unexecutedPreProcessorsByThread.get(Thread.currentThread()); if (unexecuted == null) { unexecuted = new ArrayList<>(preExecutionInterceptorList); } try { InterceptionUtils.execute(preExecutionInterceptorList, unexecuted, ExecutionRequirement.PRE_EXECUTE, execution, ctx, key, args, observer); } finally { unexecutedPreProcessorsByThread.remove(Thread.currentThread()); } } InterceptingExecutableWrapper(Executable exec, List<ExecutionPreProcessor> preExecutionInterceptorList, List<ExecutionPostProcessor> postExecutionInterceptorList); @Override void execute(final ExecutionContext ctx, final OperationKey key, final Object[] args, final ExecutionObserver observer, final ExecutionVenue executionVenue, final TimeConstraints timeConstraints); @Override Executable getWrappedExecutable(); @Override T findChild(Class<T> clazz); void setUnexecutedPreProcessorsForThisThread(List<ExecutionPreProcessor> remainingProcessors); }
InterceptingExecutableWrapper implements ExecutableWrapper { @Override public void execute(final ExecutionContext ctx, final OperationKey key, final Object[] args, final ExecutionObserver observer, final ExecutionVenue executionVenue, final TimeConstraints timeConstraints) { final Runnable execution = new Runnable() { @Override public void run() { ExecutionObserver newObserver = new PostProcessingInterceptorWrapper(observer, postExecutionInterceptorList, ctx, key, args); try { exec.execute( ctx, key, args, newObserver, executionVenue, timeConstraints); } catch (CougarException e) { newObserver.onResult(new ExecutionResult(e)); } catch (Exception e) { newObserver.onResult(new ExecutionResult( new CougarFrameworkException(ServerFaultCode.ServiceRuntimeException, "Exception thrown by service method", e))); } } }; List<ExecutionPreProcessor> unexecuted = unexecutedPreProcessorsByThread.get(Thread.currentThread()); if (unexecuted == null) { unexecuted = new ArrayList<>(preExecutionInterceptorList); } try { InterceptionUtils.execute(preExecutionInterceptorList, unexecuted, ExecutionRequirement.PRE_EXECUTE, execution, ctx, key, args, observer); } finally { unexecutedPreProcessorsByThread.remove(Thread.currentThread()); } } InterceptingExecutableWrapper(Executable exec, List<ExecutionPreProcessor> preExecutionInterceptorList, List<ExecutionPostProcessor> postExecutionInterceptorList); @Override void execute(final ExecutionContext ctx, final OperationKey key, final Object[] args, final ExecutionObserver observer, final ExecutionVenue executionVenue, final TimeConstraints timeConstraints); @Override Executable getWrappedExecutable(); @Override T findChild(Class<T> clazz); void setUnexecutedPreProcessorsForThisThread(List<ExecutionPreProcessor> remainingProcessors);  }