Search in sources :

Example 6 with ErrorType

use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.

the class MessagingExceptionResolver method collectCritical.

private List<Pair<Throwable, ErrorType>> collectCritical(Component obj, MessagingException me, ErrorTypeLocator locator) {
    List<Pair<Throwable, ErrorType>> errors = new LinkedList<>();
    getExceptionsAsList(me).forEach(e -> {
        ErrorType type = errorTypeFromException(obj, locator, e);
        if (isCriticalMuleError(type)) {
            errors.add(new Pair<>(e, type));
        }
    });
    return errors;
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) LinkedList(java.util.LinkedList) Pair(org.mule.runtime.api.util.Pair)

Example 7 with ErrorType

use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.

the class ReactiveInterceptorAdapterTestCase method interceptorMutatesEventAroundAfterFailWithErrorType.

@Test
public void interceptorMutatesEventAroundAfterFailWithErrorType() throws Exception {
    ErrorType errorTypeMock = mock(ErrorType.class);
    when(errorTypeMock.getIdentifier()).thenReturn("ID");
    when(errorTypeMock.getNamespace()).thenReturn("NS");
    ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {

        @Override
        public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
            event.message(Message.of(TEST_PAYLOAD));
            return action.fail(errorTypeMock);
        }
    });
    startFlowWithInterceptors(interceptor);
    expected.expect(MessagingException.class);
    expected.expect(withEventThat(hasErrorTypeThat(sameInstance(errorTypeMock))));
    expected.expectCause(instanceOf(InterceptionException.class));
    try {
        process(flow, eventBuilder(muleContext).message(Message.of("")).build());
    } finally {
        if (useMockInterceptor) {
            InOrder inOrder = inOrder(processor, interceptor);
            inOrder.verify(interceptor).before(any(), mapArgWithEntry("param", ""), any());
            inOrder.verify(interceptor).around(any(), mapArgWithEntry("param", ""), any(), any());
            inOrder.verify(processor, never()).process(any());
            inOrder.verify(interceptor).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), argThat(not(empty())));
            verifyParametersResolvedAndDisposed(times(1));
        }
    }
}
Also used : DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) CompletableFuture(java.util.concurrent.CompletableFuture) InOrder(org.mockito.InOrder) ErrorType(org.mule.runtime.api.message.ErrorType) EventMatcher.hasErrorType(org.mule.tck.junit4.matcher.EventMatcher.hasErrorType) 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 8 with ErrorType

use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.

the class ErrorTypeBuilderTestCase method createsExpectedTypeAndRepresentation.

@Test
public void createsExpectedTypeAndRepresentation() {
    ErrorType errorType = errorTypeBuilder.namespace(NAMESPACE).identifier(IDENTIFIER).parentErrorType(mockErrorType).build();
    assertThat(errorType.getParentErrorType(), is(mockErrorType));
    assertThat(errorType.getNamespace(), is(NAMESPACE));
    assertThat(errorType.getIdentifier(), is(IDENTIFIER));
    assertThat(errorType.toString(), is(REPRESENTATION));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) Test(org.junit.Test)

Example 9 with ErrorType

use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.

the class ErrorTypeLocatorTestCase method useDefaultErrorWhenNoMappingFound.

@Test
public void useDefaultErrorWhenNoMappingFound() {
    ErrorType mockedError = mock(ErrorType.class);
    ErrorType unknown = repository.getErrorType(UNKNOWN).get();
    ErrorTypeLocator locator = ErrorTypeLocator.builder(repository).defaultExceptionMapper(ExceptionMapper.builder().addExceptionMapping(Exception.class, mockedError).build()).defaultError(unknown).build();
    ErrorType expectedError = locator.lookupErrorType(Exception.class);
    assertThat(expectedError, is(sameInstance(mockedError)));
    ErrorType defaultError = locator.lookupErrorType(Throwable.class);
    assertThat(defaultError, is(sameInstance(unknown)));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) Test(org.junit.Test)

Example 10 with ErrorType

use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.

the class PipelineMessageNotificationTestCase method mockErrorTypeLocator.

private void mockErrorTypeLocator() {
    ErrorTypeLocator typeLocator = mock(ErrorTypeLocator.class);
    ErrorType errorType = mock(ErrorType.class);
    when(errorType.getIdentifier()).thenReturn("ID");
    when(errorType.getNamespace()).thenReturn("NS");
    when(typeLocator.lookupErrorType(any(Throwable.class))).thenReturn(errorType);
    when(typeLocator.<String, Throwable>lookupComponentErrorType(any(ComponentIdentifier.class), any(Throwable.class))).thenReturn(errorType);
    when(((PrivilegedMuleContext) muleContext).getErrorTypeLocator()).thenReturn(typeLocator);
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext)

Aggregations

ErrorType (org.mule.runtime.api.message.ErrorType)35 Test (org.junit.Test)19 SmallTest (org.mule.tck.size.SmallTest)9 SingleErrorTypeMatcher (org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)8 Error (org.mule.runtime.api.message.Error)7 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)6 ErrorTypeMatcher (org.mule.runtime.core.api.exception.ErrorTypeMatcher)6 ErrorTypeLocator (org.mule.runtime.core.privileged.exception.ErrorTypeLocator)6 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)5 Optional (java.util.Optional)4 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)4 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)4 PrivilegedMuleContext (org.mule.runtime.core.privileged.PrivilegedMuleContext)4 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Component (org.mule.runtime.api.component.Component)3 TypedException (org.mule.runtime.api.exception.TypedException)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 HashSet (java.util.HashSet)2