Search in sources :

Example 21 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class MessagingExceptionTestCase method withAnnotatedFailingProcessorPathResolver.

@Test
public void withAnnotatedFailingProcessorPathResolver() {
    AnnotatedProcessor mockProcessor = mock(AnnotatedProcessor.class);
    when(mockProcessor.getAnnotation(eq(docNameAttrName))).thenReturn("Mock Component");
    configureProcessorLocation(mockProcessor);
    when(mockComponentLocation.getLocation()).thenReturn("flow/processor");
    MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, mockProcessor);
    exception.getInfo().putAll(locationProvider.getContextInfo(createInfo(testEvent, exception, mockProcessor), mockProcessor));
    assertThat(exception.getInfo().get(INFO_LOCATION_KEY).toString(), is("flow/processor @ MessagingExceptionTestCase:muleApp.xml:10 (Mock Component)"));
}
Also used : AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 22 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class MessagingExceptionTestCase method withFailingProcessorNotPathResolver.

@Test
public void withFailingProcessorNotPathResolver() {
    AnnotatedProcessor mockProcessor = mock(AnnotatedProcessor.class);
    when(mockProcessor.getLocation()).thenReturn(fromSingleComponent("Mock@1"));
    when(mockProcessor.toString()).thenReturn("Mock@1");
    MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, mockProcessor);
    exception.getInfo().putAll(locationProvider.getContextInfo(createInfo(testEvent, exception, mockProcessor), mockProcessor));
    assertThat(exception.getInfo().get(INFO_LOCATION_KEY).toString(), is("Mock@1 @ MessagingExceptionTestCase:unknown:-1"));
}
Also used : AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 23 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class MessagingExceptionTestCase method withFailingProcessorPathResolver.

@Test
public void withFailingProcessorPathResolver() {
    AnnotatedProcessor mockProcessor = mock(AnnotatedProcessor.class);
    configureProcessorLocation(mockProcessor);
    when(mockComponentLocation.getLocation()).thenReturn("flow/processor");
    MessagingException exception = new MessagingException(createStaticMessage(""), testEvent, mockProcessor);
    exception.getInfo().putAll(locationProvider.getContextInfo(createInfo(testEvent, exception, mockProcessor), mockProcessor));
    assertThat(exception.getInfo().get(INFO_LOCATION_KEY).toString(), is("flow/processor @ MessagingExceptionTestCase:muleApp.xml:10"));
}
Also used : AnnotatedProcessor(org.mule.runtime.core.privileged.processor.AnnotatedProcessor) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 24 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class MessagingExceptionTestCase method payloadInfoNonVerbose.

@Test
public void payloadInfoNonVerbose() throws Exception {
    MuleException.verboseExceptions = false;
    CoreEvent testEvent = mock(CoreEvent.class);
    Message muleMessage = spy(of(""));
    when(testEvent.getMessage()).thenReturn(muleMessage);
    when(testEvent.getError()).thenReturn(empty());
    MessagingException e = new MessagingException(createStaticMessage(message), testEvent);
    assertThat(e.getInfo().get(PAYLOAD_INFO_KEY), nullValue());
    verify(muleMessage, never()).getPayload();
    verify(transformationService, never()).transform(muleMessage, DataType.STRING);
}
Also used : Message(org.mule.runtime.api.message.Message) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 25 with MessagingException

use of org.mule.runtime.core.internal.exception.MessagingException in project mule by mulesoft.

the class CompositeSourcePolicyTestCase method nextProcessorExecutionFailurePropagates.

@Test
public void nextProcessorExecutionFailurePropagates() throws Exception {
    RuntimeException policyException = new RuntimeException("policy failure");
    reset(flowExecutionProcessor);
    when(flowExecutionProcessor.apply(any())).thenAnswer(invocation -> {
        Mono<CoreEvent> mono = from(invocation.getArgumentAt(0, Publisher.class));
        mono.doOnNext(event -> ((BaseEventContext) event.getContext()).error(new MessagingException(event, policyException))).subscribe();
        return empty();
    });
    compositeSourcePolicy = new CompositeSourcePolicy(asList(firstPolicy, secondPolicy), sourcePolicyParametersTransformer, sourcePolicyProcessorFactory, flowExecutionProcessor, sourceParametersTransformer);
    Either<SourcePolicyFailureResult, SourcePolicySuccessResult> sourcePolicyResult = from(compositeSourcePolicy.process(initialEvent)).block();
    assertThat(sourcePolicyResult.isLeft(), is(true));
    assertThat(sourcePolicyResult.getLeft().getMessagingException(), instanceOf(FlowExecutionException.class));
    assertThat(sourcePolicyResult.getLeft().getMessagingException().getCause(), is(policyException));
}
Also used : Matchers.same(org.mockito.Matchers.same) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Message(org.mule.runtime.api.message.Message) Optional.of(java.util.Optional.of) Processor(org.mule.runtime.core.api.processor.Processor) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) ArgumentCaptor(org.mockito.ArgumentCaptor) Arrays.asList(java.util.Arrays.asList) Is.is(org.hamcrest.core.Is.is) ExpectedException.none(org.junit.rules.ExpectedException.none) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) Mono.empty(reactor.core.publisher.Mono.empty) Mono.error(reactor.core.publisher.Mono.error) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) SourcePolicyParametersTransformer(org.mule.runtime.core.api.policy.SourcePolicyParametersTransformer) Collections.emptyList(java.util.Collections.emptyList) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) EventContextFactory.create(org.mule.runtime.core.api.event.EventContextFactory.create) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Either(org.mule.runtime.core.api.functional.Either) Rule(org.junit.Rule) ArgumentCaptor.forClass(org.mockito.ArgumentCaptor.forClass) Policy(org.mule.runtime.core.api.policy.Policy) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) Optional(java.util.Optional) DefaultComponentLocation.fromSingleComponent(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation.fromSingleComponent) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Mockito.reset(org.mockito.Mockito.reset) Mockito.mock(org.mockito.Mockito.mock) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Publisher(org.reactivestreams.Publisher) Test(org.junit.Test)

Aggregations

MessagingException (org.mule.runtime.core.internal.exception.MessagingException)69 Test (org.junit.Test)42 SmallTest (org.mule.tck.size.SmallTest)37 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)26 MuleException (org.mule.runtime.api.exception.MuleException)17 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)13 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)11 Optional (java.util.Optional)9 Error (org.mule.runtime.api.message.Error)9 Message (org.mule.runtime.api.message.Message)9 IOException (java.io.IOException)8 Processor (org.mule.runtime.core.api.processor.Processor)8 Publisher (org.reactivestreams.Publisher)8 ConnectException (java.net.ConnectException)7 Component (org.mule.runtime.api.component.Component)7 ConnectionException (org.mule.runtime.api.connection.ConnectionException)7 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)7 SocketException (java.net.SocketException)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 MuleFatalException (org.mule.runtime.api.exception.MuleFatalException)6