@Test public void testPreInterceptorsOneBadCheckedOneGood() { ExecutionPreProcessor preIntercerptorBad = Mockito.mock(ExecutionPreProcessor.class); when(preIntercerptorBad.getExecutionRequirement()).thenReturn(ExecutionRequirement.EXACTLY_ONCE); when(preIntercerptorBad.invoke(any(ExecutionContext.class), any(OperationKey.class), any(Object[].class))).thenReturn(FAILURE_CHECKED); ExecutionPreProcessor preIntercerptorGood = Mockito.mock(ExecutionPreProcessor.class); when(preIntercerptorGood.getExecutionRequirement()).thenReturn(ExecutionRequirement.EXACTLY_ONCE); preExecutionInterceptorList.add(preIntercerptorBad); preExecutionInterceptorList.add(preIntercerptorGood); InterceptingExecutableWrapper executableWrapper = new InterceptingExecutableWrapper(executable, preExecutionInterceptorList, postExecutionInterceptorList); executableWrapper.execute(ctx, key, new Object[]{}, observer, ev,DefaultTimeConstraints.NO_CONSTRAINTS); ArgumentCaptor<ExecutionResult> executionResultArgumentCaptor = ArgumentCaptor.forClass(ExecutionResult.class); verify(observer).onResult(executionResultArgumentCaptor.capture()); ExecutionResult result = executionResultArgumentCaptor.getValue(); assertTrue(result.isFault()); CougarException ex = result.getFault(); assertNotNull(ex); assertEquals(ex.getServerFaultCode(), ServerFaultCode.ServiceCheckedException); verify(preIntercerptorGood, never()).invoke(any(ExecutionContext.class), any(OperationKey.class), any(Object[].class)); verify(ev, never()).execute(any(ExecutionContext.class), any(OperationKey.class), any(Object[].class), any(ExecutionObserver.class), eq(DefaultTimeConstraints.NO_CONSTRAINTS)); }
@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);  }