use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class ExpressionValueResolver method resolve.
@Override
public T resolve(ValueResolvingContext context) throws MuleException {
TypedValue typedValue = evaluator.resolveTypedValue(context.getEvent());
Object value = typedValue.getValue();
if (isInstance(ValueResolver.class, value)) {
value = ((ValueResolver) value).resolve(context);
}
return (T) value;
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class StackableTypesTestCase method configurationWithDynamicParameterResolvers.
@Test
public void configurationWithDynamicParameterResolvers() throws Exception {
NestedWrapperTypesConfig config = getPayload("configurationWithDynamicParameterResolvers");
ParameterResolver<TypedValue<KnockeableDoor>> doorResolver = config.getDoorResolver();
TypedValue<KnockeableDoor> doorTypedValue = doorResolver.resolve();
KnockeableDoor door = doorTypedValue.getValue();
assertThat(door.getVictim(), is("Victim's Name"));
ParameterResolver<TypedValue<InputStream>> lazyParameter = config.getLazyParameter();
Optional<String> expression = lazyParameter.getExpression();
TypedValue<InputStream> resolve = lazyParameter.resolve();
InputStream value = resolve.getValue();
String stringValue = IOUtils.toString(value);
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}"));
ParameterResolver<ParameterResolver<ParameterResolver<ParameterResolver<TypedValue<InputStream>>>>> nestedParameter = config.getNestedParameter();
TypedValue<InputStream> nestedTypedValue = nestedParameter.resolve().resolve().resolve().resolve();
InputStream nestedValue = nestedTypedValue.getValue();
String nestedString = IOUtils.toString(nestedValue);
assertThat(nestedString, is("{\n \"key\": \"pretty nested\"\n}"));
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 DefaultStreamingHelperTestCase method resolveStreamableTypedValueProvider.
@Test
public void resolveStreamableTypedValueProvider() {
TypedValue typedValue = new TypedValue(new ByteArrayInputStream("Apple".getBytes()), DataType.INPUT_STREAM);
TypedValue repeatableTypedValue = (TypedValue) streamingHelper.resolveCursorProvider(typedValue);
assertThat(repeatableTypedValue.getValue(), instanceOf(CursorProvider.class));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class DefaultStreamingHelperTestCase method resolveNonStreamableTypedValueProvider.
@Test
public void resolveNonStreamableTypedValueProvider() {
TypedValue typedValue = new TypedValue("Apple", DataType.STRING);
TypedValue repeatableTypedValue = (TypedValue) streamingHelper.resolveCursorProvider(typedValue);
assertThat(repeatableTypedValue.getValue(), not(instanceOf(CursorProvider.class)));
}
use of org.mule.runtime.api.metadata.TypedValue in project mule by mulesoft.
the class TypedValueParameterOperationExecutionTestCase method wrappedAndUnwrappedTypes.
@Test
public void wrappedAndUnwrappedTypes() throws Exception {
List<Object> wrappedAndUnwrappedTypes = (List<Object>) flowRunner("wrappedAndUnwrappedTypes").run().getMessage().getPayload().getValue();
assertThat(wrappedAndUnwrappedTypes.get(0), is("stringNotWrapped"));
assertThat(((TypedValue) wrappedAndUnwrappedTypes.get(1)).getValue(), is("wrappedString"));
assertThat(((SimplePojo) ((TypedValue) wrappedAndUnwrappedTypes.get(2)).getValue()).getUser(), is("user"));
assertThat(((SimplePojo) wrappedAndUnwrappedTypes.get(3)).getUser(), is("user2"));
Map<String, Object> mapOfComplexValues = (Map<String, Object>) wrappedAndUnwrappedTypes.get(4);
Map<String, TypedValue<?>> mapOfComplexTypedValues = (Map<String, TypedValue<?>>) wrappedAndUnwrappedTypes.get(5);
assertThat(mapOfComplexValues.entrySet().size(), is(2));
assertThat(((Map) mapOfComplexValues.get("first")).get("pass"), is("pass"));
assertThat(mapOfComplexTypedValues.entrySet().size(), is(1));
assertThat(((Map) ((TypedValue) mapOfComplexTypedValues.get("third")).getValue()).get("pass"), is("pass3"));
SimplePojo group = (SimplePojo) wrappedAndUnwrappedTypes.get(6);
assertThat(group.getUser(), is("groupUser"));
assertThat(group.getPass(), is("groupPass"));
}
Aggregations