use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class DefaultMessageContextTestCase method overrideCorrelationIdInContext.
@Test
public void overrideCorrelationIdInContext() {
final Message message = of(TEST_PAYLOAD);
final CoreEvent event = InternalEvent.builder(executionContextWithCorrelation).message(message).groupCorrelation(empty()).build();
assertThat(event.getCorrelationId(), is(CUSTOM_CORRELATION_ID));
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class MessagingExceptionTestCase method payloadInfoNonVerbose.
@Test
public void payloadInfoNonVerbose() throws Exception {
MuleException.verboseExceptions = false;
CoreEvent testEvent = mock(CoreEvent.class);
Message muleMessage = spy(of(""));
when(testEvent.getMessage()).thenReturn(muleMessage);
when(testEvent.getError()).thenReturn(empty());
MessagingException e = new MessagingException(createStaticMessage(message), testEvent);
assertThat(e.getInfo().get(PAYLOAD_INFO_KEY), nullValue());
verify(muleMessage, never()).getPayload();
verify(transformationService, never()).transform(muleMessage, DataType.STRING);
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class TransformationServiceTestCase method skipsConverterFailsOnTransformer.
@Test
public void skipsConverterFailsOnTransformer() throws MuleException {
// Converter(B -> D) Transformer(C->D), payload A: FAIL
Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeD).build();
Transformer transformer2 = new MockTransformerBuilder().from(dataTypeC).to(dataTypeD).build();
Message message = of(new A());
try {
transformationService.applyTransformers(message, null, converter1, transformer2);
fail("Transformation is supposed to fail");
} catch (IllegalArgumentException expected) {
}
verifyTransformerNotExecuted(converter1);
verifyTransformerNotExecuted(transformer2);
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class TransformationServiceTestCase method appliesFirstTransformerFailsOnSecondTransformer.
@Test
public void appliesFirstTransformerFailsOnSecondTransformer() throws MuleException {
// Transformer(B ->D) Transformer(C->D), payload B: applies first transformer, cannot apply second transformer -> FAIL
Transformer transformer1 = new MockTransformerBuilder().from(dataTypeB).to(dataTypeD).returning(new D()).build();
Transformer transformer2 = new MockTransformerBuilder().from(dataTypeC).to(dataTypeD).build();
Message message = of(new B());
try {
transformationService.applyTransformers(message, null, transformer1, transformer2);
fail("Transformation is supposed to fail");
} catch (IllegalArgumentException expected) {
}
verifyTransformerExecuted(transformer1);
verifyTransformerNotExecuted(transformer2);
}
use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorThrowsExceptionAroundAfterProceedInCallbackChained.
@Test
public void interceptorThrowsExceptionAroundAfterProceedInCallbackChained() throws Exception {
RuntimeException expectedException = new RuntimeException("Some Error");
ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
return action.proceed().thenApplyAsync(e -> {
throw expectedException;
});
}
});
startFlowWithInterceptors(interceptor);
expected.expect(MessagingException.class);
expected.expect(withEventThat(hasErrorType(UNKNOWN.getNamespace(), UNKNOWN.getName())));
expected.expectCause(sameInstance(expectedException));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor);
inOrder.verify(interceptor).before(any(), any(), any());
inOrder.verify(interceptor).around(any(), any(), any(), any());
inOrder.verify(processor).process(any());
inOrder.verify(interceptor).after(any(), any(), eq(of(expectedException)));
verifyParametersResolvedAndDisposed(times(1));
}
}
}
Aggregations