use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class PayloadEnricherDataTypePropagatorTestCase method doPayloadDataTypeTest.
private void doPayloadDataTypeTest(String expression) throws Exception {
final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
final CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(expressionLanguage.getParserConfiguration()));
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
dataTypePropagator.propagate((PrivilegedEvent) testEvent(), builder, new TypedValue<>(TEST_MESSAGE, expectedDataType), compiledExpression);
final CoreEvent event = builder.build();
assertThat(event.getMessage().getPayload().getDataType(), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class ExceptionTestCase method exception.
@Test
public void exception() throws Exception {
CoreEvent event = createEvent();
RuntimeException rte = new RuntimeException();
when(mockError.getCause()).thenReturn(rte);
when(mockError.getErrorType()).thenReturn(mockErrorType);
event = CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).build()).build();
Object exception = evaluate("exception", event);
assertThat(exception, is(instanceOf(MessagingException.class)));
assertThat(((MessagingException) exception).getCause(), is(rte));
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class ExceptionTestCase method assignException.
@Test
public void assignException() throws Exception {
CoreEvent event = createEvent();
event = CoreEvent.builder(event).message(InternalMessage.builder(event.getMessage()).build()).build();
RuntimeException runtimeException = new RuntimeException();
when(mockError.getCause()).thenReturn(runtimeException);
when(mockError.getErrorType()).thenReturn(mockErrorType);
assertImmutableVariable("exception='other'", event);
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class ExceptionTestCase method exceptionCausedBy.
@Test
public void exceptionCausedBy() throws Exception {
CoreEvent event = createEvent();
Message message = event.getMessage();
MessagingException me = new MessagingException(CoreMessages.createStaticMessage(""), InternalEvent.builder(context).message(message).build(), new IllegalAccessException());
when(mockError.getCause()).thenReturn(me);
assertTrue((Boolean) evaluate("exception.causedBy(java.lang.IllegalAccessException)", event));
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class FlowTestCase method assignToFlowName.
@Test
public void assignToFlowName() throws Exception {
CoreEvent event = InternalEvent.builder(context).message(of("")).build();
assertFinalProperty("flow.name='foo'", event);
}
Aggregations