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;
}
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));
}
}
}
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));
}
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)));
}
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);
}
Aggregations