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();
}
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());
}
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());
}
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;
}
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);
}
Aggregations