use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class MessageContextTestCase method payloadAsDataType.
@Test
public void payloadAsDataType() throws Exception {
InternalMessage transformedMessage = mock(InternalMessage.class, RETURNS_DEEP_STUBS);
TransformationService transformationService = mock(TransformationService.class);
when(transformedMessage.getPayload()).thenReturn(new TypedValue<Object>(TEST_PAYLOAD, STRING));
muleContext.setTransformationService(transformationService);
when(transformationService.transform(event.getMessage(), DataType.STRING)).thenReturn(transformedMessage);
Object result = evaluate("message.payloadAs(" + DataType.class.getName() + ".STRING)", event);
assertSame(TEST_PAYLOAD, result);
}
use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class SplitterTestCase method assertSplitParts.
private void assertSplitParts(int count, boolean counted, Map<String, Serializable> inboundProps, Map<String, Serializable> outboundProps, Map<String, Object> invocationProps, List<CoreEvent> splits, Set<Object> actualSequences) {
for (CoreEvent event : splits) {
Message msg = event.getMessage();
assertTrue(msg.getPayload().getValue() instanceof String);
if (counted) {
assertThat(event.getGroupCorrelation().get().getGroupSize().getAsInt(), is(count));
} else {
assertThat(event.getGroupCorrelation().get().getGroupSize().isPresent(), is(false));
}
actualSequences.add(event.getGroupCorrelation().get().getSequence());
String str = (String) msg.getPayload().getValue();
assertTrue(TEST_LIST_MULTIPLE.contains(str));
for (String key : inboundProps.keySet()) {
assertEquals(((InternalMessage) msg).getInboundProperty(key), inboundProps.get(key));
}
for (String key : outboundProps.keySet()) {
assertEquals(((InternalMessage) msg).getOutboundProperty(key), outboundProps.get(key));
}
for (String key : invocationProps.keySet()) {
assertEquals(event.getVariables().get(key).getValue(), invocationProps.get(key));
}
}
}
use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class CustomJavaSerializationProtocolTestCase method serializeWithoutDefaultConstructorFromArtifactClassLoader.
@Test
public final void serializeWithoutDefaultConstructorFromArtifactClassLoader() throws Exception {
final File compiledClasses = new File(temporaryFolder.getRoot(), "compiledClasses");
compiledClasses.mkdirs();
final File sourceFile = new File(getClass().getResource("/org/foo/SerializableClass.java").toURI());
CompilerUtils.SingleClassCompiler compiler = new CompilerUtils.SingleClassCompiler();
compiler.compile(sourceFile);
final URL[] urls = new URL[] { compiler.getTargetFolder().toURL() };
final ClassLoaderLookupPolicy lookupPolicy = mock(ClassLoaderLookupPolicy.class);
when(lookupPolicy.getClassLookupStrategy(any())).thenReturn(PARENT_FIRST);
final MuleArtifactClassLoader artifactClassLoader = new MuleArtifactClassLoader(ARTIFACT_ID, new ArtifactDescriptor(ARTIFACT_NAME), urls, getClass().getClassLoader(), lookupPolicy);
when(classLoaderRepository.getId(artifactClassLoader)).thenReturn(Optional.of(ARTIFACT_ID));
when(classLoaderRepository.find(ARTIFACT_ID)).thenReturn(Optional.of(artifactClassLoader));
final Class<?> echoTestClass = artifactClassLoader.loadClass(SERIALIZABLE_CLASS);
final Object payload = echoTestClass.newInstance();
setObjectName(payload);
CoreEvent event = eventBuilder(muleContext).message(of(payload)).build();
byte[] bytes = serializationProtocol.serialize(event.getMessage());
InternalMessage message = serializationProtocol.deserialize(bytes);
Object deserialized = message.getPayload().getValue();
assertThat(deserialized.getClass().getName(), equalTo(SERIALIZABLE_CLASS));
assertThat(deserialized.getClass().getClassLoader(), equalTo(artifactClassLoader));
assertThat(deserialized, equalTo(payload));
assertThat(getObjectName(deserialized), equalTo(INSTANCE_NAME));
}
use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class LoggerMessageProcessorTestCase method buildMuleEvent.
private CoreEvent buildMuleEvent() {
CoreEvent event = mock(CoreEvent.class);
InternalMessage message = mock(InternalMessage.class);
when(message.toString()).thenReturn("text to log");
when(event.getMessage()).thenReturn(message);
return event;
}
use of org.mule.runtime.core.internal.message.InternalMessage in project mule by mulesoft.
the class SimpleCollectionAggregatorTestCase method testAggregateMultipleEvents.
@Test
public void testAggregateMultipleEvents() throws Exception {
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
assertNotNull(flow);
SimpleCollectionAggregator router = new SimpleCollectionAggregator();
SensingNullMessageProcessor sensingMessageProcessor = getSensingNullMessageProcessor();
router.setListener(sensingMessageProcessor);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
EventContext executionContext = create(flow, TEST_CONNECTOR_LOCATION, "foo");
Message message1 = Message.of("test event A");
Message message2 = Message.of("test event B");
Message message3 = Message.of("test event C");
CoreEvent event1 = InternalEvent.builder(executionContext).message(message1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 3))).build();
CoreEvent event2 = InternalEvent.builder(executionContext).message(message2).build();
CoreEvent event3 = InternalEvent.builder(executionContext).message(message3).build();
assertNull(router.process(event1));
assertNull(router.process(event2));
CoreEvent resultEvent = router.process(event3);
assertNotNull(sensingMessageProcessor.event);
assertThat(resultEvent, equalTo(sensingMessageProcessor.event));
Message nextMessage = sensingMessageProcessor.event.getMessage();
assertNotNull(nextMessage);
assertTrue(nextMessage.getPayload().getValue() instanceof List<?>);
List<InternalMessage> list = (List<InternalMessage>) nextMessage.getPayload().getValue();
assertEquals(3, list.size());
String[] results = new String[3];
list.stream().map(msg -> msg.getPayload().getValue()).collect(toList()).toArray(results);
// Need to sort result because of MULE-5998
Arrays.sort(results);
assertEquals("test event A", results[0]);
assertEquals("test event B", results[1]);
assertEquals("test event C", results[2]);
}
Aggregations