Search in sources :

Example 6 with PrivilegedMuleContext

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

the class ExtensionErrorsRegistrantTestCase method setUp.

@Before
public void setUp() {
    XmlDslModel.XmlDslModelBuilder builder = XmlDslModel.builder();
    builder.setPrefix(EXTENSION_PREFIX);
    XmlDslModel xmlDslModel = builder.build();
    typeRepository = createDefaultErrorTypeRepository();
    typeLocator = createDefaultErrorTypeLocator(typeRepository);
    when(muleContext.getErrorTypeRepository()).thenReturn(typeRepository);
    when(((PrivilegedMuleContext) muleContext).getErrorTypeLocator()).thenReturn(typeLocator);
    errorsRegistrant = new ExtensionErrorsRegistrant(muleContext.getErrorTypeRepository(), ((PrivilegedMuleContext) muleContext).getErrorTypeLocator());
    when(extensionModel.getOperationModels()).thenReturn(asList(operationWithError, operationWithoutErrors));
    when(extensionModel.getXmlDslModel()).thenReturn(xmlDslModel);
    when(extensionModel.getName()).thenReturn(TEST_EXTENSION_NAME);
    when(operationWithError.getErrorModels()).thenReturn(singleton(extensionConnectivityError));
    when(operationWithError.getName()).thenReturn(OPERATION_NAME);
    when(operationWithError.getModelProperty(any())).thenReturn(empty());
    when(operationWithoutErrors.getName()).thenReturn("operationWithoutError");
    when(operationWithoutErrors.getErrorModels()).thenReturn(emptySet());
    when(operationWithoutErrors.getModelProperty(any())).thenReturn(empty());
    visitableMock(operationWithError, operationWithoutErrors);
}
Also used : XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext) Before(org.junit.Before)

Example 7 with PrivilegedMuleContext

use of org.mule.runtime.core.privileged.PrivilegedMuleContext 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

PrivilegedMuleContext (org.mule.runtime.core.privileged.PrivilegedMuleContext)7 ErrorTypeLocator (org.mule.runtime.core.privileged.exception.ErrorTypeLocator)5 ErrorType (org.mule.runtime.api.message.ErrorType)4 Before (org.junit.Before)3 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)3 Component (org.mule.runtime.api.component.Component)2 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)2 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 Test (org.junit.Test)1 Location (org.mule.runtime.api.component.location.Location)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 Event (org.mule.runtime.api.event.Event)1 ExceptionHelper.getExceptionsAsList (org.mule.runtime.api.exception.ExceptionHelper.getExceptionsAsList)1