本文整理了Java中org.mule.runtime.api.message.Message.of()
方法的一些代码示例,展示了Message.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.of()
方法的具体详情如下:
包路径:org.mule.runtime.api.message.Message
类名称:Message
方法名:of
暂无
代码示例来源:origin: mulesoft/mule
/**
* Create a new {@link CoreEvent} for each invocation. Useful if multiple distinct event instances are needed in a single test
* method.
*
* @return new test event.
* @throws MuleException
*/
protected <E extends CoreEvent> E newEvent() throws MuleException {
return (E) getEventBuilder().message(of(TEST_PAYLOAD)).build();
}
代码示例来源:origin: mulesoft/mule
@Test
public void maintainsCurrentDataTypeClassWhenTransformerOutputTypeIsObject() throws Exception {
Message message = of(TEST_PAYLOAD);
Transformer transformer = mock(Transformer.class);
when(transformer.isSourceDataTypeSupported(any())).thenReturn(true);
DataType outputDataType = DataType.builder().type(Object.class).mediaType(ANY).build();
when(transformer.getReturnDataType()).thenReturn(outputDataType);
when(transformer.transform(message)).thenReturn(TEST_PAYLOAD);
CoreEvent muleEvent = mock(CoreEvent.class);
Message result = transformationService.applyTransformers(message, muleEvent, singletonList(transformer));
assertDataType(result, String.class, ANY, DEFAULT_ENCODING);
}
代码示例来源:origin: mulesoft/mule
@Test
public void assignPayload() throws Exception {
message = of("");
event = getEventBuilder().message(message).build();
evaluate("payload = 'foo'", event, eventBuilder);
ArgumentCaptor<InternalMessage> argument = ArgumentCaptor.forClass(InternalMessage.class);
verify(eventBuilder).message(argument.capture());
assertThat(argument.getValue().getPayload().getValue(), equalTo("foo"));
}
代码示例来源:origin: mulesoft/mule
@Test
@Description("Verifies that streams are logged in DW but not in MVEL.")
public void parseLogStream() throws MuleException {
ByteArrayInputStream stream = new ByteArrayInputStream("hello".getBytes());
CoreEvent event = getEventBuilder().message(of(stream)).build();
assertThat(expressionManager.parseLogTemplate("this is #[dw:payload]", event, TEST_CONNECTOR_LOCATION,
NULL_BINDING_CONTEXT),
is("this is hello"));
assertThat(expressionManager.parseLogTemplate("this is #[payload]", event, TEST_CONNECTOR_LOCATION,
NULL_BINDING_CONTEXT),
both(startsWith("this is ")).and(containsString(stream.getClass().getSimpleName())));
}
代码示例来源:origin: mulesoft/mule
@Test
@Description("Verifies that streams are logged in DW but not in MVEL.")
public void parseLogStream() throws MuleException {
ByteArrayInputStream stream = new ByteArrayInputStream("hello".getBytes());
CoreEvent event = getEventBuilder().message(Message.of(stream)).build();
assertThat(expressionManager.parseLogTemplate("this is #[payload]", event, TEST_CONNECTOR_LOCATION,
NULL_BINDING_CONTEXT),
is("this is hello"));
assertThat(expressionManager.parseLogTemplate("this is #[mel:payload]", event, TEST_CONNECTOR_LOCATION,
NULL_BINDING_CONTEXT),
both(startsWith("this is ")).and(containsString(stream.getClass().getSimpleName())));
}
代码示例来源:origin: mulesoft/mule
@Test
public void testTwoChainedTransformers() throws Exception {
AbstractTransformer validTransformer = (AbstractTransformer) this.getIncreaseByOneTransformer();
assertNotNull(validTransformer);
Message message = of(new Integer(0));
Transformer messageTransformer = new TransformerChain(validTransformer, validTransformer);
message = transformationService.applyTransformers(message, eventBuilder(muleContext).message(of(0)).build(),
singletonList(messageTransformer));
Object transformedMessage = message.getPayload().getValue();
assertNotNull(transformedMessage);
assertEquals(new Integer(2), transformedMessage);
}
代码示例来源:origin: mulesoft/mule
@Test
@Description("When a route timeout occurs a CompositeRoutingException is thrown with details of timeout error in RoutingResult.")
public void timeout() throws Throwable {
strategy = createStrategy(processingStrategy, 1, true, 50);
expectedException.expect(instanceOf(CompositeRoutingException.class));
invokeStrategyBlocking(strategy, testEvent(), asList(createRoutingPairWithSleep(of(1), 250)), throwable -> {
CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 1);
RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 0, 1);
assertThat(routingResult.getFailures().get("0").getCause(), instanceOf(TimeoutException.class));
});
}
代码示例来源:origin: mulesoft/mule
@Test
public void testMuleMessageAvailableAsVariable() throws Exception {
CoreEvent event = CoreEvent.builder(context).message(of("")).build();
evaluate("p=m.uniqueId", event);
}
代码示例来源:origin: mulesoft/mule
@Test
public void consumeEventWithNullPayload() throws Exception {
CoreEvent event = getEventBuilder().message(Message.of(null)).build();
assertThat(consumeRepeatablePayload(event), is(sameInstance(event)));
}
代码示例来源:origin: mulesoft/mule
@Test
public void assignToFlowName() throws Exception {
CoreEvent event = InternalEvent.builder(context).message(of("")).build();
assertFinalProperty("flow.name='foo'", event);
}
代码示例来源:origin: mulesoft/mule
@Test
public void expressionTemplateWithoutTransformation() throws Exception {
ValueResolvingContext context = buildContext(eventBuilder(muleContext).message(of("World!")).build());
assertResolved(getResolver("Hello #[payload]", STRING).resolve(context), HELLO_WORLD, times(1));
}
代码示例来源:origin: mulesoft/mule
@Test
public void templateWithTransformation() throws Exception {
ValueResolver<Object> resolver = getResolver("#['tru$('e')']", STRING);
ValueResolvingContext ctx = ValueResolvingContext.builder(eventBuilder(muleContext).message(of(HELLO_WORLD)).build())
.withExpressionManager(expressionManager)
.build();
assertResolved(resolver.resolve(ctx), "true", times(1));
}
代码示例来源:origin: mulesoft/mule
@Before
public void setup() throws Exception {
event = CoreEvent.builder(testEvent()).message(of("")).build();
personType = getMetadata(PERSON_METADATA_KEY.getId());
}
代码示例来源:origin: mulesoft/mule
@Before
public void before() throws Exception {
flow = getTestFlow(muleContext);
flow.initialise();
context = create(flow, TEST_CONNECTOR_LOCATION);
muleEvent = InternalEvent.builder(context).message(of("")).build();
}
代码示例来源:origin: mulesoft/mule
@Test
public void testAssignValueToVariableAlias() throws Exception {
CoreEvent event = CoreEvent.builder(context).message(of("")).build();
CoreEvent.Builder eventBuilder = CoreEvent.builder(event);
evaluate("p='bar'", event, eventBuilder);
assertThat(eventBuilder.build().getMessage().getPayload().getValue(), is("bar"));
}
代码示例来源:origin: mulesoft/mule
@Test
public void assignValueToNewSessionVariable() throws Exception {
Message message = of("");
CoreEvent event = InternalEvent.builder(context).message(message).build();
evaluate("sessionVars['foo']='bar'", event);
assertEquals("bar", ((PrivilegedEvent) event).getSession().getProperty("foo"));
}
代码示例来源:origin: mulesoft/mule
@Test
public void message() throws Exception {
CoreEvent event = CoreEvent.builder(context).message(Message.of("foo")).build();
assertTrue(evaluate("message", event) instanceof MessageContext);
assertEquals("foo", evaluate("message.payload", event));
}
代码示例来源:origin: mulesoft/mule
@Test
public void assignValueToSessionVariable() throws Exception {
Message message = of("");
PrivilegedEvent event = (PrivilegedEvent) InternalEvent.builder(context).message(message).build();
event.getSession().setProperty("foo", "bar_old");
evaluate("sessionVars['foo']='bar'", event);
assertEquals("bar", event.getSession().getProperty("foo"));
}
代码示例来源:origin: mulesoft/mule
@Test
public void collectionAccessPayloadChangedMULE7506() throws Exception {
PrivilegedEvent event = this.<PrivilegedEvent.Builder>getEventBuilder().message(Message.of(new String[] {"1", "2"})).build();
assertEquals("1", mvel.evaluateUntyped("payload[0]", event, PrivilegedEvent.builder(event),
(flowConstruct).getLocation(), null));
event = PrivilegedEvent.builder(event).message(InternalMessage.builder(event.getMessage()).value(singletonList("1")).build())
.build();
assertEquals("1", mvel.evaluateUntyped("payload[0]", event, PrivilegedEvent.builder(event),
(flowConstruct).getLocation(), null));
}
代码示例来源:origin: mulesoft/mule
@Test
public void skipBothConvertersButPayloadMatchesExpectedOutputType() throws MuleException {
// Converter(B -> C) Converter(C->D), payload D: skips converter(B-C), skips converter(C->D), but D is the expected output
// type -> OK
Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).build();
Transformer converter2 = new MockConverterBuilder().from(dataTypeC).to(dataTypeD).build();
Message message = of(new D());
message = transformationService.applyTransformers(message, null, converter1, converter2);
assertTrue(message.getPayload().getValue() instanceof D);
verifyTransformerNotExecuted(converter1);
verifyTransformerNotExecuted(converter2);
}
内容来源于网络,如有侵权,请联系作者删除!