@Override protected void describeMismatchSafely(ErrorType item, Description mismatchDescription) { mismatchDescription .appendText(format("was an ErrorType with namespace <%s> and type: <%s>", item.getNamespace(), item.getIdentifier())); } }
private boolean isAllowedError(ErrorType errorType) { return allowedErrorTypes .stream() .anyMatch(errorModel -> { boolean isAllowed = false; ErrorType currentError = errorType; while (currentError != null && !isAllowed) { isAllowed = errorModel.getType().equals(currentError.getIdentifier()) && errorModel.getNamespace().equals(currentError.getNamespace()); currentError = currentError.getParentErrorType(); } return isAllowed; }); }
@Test public void getsAvailableErrorTypes() { Optional<ErrorType> myErrorType = errorTypeRepository.getErrorType(CONNECTIVITY); assertThat(myErrorType.isPresent(), is(true)); assertThat(myErrorType.get().getIdentifier(), is(CONNECTIVITY_ERROR_IDENTIFIER)); assertThat(myErrorType.get().getParentErrorType().getIdentifier(), is(ANY_IDENTIFIER)); }
@Override protected boolean matchesSafely(MessagingException item) { errorTypeId = item.getEvent().getError().get().getErrorType().getIdentifier(); return FLOW_BACK_PRESSURE_ERROR_IDENTIFIER.equals(errorTypeId); } };
@Test public void acceptsCriticalChild() { ErrorType errorType = mock(ErrorType.class); when(error.getErrorType()).thenReturn(errorType); when(errorType.getParentErrorType()).thenReturn(CRITICAL_ERROR_TYPE); assertThat(handler.accept(muleEvent), is(true)); }
@Test public void getsUnavailableErrorTypes() { Optional<ErrorType> myErrorType = errorTypeRepository.getErrorType(INTERNAL_ERROR); assertThat(myErrorType.isPresent(), is(true)); assertThat(myErrorType.get().getIdentifier(), is("NAME")); assertThat(myErrorType.get().getParentErrorType().getIdentifier(), is(CRITICAL_IDENTIFIER)); }
@Override public Supplier<SourceResult> resolve(ExecutionContext executionContext) { return new LazyValue<>(() -> { Error error = errorArgumentResolver.resolve(executionContext).get(); SourceCallbackContext callbackContext = callbackContextArgumentResolver.resolve(executionContext).get(); if (error == null) { return success(callbackContext); } else { String errorIdentifier = error.getErrorType().getIdentifier(); return isErrorGeneratingErrorResponse(errorIdentifier) ? invocationError(error, callbackContext) : responseError(error, callbackContext); } }); }
@Test public void allMatch() { ErrorType mockErrorType = mock(ErrorType.class); when(mockErrorType.getParentErrorType()).thenReturn(transformationErrorType); ErrorTypeMatcher matcherWithTwoTransformation = createMatcher(transformationErrorType, mockErrorType); assertThat(matcherWithTwoTransformation.match(mockErrorType), is(true)); }
@Override protected boolean matchesSafely(ErrorType item) { return type.matches(item.getIdentifier()) && namespace.matches(item.getNamespace()); }
@Test public void lookupErrorsForOperation() { when(extensionModel.getErrorModels()).thenReturn(singleton(extensionConnectivityError)); errorsRegistrant.registerErrors(extensionModel); ErrorType errorType = typeLocator.lookupComponentErrorType(OPERATION_IDENTIFIER, ConnectionException.class); assertThat(errorType.getIdentifier(), is(CONNECTIVITY_ERROR_IDENTIFIER)); assertThat(errorType.getNamespace(), is(EXTENSION_PREFIX.toUpperCase())); ErrorType muleConnectivityError = errorType.getParentErrorType(); assertThat(muleConnectivityError.getNamespace(), is(MULE_CONNECTIVITY_ERROR.getNamespace())); assertThat(muleConnectivityError.getIdentifier(), is(MULE_CONNECTIVITY_ERROR.getType())); ErrorType anyErrorType = muleConnectivityError.getParentErrorType(); assertThat(anyErrorType.getNamespace(), is(MULE)); assertThat(anyErrorType.getIdentifier(), is(ANY)); assertThat(anyErrorType.getParentErrorType(), is(nullValue())); }
@Test public void lookupsAvailableErrorType() { Optional<ErrorType> errorType = errorTypeRepository.lookupErrorType(CONNECTIVITY); assertThat(errorType.isPresent(), is(true)); assertThat(errorType.get().getIdentifier(), is(CONNECTIVITY.getName())); assertThat(errorType.get().getParentErrorType().getIdentifier(), is(ANY_IDENTIFIER)); }
@Test public void fullErrorBinding() throws Exception { String description = "An error occurred"; String detailedDescription = "A division by zero has collapsed our systems."; String exceptionMessage = "dividend cannot be zero"; String errorId = "WEAVE_TEST"; ErrorType errorType = mock(ErrorType.class); when(errorType.getIdentifier()).thenReturn(errorId); Error error = ErrorBuilder.builder() .description(description) .detailedDescription(detailedDescription) .exception(new IllegalArgumentException(exceptionMessage)) .errorType(errorType) .build(); Optional opt = Optional.of(error); CoreEvent event = getEventWithError(opt); doReturn(testEvent().getMessage()).when(event).getMessage(); String expression = "'$(error.description) $(error.detailedDescription) $(error.cause.message) $(error.errorType.identifier)'"; TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build()); assertThat(result.getValue(), is(format("%s %s %s %s", description, detailedDescription, exceptionMessage, errorId))); }
@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)); }
private EventMatcher isErrorTypeFlowFailure() { return hasErrorType(ERROR_FROM_FLOW.getNamespace(), ERROR_FROM_FLOW.getIdentifier()); }
@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)); }
@Test public void getsUnavailableErrorTypes() { Optional<ErrorType> myErrorType = errorTypeRepository.getErrorType(INTERNAL_ERROR); assertThat(myErrorType.isPresent(), is(true)); assertThat(myErrorType.get().getIdentifier(), is("NAME")); assertThat(myErrorType.get().getParentErrorType().getIdentifier(), is(CRITICAL_IDENTIFIER)); }
@Override public CompletableFuture<InterceptionEvent> fail(ErrorType errorType) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Called fail() for processor {} with errorType {}", ((Component) processor).getLocation().getLocation(), errorType.getIdentifier()); } Throwable cause = new InterceptionException(""); interceptionEvent.setError(errorType, cause); CompletableFuture<InterceptionEvent> completableFuture = new CompletableFuture<>(); completableFuture .completeExceptionally(new MessagingException(interceptionEvent.resolve(), cause, (Component) processor)); return completableFuture; } }
@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)); }
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); }
private boolean isAllowedError(ErrorType errorType) { return allowedErrorTypes .stream() .anyMatch(errorModel -> { boolean isAllowed = false; ErrorType currentError = errorType; while (currentError != null && !isAllowed) { isAllowed = errorModel.getType().equals(currentError.getIdentifier()) && errorModel.getNamespace().equals(currentError.getNamespace()); currentError = currentError.getParentErrorType(); } return isAllowed; }); }