@Override public CoreEvent process(CoreEvent event) throws MuleException { if (event != null && event.getMessage() != null) { return CoreEvent.builder(event) .message(Message.builder(event.getMessage()).value(event.getMessage().getPayload().getValue() + ":" + label) .build()) .build(); } return event; }
private CoreEvent handleError(Throwable error, CoreEvent childEvent) { try { errorHandler.accept(error, EventedResult.from(childEvent)); } catch (Throwable e) { ((BaseEventContext) originalEvent.getContext()).error(e); } return null; }
@Override protected boolean matchesSafely(CoreEvent item) { return (messageMatcher != null ? messageMatcher.matches(item.getMessage()) : true) && (variablesMatcher != null ? variablesMatcher.matches(item.getVariables()) : true) && (securityContextMatcher != null ? securityContextMatcher.matches(item.getSecurityContext()) : true) && (errorTypeMatcher != null ? errorTypeMatcher.matches(item.getError().get().getErrorType()) : true); }
@Override public Supplier<CorrelationInfo> resolve(ExecutionContext executionContext) { return () -> { CoreEvent event = ((ExecutionContextAdapter) executionContext).getEvent(); return new ImmutableCorrelationInfo(event.getContext().getId(), true, event.getCorrelationId(), event.getItemSequenceInfo().orElse(null)); }; } }
@Override public CoreEvent process(CoreEvent coreEvent) throws MuleException { String routeName = coreEvent.getVariables().get(EXECUTION_ROUTE_KEY).getValue().toString(); Message message = coreEvent.getMessage(); if (executionLogsMap.containsKey(routeName)) { executionLogsMap.get(routeName).logExecution(message); } else { ExecutionLog newLog = new ExecutionLog(message); executionLogsMap.put(routeName, newLog); } return coreEvent; }
@Test public void variablesAddedInNextProcessorNotPropagated() throws MuleException { CoreEvent initialEventWithVars = CoreEvent.builder(initialEvent).addVariable(INIT_VAR_NAME, INIT_VAR_VALUE).build(); CoreEvent modifiedVarsEvent = CoreEvent.builder(initialEvent).addVariable(ADDED_VAR_NAME, ADDED_VAR_VALUE).build(); mockFlowReturningEvent(modifiedVarsEvent); when(policy.getPolicyChain().apply(any())).thenAnswer(invocation -> Flux.<CoreEvent>from(invocation.getArgument(0))); CoreEvent resultEvent = just(initialEventWithVars).transform(policyProcessor).block(); assertEquals(resultEvent.getVariables().keySet(), initialEventWithVars.getVariables().keySet()); }
@Before public void setUp() { when(event.getError()).thenReturn(empty()); when(event.getAuthentication()).thenReturn(empty()); Message msg = of(null); when(event.getMessage()).thenReturn(msg); when(event.asBindingContext()).thenReturn(getTargetBindingContext(msg)); when(event.getItemSequenceInfo()).thenReturn(empty()); }
@Override public CoreEvent process(CoreEvent event) throws MuleException { event.getError().ifPresent(theError -> exception = theError.getCause()); TypedValue<Object> payload = event.getMessage().getPayload(); if (payload.getValue() != null) { messages.add((TestTransactionalConnection) payload.getValue()); } return event; }
@Test public void testExecuteWithInputEvent() throws Exception { ExecutionResult executionResult = executableComponent.execute(InputEvent.create().message(requestMessage)).get(); Event response = executionResult.getEvent(); assertThat(componentInEvent.get().getMessage(), equalTo(requestMessage)); assertThat(response.getMessage(), equalTo(responseMessage)); assertThat(componentInEvent.get().getContext(), equalTo(response.getContext())); BaseEventContext eventContext = (BaseEventContext) componentInEvent.get().getContext(); assertThat(eventContext.isTerminated(), is(false)); executionResult.complete(); assertThat(eventContext.isTerminated(), is(true)); }
@Test public void securityContextCopy() throws Exception { SecurityContext securityContext = mock(SecurityContext.class); CoreEvent event = CoreEvent.builder(testEvent()).securityContext(securityContext).build(); CoreEvent eventCopy = CoreEvent.builder(event).message(Message.of("copy")).build(); assertThat(securityContext, sameInstance(eventCopy.getSecurityContext())); }
assertEquals(2, ((List<InternalMessage>) result.getMessage().getPayload().getValue()).size()); assertTrue(result.getMessage().getPayload().getValue() instanceof List<?>); assertEquals(messageCollection, ((List<InternalMessage>) result.getMessage().getPayload().getValue()).get(0)); assertEquals(messageCollection2, ((List<InternalMessage>) result.getMessage().getPayload().getValue()).get(1)); assertThat(result.getVariables().get("key1").getValue(), equalTo("value1")); assertThat(result.getVariables().get("key2").getValue(), equalTo("value2")); assertThat(result.getVariables().get("key3").getValue(), equalTo("value3")); assertThat(result.getCorrelationId(), equalTo(event1.getCorrelationId()));
private void assertLogicallyEqualEvents(final CoreEvent testEvent, CoreEvent eventReceived) throws MuleException { // events have been rewritten so are different but the correlation ID has been carried around assertEquals(testEvent.getCorrelationId(), eventReceived.getCorrelationId()); // and their payload assertEquals(testEvent.getMessage(), eventReceived.getMessage()); }
@Override public Supplier<Error> resolve(ExecutionContext executionContext) { return () -> ((ExecutionContextAdapter) executionContext).getEvent().getError().orElse(null); } }
@Override public void changeEvent(CoreEvent updated) { requireNonNull(event); event = updated; securityContext = event.getSecurityContext(); }
@Override public CoreEvent process(CoreEvent event) throws MuleException { correlationId = event.getCorrelationId(); return event; } }
protected CoreEvent buildEvent(String eventId, FlowCallStack flowStack) { CoreEvent event = mock(CoreEvent.class); when(event.getContext()).thenReturn(messageContext); when(event.getContext()).thenReturn(messageContext); when(event.getFlowCallStack()).thenReturn(flowStack); return event; }
@Test public void sessionEvaluatesPayloadExpressionWithExpectedDataType() throws MuleException { TypedValue<String> stringJsonPayload = new TypedValue<>("\"string\"", JSON_STRING); CoreEvent eventWithJsonPayload = CoreEvent.builder(testEvent()).message(Message.of(stringJsonPayload)).build(); BindingContext bindingContext = eventWithJsonPayload.asBindingContext(); ExpressionLanguageSessionAdaptor session = expressionLanguage.openSession(TEST_CONNECTOR_LOCATION, null, bindingContext); assertThat(session.evaluate("payload", STRING).getValue(), is("string")); }
public ValueResolvingContext build() { if (event == null) { return new ValueResolvingContext(null, null, null, true); } else if (manager == null) { return new ValueResolvingContext(event, null, config.orElse(null), resolveCursors); } else { return new ValueResolvingContext(event, manager.openSession(event.asBindingContext()), config.orElse(null), resolveCursors); } } }
@Test public void testExtractingJsonResponseAndFeedingSimpleType() throws Exception { final CoreEvent muleEvent = flowRunner("testExtractingJsonResponseAndFeedingSimpleType").run(); final Map<String, TypedValue<?>> variables = muleEvent.getVariables(); assertThat(variables.get("checkingNotAvenue").getValue(), is(false)); assertThat(variables.get("checkingFromExpression").getValue(), is(true)); assertThat(variables.get("checkingFromHardcodedType1").getValue(), is(true)); assertThat(variables.get("checkingFromHardcodedType1WithVariables").getValue(), is(true)); }
@Test public void munitSpyNoAttributes() throws Exception { CoreEvent internalEvent = flowRunner("munitSpyNoAttributes").run(); assertThat(internalEvent.getMessage().getPayload().getValue(), is(nullValue())); assertThat(internalEvent.getVariables().get("before"), is(nullValue())); assertThat(internalEvent.getVariables().get("after"), is(nullValue())); } }