use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class AbstractMuleContextTestCase method verifyAndStopSchedulers.
protected static void verifyAndStopSchedulers() throws MuleException {
final SchedulerService serviceImpl = muleContext.getSchedulerService();
Set<String> schedulersOnInitNames = schedulersOnInit.stream().map(s -> s.getName()).collect(toSet());
try {
assertThat(muleContext.getSchedulerService().getSchedulers().stream().filter(s -> !schedulersOnInitNames.contains(s.getName())).collect(toList()), empty());
} finally {
if (serviceImpl instanceof SimpleUnitTestSupportSchedulerService) {
stopIfNeeded(serviceImpl);
}
}
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class DefaultFlowTestCase method lifecycleOrder.
@Test
public void lifecycleOrder() throws MuleException {
Sink sink = mock(Sink.class, withSettings().extraInterfaces(Disposable.class));
Processor processor = mock(Processor.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class, withSettings().extraInterfaces(Startable.class, Stoppable.class));
when(processingStrategy.createSink(any(FlowConstruct.class), any(ReactiveProcessor.class))).thenReturn(sink);
flow = (DefaultFlow) Flow.builder(FLOW_NAME, muleContext).source(directInboundMessageSource).processors(singletonList(processor)).processingStrategyFactory((muleContext, s) -> processingStrategy).build();
flow.initialise();
flow.start();
InOrder inOrder = inOrder(sink, processor, processingStrategy);
inOrder.verify((Startable) processingStrategy).start();
inOrder.verify(processingStrategy).createSink(any(FlowConstruct.class), any(ReactiveProcessor.class));
inOrder.verify((Startable) processor).start();
flow.stop();
inOrder.verify((Disposable) sink).dispose();
inOrder.verify((Stoppable) processor).stop();
inOrder.verify((Stoppable) processingStrategy).stop();
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class MVELExpressionLanguageTestCase method createEvent.
protected PrivilegedEvent createEvent(String payload, DataType dataType, Object attributes, DataType attributesDataType) {
InternalMessage message = mock(InternalMessage.class);
when(message.getPayload()).thenReturn(new TypedValue<>(payload, dataType));
when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, attributesDataType));
try {
return this.<PrivilegedEvent.Builder>getEventBuilder().message(message).build();
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class ErrorHandlerTestCase method before.
@Before
public void before() throws MuleException {
Error mockError = mock(Error.class);
when(mockError.getErrorType()).thenReturn(mockErrorType);
event = getEventBuilder().message(Message.of("")).error(mockError).build();
mockException = new MessagingException(event, new Exception());
CoreEvent handledEvent = testEvent();
when(mockTestExceptionStrategy1.accept(any(CoreEvent.class))).thenReturn(true);
when(mockTestExceptionStrategy1.apply(any(MessagingException.class))).thenReturn(just(handledEvent));
when(mockTestExceptionStrategy2.accept(any(CoreEvent.class))).thenReturn(true);
when(mockTestExceptionStrategy2.apply(any(MessagingException.class))).thenReturn(just(handledEvent));
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class AsyncRequestReplyRequesterTestCase method returnsNullWhenInterruptedWhileWaitingForReply.
@Test
@Ignore("See MULE-8830")
public void returnsNullWhenInterruptedWhileWaitingForReply() throws Exception {
final Latch fakeLatch = new Latch() {
@Override
public void await() throws InterruptedException {
throw new InterruptedException();
}
};
asyncReplyMP = new TestAsyncRequestReplyRequester(muleContext) {
@Override
protected Latch createEventLock() {
return fakeLatch;
}
};
final CountDownLatch processingLatch = new CountDownLatch(1);
Processor target = mock(Processor.class);
asyncReplyMP.setListener(target);
MessageSource messageSource = mock(MessageSource.class);
asyncReplyMP.setReplySource(messageSource);
asyncReplyMP.setMuleContext(muleContext);
final boolean[] exceptionThrown = new boolean[1];
final Object[] responseEvent = new Object[1];
Thread thread = new Thread(() -> {
try {
responseEvent[0] = asyncReplyMP.process(testEvent());
} catch (MuleException e) {
exceptionThrown[0] = true;
} finally {
processingLatch.countDown();
}
});
thread.start();
assertTrue(processingLatch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
assertFalse(exceptionThrown[0]);
assertNull(responseEvent[0]);
}
Aggregations