Search in sources :

Example 1 with ModuleException

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));
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ErrorType(org.mule.runtime.api.message.ErrorType) ModuleException(org.mule.runtime.extension.api.exception.ModuleException) TypedException(org.mule.runtime.api.exception.TypedException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with ModuleException

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));
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ErrorType(org.mule.runtime.api.message.ErrorType) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) ModuleException(org.mule.runtime.extension.api.exception.ModuleException) TypedException(org.mule.runtime.api.exception.TypedException) HashSet(java.util.HashSet) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with ModuleException

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");
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ModuleException(org.mule.runtime.extension.api.exception.ModuleException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with ModuleException

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.");
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ModuleException(org.mule.runtime.extension.api.exception.ModuleException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)4 ModuleException (org.mule.runtime.extension.api.exception.ModuleException)4 SmallTest (org.mule.tck.size.SmallTest)4 TypedException (org.mule.runtime.api.exception.TypedException)2 ErrorType (org.mule.runtime.api.message.ErrorType)2 HashSet (java.util.HashSet)1 ErrorModel (org.mule.runtime.api.meta.model.error.ErrorModel)1