use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.
the class MessageProcessingFlowTraceManagerTestCase method createMockProcessor.
public Processor createMockProcessor(String processorPath, boolean useLocationSettings) {
ComponentLocation componentLocation = mock(ComponentLocation.class);
when(componentLocation.getLocation()).thenReturn(processorPath);
when(componentLocation.getFileName()).thenReturn(useLocationSettings ? of(CONFIG_FILE_NAME) : empty());
when(componentLocation.getLineInFile()).thenReturn(useLocationSettings ? of(LINE_NUMBER) : empty());
Component annotatedMessageProcessor = (Component) mock(Processor.class, withSettings().extraInterfaces(Component.class).defaultAnswer(RETURNS_DEEP_STUBS));
when(annotatedMessageProcessor.getAnnotation(any())).thenReturn(null);
when(annotatedMessageProcessor.getLocation()).thenReturn(componentLocation);
return (Processor) annotatedMessageProcessor;
}
use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.
the class MVELExpressionLanguage method evaluate.
@Override
public TypedValue evaluate(String expression, CoreEvent event, CoreEvent.Builder eventBuilder, ComponentLocation componentLocation, BindingContext bindingContext) {
expression = removeExpressionMarker(expression);
Map<String, Object> bindingMap = bindingContext.identifiers().stream().collect(toMap(id -> id, id -> bindingContext.lookup(id).get().getValue()));
final Object value = evaluateUntyped(expression, (PrivilegedEvent) event, (PrivilegedEvent.Builder) eventBuilder, componentLocation, bindingMap);
if (value instanceof TypedValue) {
return (TypedValue) value;
} else {
final Serializable compiledExpression = expressionExecutor.getCompiledExpression(expression);
DataType dataType = event != null ? dataTypeResolver.resolve(value, (PrivilegedEvent) event, compiledExpression) : OBJECT;
return new TypedValue(value, dataType);
}
}
use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.
the class NotificationHelperTestCase method fireNotificationUsingLocation.
@Test
public void fireNotificationUsingLocation() {
final LocationPart flowPart = mock(LocationPart.class);
when(flowPart.getPartPath()).thenReturn("flowName");
final ComponentLocation location = mock(ComponentLocation.class);
when(location.getParts()).thenReturn(Collections.singletonList(flowPart));
when(location.getComponentIdentifier()).thenReturn(TypedComponentIdentifier.builder().type(SOURCE).identifier(buildFromStringRepresentation("http:listener")).build());
when(messageSource.getLocation()).thenReturn(location);
final FlowConstruct flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class));
when(flowConstruct.getMuleContext()).thenReturn(muleContext);
final int action = 100;
helper.fireNotification(messageSource, event, location, action);
assertConnectorMessageNotification(eventNotificationHandler, messageSource, location, action);
}
use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method firstInterceptorMutatesEventAfter.
@Test
public void firstInterceptorMutatesEventAfter() throws Exception {
ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
@Override
public void after(ComponentLocation location, InterceptionEvent event, Optional<Throwable> thrown) {
event.message(Message.of(TEST_PAYLOAD));
}
});
ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {
});
startFlowWithInterceptors(interceptor1, interceptor2);
CoreEvent result = process(flow, eventBuilder(muleContext).message(Message.of("")).build());
assertThat(result.getMessage().getPayload().getValue(), is(TEST_PAYLOAD));
assertThat(result.getError().isPresent(), is(false));
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor1, interceptor2);
inOrder.verify(interceptor1).before(any(), any(), any());
inOrder.verify(interceptor2).before(any(), any(), any());
inOrder.verify(interceptor1).around(any(), any(), any(), any());
inOrder.verify(interceptor2).around(any(), any(), any(), any());
inOrder.verify(processor).process(argThat(hasPayloadValue("")));
inOrder.verify(interceptor2).after(any(), any(), eq(empty()));
inOrder.verify(interceptor1).after(any(), any(), eq(empty()));
assertThat(((InternalEvent) result).getInternalParameters().entrySet(), hasSize(0));
verifyParametersResolvedAndDisposed(times(1));
}
}
use of org.mule.runtime.api.component.location.ComponentLocation in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorMutatesEventAroundAfterFailWithCause.
@Test
public void interceptorMutatesEventAroundAfterFailWithCause() throws Exception {
Throwable cause = new RuntimeException("");
ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
event.message(Message.of(TEST_PAYLOAD));
return action.fail(cause);
}
});
startFlowWithInterceptors(interceptor);
expected.expectCause(sameInstance(cause));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor);
inOrder.verify(interceptor).before(any(), mapArgWithEntry("param", ""), any());
inOrder.verify(interceptor).around(any(), mapArgWithEntry("param", ""), any(), any());
inOrder.verify(processor, never()).process(any());
inOrder.verify(interceptor).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), eq(of(cause)));
verifyParametersResolvedAndDisposed(times(1));
}
}
}
Aggregations