use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class DefaultFlowBuilderTestCase method buildsFullFlow.
@Test
public void buildsFullFlow() throws Exception {
Processor processor1 = mock(Processor.class);
Processor processor2 = mock(Processor.class);
List<Processor> messageProcessors = new ArrayList<>();
messageProcessors.add(processor1);
messageProcessors.add(processor2);
MessageSource messageSource = mock(MessageSource.class);
ProcessingStrategyFactory processingStrategyFactory = mock(ProcessingStrategyFactory.class);
ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class);
when(processingStrategyFactory.create(any(), any())).thenReturn(processingStrategy);
FlowExceptionHandler exceptionListener = mock(FlowExceptionHandler.class);
Flow flow = flowBuilder.processors(messageProcessors).source(messageSource).processingStrategyFactory(processingStrategyFactory).messagingExceptionHandler(exceptionListener).build();
assertThat(flow.getName(), equalTo(FLOW_NAME));
assertThat(flow.getMuleContext(), is(muleContext));
assertThat(flow.getProcessors(), contains(processor1, processor2));
assertThat(flow.getSource(), is(messageSource));
assertThat(flow.getExceptionListener(), is(exceptionListener));
assertThat(flow.getProcessingStrategy(), sameInstance(processingStrategy));
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class MessageProcessingFlowTraceManagerTestCase method createMockProcessor.
public Processor createMockProcessor(String processorPath, boolean useLocationSettings) {
ComponentLocation componentLocation = mock(ComponentLocation.class);
when(componentLocation.getLocation()).thenReturn(processorPath);
when(componentLocation.getFileName()).thenReturn(useLocationSettings ? of(CONFIG_FILE_NAME) : empty());
when(componentLocation.getLineInFile()).thenReturn(useLocationSettings ? of(LINE_NUMBER) : empty());
Component annotatedMessageProcessor = (Component) mock(Processor.class, withSettings().extraInterfaces(Component.class).defaultAnswer(RETURNS_DEEP_STUBS));
when(annotatedMessageProcessor.getAnnotation(any())).thenReturn(null);
when(annotatedMessageProcessor.getLocation()).thenReturn(componentLocation);
return (Processor) annotatedMessageProcessor;
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class MessageProcessingFlowTraceManagerTestCase method newAnnotatedComponentCall.
@Test
public void newAnnotatedComponentCall() {
CoreEvent event = buildEvent("newAnnotatedComponentCall");
PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName());
assertThat(getContextInfo(event, rootFlowConstruct), is(""));
manager.onPipelineNotificationStart(pipelineNotification);
assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName()));
Component annotatedMessageProcessor = (Component) createMockProcessor("/comp", true);
when(annotatedMessageProcessor.getAnnotation(docNameAttrName)).thenReturn("annotatedName");
manager.onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, (Processor) annotatedMessageProcessor));
assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":muleApp.xml:10 (annotatedName))"));
manager.onPipelineNotificationComplete(pipelineNotification);
assertThat(getContextInfo(event, rootFlowConstruct), is(""));
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class AbstractForkJoinStrategyTestCase method errorDelayed.
@Test
@Description("When an error occurs all routes are executed regardless and a CompositeRoutingException is thrown containing a RoutingResult with details of both failures and successes.")
public void errorDelayed() throws Throwable {
Processor processorSpy = createProcessorSpy(testEvent().getMessage());
RuntimeException exception1 = new IllegalStateException();
RoutingPair failingPair1 = of(testEvent(), createFailingRoutingPair(exception1));
RuntimeException exception2 = new UnsupportedOperationException();
RoutingPair failingPair2 = of(testEvent(), createFailingRoutingPair(exception2));
RuntimeException exception3 = new IndexOutOfBoundsException();
RoutingPair failingPair3 = of(testEvent(), createFailingRoutingPair(exception3));
RoutingPair okPair = of(testEvent(), createChain(processorSpy));
expectedException.expect(instanceOf(CompositeRoutingException.class));
invokeStrategyBlocking(strategy, testEvent(), asList(failingPair1, failingPair2, failingPair3, okPair), throwable -> {
verify(processorSpy, times(1)).process(any(CoreEvent.class));
CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 3);
RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 1, 3);
assertThat(routingResult.getFailures().get("0").getCause(), is(exception1));
assertThat(routingResult.getFailures().get("1").getCause(), is(exception2));
assertThat(routingResult.getFailures().get("2").getCause(), is(exception3));
assertThat(routingResult.getFailures().get("3"), is(nullValue()));
});
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class AbstractForkJoinStrategyTestCase method timeoutEager.
@Test
@Description("When configured with delayErrors='false' the first timeout causes strategy to throw a TimeoutException.")
public void timeoutEager() throws Throwable {
strategy = createStrategy(processingStrategy, 1, false, 50);
Message pair2Result = of(2);
Processor pair2Processor = createProcessorSpy(pair2Result);
RoutingPair pair2 = of(testEvent(), createChain(pair2Processor));
expectedException.expect(instanceOf(DefaultMuleException.class));
expectedException.expectCause(instanceOf(TimeoutException.class));
invokeStrategyBlocking(strategy, testEvent(), asList(createRoutingPairWithSleep(of(1), 250), pair2), throwable -> verify(pair2Processor, never()).process(any(CoreEvent.class)));
}
Aggregations