Search in sources :

Example 6 with ErrorTypeLocator

use of org.mule.runtime.core.privileged.exception.ErrorTypeLocator in project mule by mulesoft.

the class DefaultMessageProcessorChainTestCase method before.

@Before
public void before() throws MuleException {
    nonBlockingProcessorsExecuted.set(0);
    muleContext = spy(super.muleContext);
    ErrorTypeLocator errorTypeLocator = mock(ErrorTypeLocator.class);
    ErrorType errorType = mock(ErrorType.class);
    ExceptionContextProvider exceptionContextProvider = mock(ExceptionContextProvider.class);
    MuleConfiguration muleConfiguration = mock(MuleConfiguration.class);
    when(muleConfiguration.isContainerMode()).thenReturn(false);
    when(muleConfiguration.getId()).thenReturn(randomNumeric(3));
    when(muleConfiguration.getShutdownTimeout()).thenReturn(1000L);
    when(muleContext.getConfiguration()).thenReturn(muleConfiguration);
    when(((PrivilegedMuleContext) muleContext).getErrorTypeLocator()).thenReturn(errorTypeLocator);
    when(muleContext.getExceptionContextProviders()).thenReturn(singletonList(exceptionContextProvider));
    when(errorTypeLocator.lookupErrorType((Exception) any())).thenReturn(errorType);
    flow = builder("flow", muleContext).processingStrategyFactory(processingStrategyFactory).build();
    flow.initialise();
    flow.start();
}
Also used : ExceptionContextProvider(org.mule.runtime.core.api.execution.ExceptionContextProvider) MuleConfiguration(org.mule.runtime.core.api.config.MuleConfiguration) ErrorType(org.mule.runtime.api.message.ErrorType) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext) Before(org.junit.Before)

Example 7 with ErrorTypeLocator

use of org.mule.runtime.core.privileged.exception.ErrorTypeLocator in project mule by mulesoft.

the class ExtensionErrorsRegistrantTestCase method operationWithoutErrorsDoesntGenerateComponentMapper.

