use of org.mule.runtime.extension.api.exception.ModuleException in project mule by mulesoft.
the class ModuleExceptionHandlerTestCase method handleTypedException.
@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));
}
use of org.mule.runtime.extension.api.exception.ModuleException in project mule by mulesoft.
the class ModuleExceptionHandlerTestCase method handleThrowingChildErrorsFromTheOneDeclared.
@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));
}
use of org.mule.runtime.extension.api.exception.ModuleException in project mule by mulesoft.
the class ModuleExceptionHandlerTestCase method handleThrowingOfNotRegisteredErrorType.
@Test
public void handleThrowingOfNotRegisteredErrorType() {
when(operationModel.getErrorModels()).thenReturn(singleton(newError(CONNECTIVITY_ERROR_IDENTIFIER, ERROR_NAMESPACE).build()));
ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository);
ModuleException moduleException = new ModuleException(CONNECTIVITY, new RuntimeException());
assertThatThrownBy(() -> handler.processException(moduleException)).isInstanceOf(MuleRuntimeException.class).hasMessage("The component 'testOperation' from the connector 'Test Extension' attempted to throw 'TEST-EXTENSION:CONNECTIVITY'," + " but it was not registered in the Error Repository");
}
use of org.mule.runtime.extension.api.exception.ModuleException in project mule by mulesoft.
the class ModuleExceptionHandlerTestCase method handleThrowingOfNotDeclaredErrorType.
@Test
public void handleThrowingOfNotDeclaredErrorType() {
typeRepository.addErrorType(buildFromStringRepresentation(ERROR_NAMESPACE + ":" + CONNECTIVITY_ERROR_IDENTIFIER), typeRepository.getAnyErrorType());
when(operationModel.getErrorModels()).thenReturn(singleton(newError(TRANSFORMATION_ERROR_IDENTIFIER, ERROR_NAMESPACE).build()));
ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository);
ModuleException moduleException = new ModuleException(CONNECTIVITY, new RuntimeException());
assertThatThrownBy(() -> handler.processException(moduleException)).isInstanceOf(MuleRuntimeException.class).hasMessage("The component 'testOperation' from the connector 'Test Extension' attempted to throw 'TEST-EXTENSION:CONNECTIVITY', " + "but only [TEST-EXTENSION:TRANSFORMATION] errors are allowed.");
}
Aggregations