Search in sources :

Example 16 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class ExceptionsTestCase method testRoutingExceptionNullMessageValidProcessor.

@Test
public final void testRoutingExceptionNullMessageValidProcessor() throws MuleException {
    Processor processor = mock(Processor.class);
    RoutingException rex = new RoutingException(processor);
    assertSame(processor, rex.getRoute());
}
Also used : RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) Processor(org.mule.runtime.core.api.processor.Processor) Test(org.junit.Test)

Example 17 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class ReactiveInterceptorAdapterTestCase method interceptorThrowsExceptionAroundAfterProceedInCallbackChained.

@Test
public void interceptorThrowsExceptionAroundAfterProceedInCallbackChained() throws Exception {
    RuntimeException expectedException = new RuntimeException("Some Error");
    ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {

        @Override
        public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
            return action.proceed().thenApplyAsync(e -> {
                throw expectedException;
            });
        }
    });
    startFlowWithInterceptors(interceptor);
    expected.expect(MessagingException.class);
    expected.expect(withEventThat(hasErrorType(UNKNOWN.getNamespace(), UNKNOWN.getName())));
    expected.expectCause(sameInstance(expectedException));
    try {
        process(flow, eventBuilder(muleContext).message(Message.of("")).build());
    } finally {
        if (useMockInterceptor) {
            InOrder inOrder = inOrder(processor, interceptor);
            inOrder.verify(interceptor).before(any(), any(), any());
            inOrder.verify(interceptor).around(any(), any(), any(), any());
            inOrder.verify(processor).process(any());
            inOrder.verify(interceptor).after(any(), any(), eq(of(expectedException)));
            verifyParametersResolvedAndDisposed(times(1));
        }
    }
}
Also used : Schedulers.fromExecutorService(reactor.core.scheduler.Schedulers.fromExecutorService) Message(org.mule.runtime.api.message.Message) Optional.of(java.util.Optional.of) Matchers.not(org.hamcrest.Matchers.not) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Thread.currentThread(java.lang.Thread.currentThread) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ParametersResolverProcessor(org.mule.runtime.core.internal.processor.ParametersResolverProcessor) TypedComponentIdentifier.builder(org.mule.runtime.api.component.TypedComponentIdentifier.builder) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Matchers.any(org.mockito.Matchers.any) VerificationMode(org.mockito.verification.VerificationMode) Matchers.argThat(org.mockito.Matchers.argThat) QName(javax.xml.namespace.QName) Mockito.mock(org.mockito.Mockito.mock) Optional.empty(java.util.Optional.empty) ComponentIdentifier.buildFromStringRepresentation(org.mule.runtime.api.component.ComponentIdentifier.buildFromStringRepresentation) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) OPERATION(org.mule.runtime.api.component.TypedComponentIdentifier.ComponentType.OPERATION) EventMatcher.hasErrorTypeThat(org.mule.tck.junit4.matcher.EventMatcher.hasErrorTypeThat) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingExceptionMatcher.withEventThat(org.mule.tck.junit4.matcher.MessagingExceptionMatcher.withEventThat) Component(org.mule.runtime.api.component.Component) Mono.from(reactor.core.publisher.Mono.from) BiConsumer(java.util.function.BiConsumer) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) Before(org.junit.Before) Disposable(org.mule.runtime.api.lifecycle.Disposable) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.never(org.mockito.Mockito.never) Matcher(org.hamcrest.Matcher) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Flow.builder(org.mule.runtime.core.api.construct.Flow.builder) PollingProber(org.mule.tck.probe.PollingProber) Assert.assertThat(org.junit.Assert.assertThat) SmallTest(org.mule.tck.size.SmallTest) Scheduler(org.mule.runtime.api.scheduler.Scheduler) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Parameterized(org.junit.runners.Parameterized) IsMapContaining.hasEntry(org.hamcrest.collection.IsMapContaining.hasEntry) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Flow(org.mule.runtime.core.api.construct.Flow) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) Mockito.inOrder(org.mockito.Mockito.inOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ErrorType(org.mule.runtime.api.message.ErrorType) Optional(java.util.Optional) ANNOTATION_PARAMETERS(org.mule.runtime.core.internal.component.ComponentAnnotations.ANNOTATION_PARAMETERS) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) Parameters(org.junit.runners.Parameterized.Parameters) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Processor(org.mule.runtime.core.api.processor.Processor) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) DefaultLocationPart(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.DefaultLocationPart) ProcessorInterceptorFactory(org.mule.runtime.api.interception.ProcessorInterceptorFactory) Inject(javax.inject.Inject) CompletableFuture.supplyAsync(java.util.concurrent.CompletableFuture.supplyAsync) ExpectedException.none(org.junit.rules.ExpectedException.none) CPU_LITE_ASYNC(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_LITE_ASYNC) Collections.singletonMap(java.util.Collections.singletonMap) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ExpectedException(org.junit.rules.ExpectedException) EventMatcher.hasErrorType(org.mule.tck.junit4.matcher.EventMatcher.hasErrorType) SchedulerConfig(org.mule.runtime.api.scheduler.SchedulerConfig) CheckedConsumer(org.mule.runtime.core.api.util.func.CheckedConsumer) ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) Description(org.hamcrest.Description) InOrder(org.mockito.InOrder) Mockito.when(org.mockito.Mockito.when) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) Mockito.verify(org.mockito.Mockito.verify) UNKNOWN(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.UNKNOWN) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) Collectors.toList(java.util.stream.Collectors.toList) LazyValue(org.mule.runtime.api.util.LazyValue) Rule(org.junit.Rule) IsSame.sameInstance(org.hamcrest.core.IsSame.sameInstance) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) CompletableFuture(java.util.concurrent.CompletableFuture) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) InOrder(org.mockito.InOrder) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 18 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class ExceptionListenerTestCase method setGoodProcessors.