@Test
public void operationWithoutErrorsDoesntGenerateComponentMapper() {
    when(extensionModel.getOperationModels()).thenReturn(singletonList(operationWithoutErrors));
    ErrorTypeLocator mockTypeLocator = mock(ErrorTypeLocator.class);
    errorsRegistrant = new ExtensionErrorsRegistrant(typeRepository, mockTypeLocator);
    errorsRegistrant.registerErrors(extensionModel);
    verify(mockTypeLocator, times(0)).addComponentExceptionMapper(any(), any());
}
Also used : ErrorTypeLocatorFactory.createDefaultErrorTypeLocator(org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 8 with ErrorTypeLocator

use of org.mule.runtime.core.privileged.exception.ErrorTypeLocator in project mule by mulesoft.

the class ExtensionErrorsRegistrantTestCase method operationTriesToAddInternalErrorType.

@Test
public void operationTriesToAddInternalErrorType() {
    ErrorTypeRepository repository = mock(ErrorTypeRepository.class);
    when(repository.getErrorType(any())).then((e) -> typeRepository.getErrorType(((ComponentIdentifier) e.getArguments()[0])));
    ErrorModel internalRepeatedError = ErrorModelBuilder.newError(SOURCE_RESPONSE_GENERATE).build();
    when(operationWithError.getErrorModels()).thenReturn(singleton(internalRepeatedError));
    when(extensionModel.getOperationModels()).thenReturn(singletonList(operationWithError));
    when(extensionModel.getErrorModels()).thenReturn(singleton(internalRepeatedError));
    ErrorTypeLocator mockTypeLocator = mock(ErrorTypeLocator.class);
    errorsRegistrant = new ExtensionErrorsRegistrant(typeRepository, mockTypeLocator);
    errorsRegistrant.registerErrors(extensionModel);
    verify(repository, times(0)).addErrorType(any(), any());
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository(org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository) ErrorTypeLocatorFactory.createDefaultErrorTypeLocator(org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 9 with ErrorTypeLocator

use of org.mule.runtime.core.privileged.exception.ErrorTypeLocator in project mule by mulesoft.

the class ExtensionPluginMetadataGenerator method createExtensionManager.

/**
 * Creates a {@link ExtensionManager} needed for generating the metadata for an extension. It would be later discarded due to
 * the manager would have references to classes loaded with the launcher class loader instead of the hierarchical class loaders
 * created as result of the classification process.
 *
 * @return an {@link ExtensionManager} that would be used to register the extensions.
 */
private ExtensionManager createExtensionManager() {
    DefaultExtensionManager extensionManager = new DefaultExtensionManager();
    extensionManager.setMuleContext(new DefaultMuleContext() {

        private ErrorTypeRepository errorTypeRepository = createDefaultErrorTypeRepository();

        private ErrorTypeLocator errorTypeLocator = createDefaultErrorTypeLocator(errorTypeRepository);

        @Override
        public MuleRegistry getRegistry() {
            return new MuleRegistryHelper(new DefaultRegistryBroker(this, new MuleLifecycleInterceptor()), this);
        }

        @Override
        public ErrorTypeLocator getErrorTypeLocator() {
            return errorTypeLocator;
        }

        @Override
        public ErrorTypeRepository getErrorTypeRepository() {
            return errorTypeRepository;
        }
    });
    try {
        extensionManager.initialise();
    } catch (InitialisationException e) {
        throw new RuntimeException("Error while initialising the extension manager", e);
    }
    return extensionManager;
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository(org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository) MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) DefaultMuleContext(org.mule.runtime.core.internal.context.DefaultMuleContext) DefaultRegistryBroker(org.mule.runtime.core.internal.registry.DefaultRegistryBroker) ErrorTypeLocatorFactory.createDefaultErrorTypeLocator(org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) DefaultExtensionManager(org.mule.runtime.module.extension.internal.manager.DefaultExtensionManager)

Example 10 with ErrorTypeLocator

use of org.mule.runtime.core.privileged.exception.ErrorTypeLocator in project mule by mulesoft.

the class ModuleFlowProcessingPhaseTestCase method before.

@Before
public void before() throws Exception {
    final PrivilegedMuleContext muleContext = (PrivilegedMuleContext) mockMuleContext();
    when(muleContext.getErrorTypeRepository()).thenReturn(createDefaultErrorTypeRepository());
    ErrorTypeLocator errorTypeLocator = mock(ErrorTypeLocator.class);
    when(errorTypeLocator.lookupErrorType(any(Throwable.class))).thenReturn(ErrorTypeBuilder.builder().namespace(CORE_NAMESPACE_NAME).identifier(ANY_IDENTIFIER).build());
    when(muleContext.getErrorTypeLocator()).thenReturn(errorTypeLocator);
    event = mock(CoreEvent.class);
    mockException = mock(RuntimeException.class);
    policyManager = mock(PolicyManager.class);
    sourcePolicy = mock(SourcePolicy.class);
    when(policyManager.createSourcePolicyInstance(any(), any(), any(), any())).thenReturn(sourcePolicy);
    successResult = mock(SourcePolicySuccessResult.class);
    when(successResult.getResult()).then(invocation -> event);
    when(successResult.getResponseParameters()).thenReturn(() -> emptyMap());
    when(successResult.createErrorResponseParameters()).thenReturn(event -> emptyMap());
    failureResult = mock(SourcePolicyFailureResult.class);
    when(failureResult.getMessagingException()).then(invocation -> messagingException);
    when(failureResult.getErrorResponseParameters()).thenReturn(() -> emptyMap());
    when(sourcePolicy.process(any())).thenAnswer(invocation -> {
        event = invocation.getArgumentAt(0, CoreEvent.class);
        return just(right(successResult));
    });
    moduleFlowProcessingPhase = new ModuleFlowProcessingPhase(policyManager);
    moduleFlowProcessingPhase.setMuleContext(muleContext);
    initialiseIfNeeded(moduleFlowProcessingPhase, muleContext);
    flow = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class));
    final FlowExceptionHandler exceptionHandler = mock(FlowExceptionHandler.class);
    when(flow.getExceptionListener()).thenReturn(exceptionHandler);
    when(exceptionHandler.apply(any())).thenAnswer(invocationOnMock -> error(invocationOnMock.getArgumentAt(0, MessagingException.class)));
    when(flow.getMuleContext()).thenReturn(muleContext);
    context = mock(MessageProcessContext.class);
    final MessageSource source = mock(MessageSource.class);
    when(source.getRootContainerLocation()).thenReturn(Location.builder().globalName("root").build());
    when(source.getLocation()).thenReturn(mock(ComponentLocation.class));
    when(context.getMessageSource()).thenReturn(source);
    when(context.getTransactionConfig()).thenReturn(empty());
    when(muleContext.getConfigurationComponentLocator().find(any(Location.class))).thenReturn(of(flow));
    template = mock(ModuleFlowProcessingPhaseTemplate.class);
    when(template.getMessage()).thenReturn(Message.of(null));
    when(template.getNotificationFunctions()).thenReturn(emptyList());
    when(template.sendResponseToClient(any(), any())).thenAnswer(invocation -> Mono.empty());
    when(template.sendFailureResponseToClient(any(), any())).thenAnswer(invocation -> Mono.empty());
    notifier = mock(PhaseResultNotifier.class);
}
Also used : PolicyManager(org.mule.runtime.core.internal.policy.PolicyManager) SourcePolicyFailureResult(org.mule.runtime.core.internal.policy.SourcePolicyFailureResult) SourcePolicy(org.mule.runtime.core.internal.policy.SourcePolicy) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) MessageSource(org.mule.runtime.core.api.source.MessageSource) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext) FlowExceptionHandler(org.mule.runtime.core.api.exception.FlowExceptionHandler) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) SourcePolicySuccessResult(org.mule.runtime.core.internal.policy.SourcePolicySuccessResult) MessageProcessContext(org.mule.runtime.core.privileged.execution.MessageProcessContext) Location(org.mule.runtime.api.component.location.Location) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) Before(org.junit.Before)

Aggregations

ErrorTypeLocator (org.mule.runtime.core.privileged.exception.ErrorTypeLocator)10 ErrorType (org.mule.runtime.api.message.ErrorType)6 PrivilegedMuleContext (org.mule.runtime.core.privileged.PrivilegedMuleContext)5 Test (org.junit.Test)4 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 ErrorTypeLocatorFactory.createDefaultErrorTypeLocator (org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator)3 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)3 SmallTest (org.mule.tck.size.SmallTest)3 List (java.util.List)2 Before (org.junit.Before)2 Component (org.mule.runtime.api.component.Component)2 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)2 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)2 Error (org.mule.runtime.api.message.Error)2 ExceptionUtils.getComponentIdentifier (org.mule.runtime.core.api.util.ExceptionUtils.getComponentIdentifier)2 ExceptionUtils.isUnknownMuleError (org.mule.runtime.core.api.util.ExceptionUtils.isUnknownMuleError)2 ErrorMapping (org.mule.runtime.core.internal.exception.ErrorMapping)2 ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository (org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository)2 ErrorBuilder (org.mule.runtime.core.internal.message.ErrorBuilder)2 Collections.emptyList (java.util.Collections.emptyList)1