use of org.mule.runtime.core.api.exception.ErrorTypeMatcher in project mule by mulesoft.
the class TemplateOnErrorHandler method createErrorType.
public static ErrorTypeMatcher createErrorType(ErrorTypeRepository errorTypeRepository, String errorTypeNames) {
if (errorTypeNames == null) {
return null;
}
String[] errorTypeIdentifiers = errorTypeNames.split(",");
List<ErrorTypeMatcher> matchers = stream(errorTypeIdentifiers).map((identifier) -> {
String parsedIdentifier = identifier.trim();
return new SingleErrorTypeMatcher(errorTypeRepository.lookupErrorType(buildFromStringRepresentation(parsedIdentifier)).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Could not find ErrorType for the given identifier: '%s'", parsedIdentifier))));
}).collect(toList());
return new DisjunctiveErrorTypeMatcher(matchers);
}
use of org.mule.runtime.core.api.exception.ErrorTypeMatcher in project mule by mulesoft.
the class DisjunctiveErrorTypeMatcherTestCase method anyPresenceMatchAll.
@Test
public void anyPresenceMatchAll() {
ErrorTypeMatcher matcherWithAny = createMatcher(anyErrorType, transformationErrorType);
assertThat(matcherWithAny.match(anyErrorType), is(true));
assertThat(matcherWithAny.match(transformationErrorType), is(true));
assertThat(matcherWithAny.match(expressionErrorType), is(true));
}
use of org.mule.runtime.core.api.exception.ErrorTypeMatcher in project mule by mulesoft.
the class DisjunctiveErrorTypeMatcherTestCase method noMatch.
@Test
public void noMatch() {
ErrorType mockErrorType = mock(ErrorType.class);
when(mockErrorType.getParentErrorType()).thenReturn(anyErrorType);
ErrorTypeMatcher matcherWithTwoTransformation = createMatcher(transformationErrorType, expressionErrorType);
assertThat(matcherWithTwoTransformation.match(mockErrorType), is(false));
}
use of org.mule.runtime.core.api.exception.ErrorTypeMatcher in project mule by mulesoft.
the class DisjunctiveErrorTypeMatcherTestCase method oneMatch.
@Test
public void oneMatch() {
ErrorType mockErrorType = mock(ErrorType.class);
when(mockErrorType.getParentErrorType()).thenReturn(transformationErrorType);
ErrorTypeMatcher matcherWithTransformation = createMatcher(transformationErrorType, expressionErrorType);
assertThat(matcherWithTransformation.match(transformationErrorType), is(true));
assertThat(matcherWithTransformation.match(mockErrorType), is(true));
}
use of org.mule.runtime.core.api.exception.ErrorTypeMatcher in project mule by mulesoft.
the class SingleErrorTypeMatcherTestCase method matchChild.
@Test
public void matchChild() {
ComponentIdentifier customTransformerIdentifier = ComponentIdentifier.builder().name("custom").namespace(CORE_NAMESPACE_NAME).build();
ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
ErrorType customTransformerErrorType = errorTypeRepository.addErrorType(customTransformerIdentifier, transformationErrorType);
ErrorTypeMatcher transformationMatcher = new SingleErrorTypeMatcher(transformationErrorType);
assertThat(transformationMatcher.match(customTransformerErrorType), is(true));
}
Aggregations