@Test
public void setGoodProcessors() throws Exception {
    List<Processor> list = new ArrayList<Processor>();
    list.add(mock(Processor.class));
    list.add(mock(Processor.class));
    AbstractExceptionListener router = new OnErrorPropagateHandler();
    assertNotNull(router.getMessageProcessors());
    assertEquals(0, router.getMessageProcessors().size());
    router.setMessageProcessors(singletonList(mock(Processor.class)));
    assertEquals(1, router.getMessageProcessors().size());
    router.setMessageProcessors(list);
    assertNotNull(router.getMessageProcessors());
    assertEquals(2, router.getMessageProcessors().size());
}
Also used : AbstractExceptionListener(org.mule.runtime.core.privileged.exception.AbstractExceptionListener) Processor(org.mule.runtime.core.api.processor.Processor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 19 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class ExceptionListenerTestCase method setSingleGoodProcessorEndpoint.

@Test
public void setSingleGoodProcessorEndpoint() throws Exception {
    AbstractExceptionListener router = new OnErrorPropagateHandler();
    Processor messageProcessor = mock(Processor.class);
    router.setMessageProcessors(singletonList(messageProcessor));
    assertNotNull(router.getMessageProcessors());
    assertTrue(router.getMessageProcessors().contains(messageProcessor));
}
Also used : AbstractExceptionListener(org.mule.runtime.core.privileged.exception.AbstractExceptionListener) Processor(org.mule.runtime.core.api.processor.Processor) Test(org.junit.Test)

Example 20 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class DefaultMessageProcessorChainTestCase method testMPChainLifecycle.

@Test
public void testMPChainLifecycle() throws Exception {
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    AppendingInterceptingMP mp1 = new AppendingInterceptingMP("1");
    AppendingInterceptingMP mp2 = new AppendingInterceptingMP("2");
    Processor chain = builder.chain(mp1, mp2).build();
    initialiseIfNeeded(chain, muleContext);
    ((Lifecycle) chain).start();
    ((Lifecycle) chain).stop();
    ((Lifecycle) chain).dispose();
    assertLifecycle(mp1);
    assertLifecycle(mp2);
}
Also used : AbstractInterceptingMessageProcessor(org.mule.runtime.core.privileged.processor.AbstractInterceptingMessageProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

Processor (org.mule.runtime.core.api.processor.Processor)58 Test (org.junit.Test)31 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)24 MuleException (org.mule.runtime.api.exception.MuleException)15 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)14 Component (org.mule.runtime.api.component.Component)12 ArrayList (java.util.ArrayList)11 InternalProcessor (org.mule.runtime.core.privileged.processor.InternalProcessor)11 Publisher (org.reactivestreams.Publisher)11 Message (org.mule.runtime.api.message.Message)10 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)10 Map (java.util.Map)9 Arrays.asList (java.util.Arrays.asList)8 Flow (org.mule.runtime.core.api.construct.Flow)8 Inject (javax.inject.Inject)7 Assert.assertThat (org.junit.Assert.assertThat)7 Mockito.mock (org.mockito.Mockito.mock)7 Mockito.when (org.mockito.Mockito.when)7 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)7 Disposable (org.mule.runtime.api.lifecycle.Disposable)7