@Override protected boolean matchesSafely(ErrorType item) { return type.matches(item.getIdentifier()) && namespace.matches(item.getNamespace()); }
@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; }); }
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); }
@Before public void before() throws MuleException { event = newEvent(); when(errorType.getIdentifier()).thenReturn("ID"); when(errorType.getNamespace()).thenReturn("NS"); when(errorTypeLocator.lookupErrorType(any(Exception.class))).thenReturn(errorType); when(messageProcessContext.getErrorTypeLocator()).thenReturn(errorTypeLocator); when(messageProcessContext.getMessageSource()).thenReturn(messageSource); callback = new ExtensionSourceExceptionCallback(responseCallback, event, exceptionHandlingCallback, messageProcessContext); }
private EventMatcher isErrorTypeFlowFailure() { return hasErrorType(ERROR_FROM_FLOW.getNamespace(), ERROR_FROM_FLOW.getIdentifier()); }
@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())); }
@Override protected boolean matchesSafely(TypedException item) { ErrorType errorType = item.getErrorType(); return errorIdentifier.getNamespace().equals(errorType.getNamespace()) && errorIdentifier.getName().equals( errorType .getIdentifier()); }
@Test public void handleTypedException() { when(operationModel.getErrorModels()).thenReturn(singleton(newError(CONNECTIVITY_ERROR_IDENTIFIER, ERROR_NAMESPACE).build())); ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository); typeRepository.addErrorType(builder() .name(CONNECTIVITY_ERROR_IDENTIFIER) .namespace(ERROR_NAMESPACE) .build(), typeRepository.getAnyErrorType()); ModuleException moduleException = new ModuleException(CONNECTIVITY, new RuntimeException()); Throwable exception = handler.processException(moduleException); assertThat(exception, is(instanceOf(TypedException.class))); ErrorType errorType = ((TypedException) exception).getErrorType(); assertThat(errorType.getIdentifier(), is(CONNECTIVITY_ERROR_IDENTIFIER)); assertThat(errorType.getNamespace(), is(ERROR_NAMESPACE)); }
@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 handleThrowingChildErrorsFromTheOneDeclared() { Set<ErrorModel> errors = new HashSet<>(); ErrorModel parent = newError(PARENT.getType(), ERROR_NAMESPACE).build(); ErrorModel child = newError(CHILD.getType(), ERROR_NAMESPACE).withParent(parent).build(); errors.add(parent); ErrorType parentErrorType = typeRepository.addErrorType(getIdentifier(parent), typeRepository.getAnyErrorType()); typeRepository.addErrorType(getIdentifier(child), parentErrorType); when(operationModel.getErrorModels()).thenReturn(errors); ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository); ModuleException moduleException = new ModuleException(CHILD, new RuntimeException()); Throwable throwable = handler.processException(moduleException); assertThat(throwable, is(instanceOf(TypedException.class))); ErrorType errorType = ((TypedException) throwable).getErrorType(); assertThat(errorType.getIdentifier(), is(CHILD.getType())); assertThat(errorType.getNamespace(), is(ERROR_NAMESPACE)); }
ErrorType errorTypeMock = mock(ErrorType.class); when(errorTypeMock.getIdentifier()).thenReturn("ID"); when(errorTypeMock.getNamespace()).thenReturn("NS"); ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {
/** * Checks if an error type is MULE:UNKNOWN */ public static boolean isUnknownMuleError(ErrorType type) { return type.getNamespace().equals(CORE_NAMESPACE_NAME) && type.getIdentifier().equals(UNKNOWN_ERROR_IDENTIFIER); }
@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 isCriticalMuleError(ErrorType type) { return type.getNamespace().equals(CORE_NAMESPACE_NAME) && type.getIdentifier().equals(CRITICAL_IDENTIFIER); } }
@Override protected boolean matchesSafely(ErrorType item) { return type.matches(item.getIdentifier()) && namespace.matches(item.getNamespace()); }
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); }
@Override protected boolean matchesSafely(TypedException item) { ErrorType errorType = item.getErrorType(); return errorIdentifier.getNamespace().equals(errorType.getNamespace()) && errorIdentifier.getName().equals( errorType .getIdentifier()); }
private void assertErrorType(Callable task, String errorNamespace, String errorIdentifier) throws Exception { try { task.call(); fail("Expected exception"); } catch (MessagingException e) { InternalEvent event = e.getEvent(); Error error = event.getError().orElse(null); assertThat(error, is(notNullValue())); assertThat(error.getErrorType().getNamespace(), equalTo(errorNamespace)); assertThat(error.getErrorType().getIdentifier(), equalTo(errorIdentifier)); } } }
@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)); }