use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class StackableTypesTestCase method configurationWithStaticParameterResolvers.
@Test
public void configurationWithStaticParameterResolvers() throws Exception {
NestedWrapperTypesConfig config = getPayload("configurationWithStaticParameterResolvers");
ParameterResolver<TypedValue<KnockeableDoor>> doorResolver = config.getDoorResolver();
TypedValue<KnockeableDoor> doorTypedValue = doorResolver.resolve();
KnockeableDoor door = doorTypedValue.getValue();
assertThat(door.getVictim(), is("Victim's Name"));
ParameterResolver<TypedValue<String>> lazyParameter = config.getLazyString();
Optional<String> expression = lazyParameter.getExpression();
TypedValue<String> resolve = lazyParameter.resolve();
assertThat(expression, is(empty()));
assertThat(resolve.getValue(), is("a nice looking string"));
ParameterResolver<Literal<String>> resolverOfLiteral = config.getResolverOfLiteral();
Literal<String> stringLiteral = resolverOfLiteral.resolve();
Optional<String> literalValue = stringLiteral.getLiteralValue();
assertThat(literalValue, is(not(empty())));
assertThat(literalValue.get(), is("this doesn't make sense"));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class StackableTypesTestCase method parameterResolverOfTypedValueOnOperation.
@Test
public void parameterResolverOfTypedValueOnOperation() throws Exception {
ParameterResolver<TypedValue<InputStream>> lazyValue = (ParameterResolver<TypedValue<InputStream>>) flowRunner("parameterResolverOfTypedValueOnOperation").run().getMessage().getPayload().getValue();
TypedValue<InputStream> resolve = lazyValue.resolve();
InputStream jsonValue = resolve.getValue();
Optional<String> expression = lazyValue.getExpression();
String stringValue = IOUtils.toString(jsonValue);
assertThat(expression, is(not(empty())));
assertThat(expression.get(), is("#[output application/json --- {key : 'a nice looking json'}]"));
assertThat(stringValue, is("{\n \"key\": \"a nice looking json\"\n}"));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class FunctionExecutionTestCase method executeWithTypedValueParameters.
@Test
public void executeWithTypedValueParameters() throws Exception {
final String xmlString = IOUtils.toString(getDocumentStream());
final InputStream jsonStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("models/subtypes.json");
final KnockeableDoor knockeableDoor = new KnockeableDoor("Ricky", "Universe 137");
TypedValue<List<Object>> payload = flowRunner("typedValueFunction").withPayload(new TypedValue<>(xmlString, XML_STRING)).withVariable("door", TypedValue.of(knockeableDoor)).withVariable("xmlString", new TypedValue<>(xmlString, XML_STRING)).withVariable("jsonStream", new TypedValue<>(jsonStream, DataType.builder().type(InputStream.class).mediaType(APPLICATION_JSON).build())).run().getMessage().getPayload();
List<Object> values = payload.getValue();
assertThat(values, hasSize(4));
assertThat(getValue(values.get(0)), is(xmlString));
assertThat(getValue(values.get(1)), is(xmlString));
assertThat(getValue(values.get(2)), is(jsonStream));
assertThat(getValue(values.get(3)), is(knockeableDoor));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class PropertyEnricherDataTypePropagatorTestCase method propagatesDataTypeForInlinedSessionProperty.
@Test
public void propagatesDataTypeForInlinedSessionProperty() 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("foo = 'unused'", new ParserContext(expressionLanguage.getParserConfiguration()));
PrivilegedEvent event = (PrivilegedEvent) testEvent();
event.getSession().setProperty("foo", "bar");
final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
dataTypePropagator.propagate((PrivilegedEvent) testEvent(), builder, new TypedValue(TEST_MESSAGE, expectedDataType), compiledExpression);
assertThat(builder.build().getSession().getPropertyDataType("foo"), like(String.class, JSON, CUSTOM_ENCODING));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DefaultMuleMessageBuilderTestCase method wholeAttributes.
@Test
public void wholeAttributes() {
Message message = Message.builder().nullValue().attributes(new TypedValue<>(EMPTY_JSON, JSON_STRING)).build();
assertThat(message.getAttributes().getValue(), equalTo(EMPTY_JSON));
assertThat(message.getAttributes().getDataType().getType(), equalTo(String.class));
assertThat(message.getAttributes().getDataType().getMediaType(), is(APPLICATION_JSON));
}
Aggregations