use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class RunContext method createCallableChain.
/**
* Creates the {@link CallableChain} to initialize this context, and provides basic functionality for this
* {@link RunContext}.
* <p>
* This method is not intended to be overwritten. To contribute behavior, overwrite
* {@link #interceptCallableChain(CallableChain)}. Contributions are added before setting the transaction boundary.
*/
protected <RESULT> CallableChain<RESULT> createCallableChain() {
final CallableChain<RESULT> contributions = new CallableChain<RESULT>();
interceptCallableChain(contributions);
@SuppressWarnings("unchecked") final TransactionProcessor<RESULT> transactionProcessor = BEANS.get(TransactionProcessor.class).withCallerTransaction(m_transaction).withTransactionScope(m_transactionScope).withTransactionMembers(m_transactionMembers);
return new CallableChain<RESULT>().add(new ThreadLocalProcessor<>(RunContext.CURRENT, this)).add(new ThreadLocalProcessor<>(CorrelationId.CURRENT, m_correlationId)).add(new ThreadLocalProcessor<>(RunMonitor.CURRENT, Assertions.assertNotNull(m_runMonitor))).add(new SubjectProcessor<RESULT>(m_subject)).add(new DiagnosticContextValueProcessor(BEANS.get(PrinicpalContextValueProvider.class))).add(new DiagnosticContextValueProcessor(BEANS.get(CorrelationIdContextValueProvider.class))).add(new ThreadLocalProcessor<>(NlsLocale.CURRENT, m_locale)).add(new ThreadLocalProcessor<>(PropertyMap.CURRENT, m_propertyMap)).addAll(m_threadLocalProcessors.values()).addAll(contributions.asList()).addAll(m_diagnosticProcessors.values()).add(transactionProcessor).addAll(m_interceptors);
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class ClientRunContextChainTest method testCallableChain.
/**
* Tests the correct order of interceptors in {@link ClientRunContext}.
*/
@Test
public void testCallableChain() throws Exception {
CallableChain<Object> chain = new ClientRunContext() {
@Override
protected <RESULT> CallableChain<RESULT> createCallableChain() {
// overwrite to be accessible in test
return super.createCallableChain();
}
}.createCallableChain();
Iterator<IChainable> chainIterator = chain.values().iterator();
// 1. ThreadLocalProcessor for RunContext.CURRENT
IChainable c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(RunContext.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 2. ThreadLocalProcessor for CorrelationId.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(CorrelationId.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 3. ThreadLocalProcessor for RunMonitor.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(RunMonitor.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 4. SubjectProcessor
c = (IChainable) chainIterator.next();
assertEquals(SubjectProcessor.class, c.getClass());
// 5. DiagnosticContextValueProcessor
c = chainIterator.next();
assertEquals(DiagnosticContextValueProcessor.class, c.getClass());
assertEquals("subject.principal.name", ((DiagnosticContextValueProcessor) c).getMdcKey());
// 6. DiagnosticContextValueProcessor
c = chainIterator.next();
assertEquals(DiagnosticContextValueProcessor.class, c.getClass());
assertEquals("scout.correlation.id", ((DiagnosticContextValueProcessor) c).getMdcKey());
// 7. ThreadLocalProcessor for NlsLocale.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(NlsLocale.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 8. ThreadLocalProcessor for PropertyMap.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(PropertyMap.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 9. ThreadLocalProcessor for ISession.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(ISession.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 10. DiagnosticContextValueProcessor
c = chainIterator.next();
assertEquals(DiagnosticContextValueProcessor.class, c.getClass());
assertEquals("scout.user.name", ((DiagnosticContextValueProcessor) c).getMdcKey());
// 11. DiagnosticContextValueProcessor
c = chainIterator.next();
assertEquals(DiagnosticContextValueProcessor.class, c.getClass());
assertEquals("scout.session.id", ((DiagnosticContextValueProcessor) c).getMdcKey());
// 12. ThreadLocalProcessor for UserAgent.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(UserAgent.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 13. ThreadLocalProcessor for IDesktop.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(IDesktop.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 14. ThreadLocalProcessor for IOutline.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(IOutline.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 15. ThreadLocalProcessor for IForm.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(IForm.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 16. TransactionProcessor
c = chainIterator.next();
assertEquals(TransactionProcessor.class, c.getClass());
assertFalse(chainIterator.hasNext());
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class ExceptionProcessorTest method testSuccess.
@Test
public void testSuccess() throws Exception {
JobInput jobInput = Jobs.newInput();
CallableChain<String> chain = new CallableChain<>();
chain.add(new ExceptionProcessor<String>(jobInput));
String result = chain.call(new Callable<String>() {
@Override
public String call() throws Exception {
return "result";
}
});
assertEquals("result", result);
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class ExceptionProcessorTest method testWithNullExceptionHandlerAndPropagate.
@Test
public void testWithNullExceptionHandlerAndPropagate() throws Exception {
final RuntimeException exception = new RuntimeException("expected JUnit test exception");
JobInput jobInput = Jobs.newInput().withExceptionHandling(null, false);
CallableChain<String> chain = new CallableChain<>();
chain.add(new ExceptionProcessor<String>(jobInput));
try {
chain.call(new Callable<String>() {
@Override
public String call() throws Exception {
throw exception;
}
});
fail();
} catch (RuntimeException e) {
assertSame(exception, e);
verify(m_exceptionHandler, never()).handle(eq(exception));
}
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class ExceptionProcessorTest method testDefaultSettingsWithException.
@Test
public void testDefaultSettingsWithException() throws Exception {
final RuntimeException exception = new RuntimeException("expected JUnit test exception");
JobInput jobInput = Jobs.newInput();
CallableChain<String> chain = new CallableChain<>();
chain.add(new CallableChainExceptionHandler<String>());
chain.add(new ExceptionProcessor<String>(jobInput));
try {
chain.call(new Callable<String>() {
@Override
public String call() throws Exception {
throw exception;
}
});
fail();
} catch (RuntimeException e) {
assertSame(exception, e);
verify(m_exceptionHandler, times(1)).handle(eq(exception));
verifyNoMoreInteractions(m_exceptionHandler);
}
}
Aggregations