Search in sources :

Example 1 with ParameterResolver

use of org.mule.runtime.extension.api.runtime.parameter.ParameterResolver 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}"));
}
Also used : ParameterResolver(org.mule.runtime.extension.api.runtime.parameter.ParameterResolver) InputStream(java.io.InputStream) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 2 with ParameterResolver

use of org.mule.runtime.extension.api.runtime.parameter.ParameterResolver in project mule by mulesoft.

the class ParameterResolverOperationExecutionTestCase method assertExpressionResolverWeapon.

private void assertExpressionResolverWeapon(String flowName, String expression, Matcher weaponMatcher) throws Exception {
    ParameterResolver weaponInfo = (ParameterResolver) flowRunner(flowName).run().getMessage().getPayload().getValue();
    assertThat(weaponInfo.getExpression(), is(ofNullable(expression)));
    assertThat(weaponInfo.resolve(), weaponMatcher);
}
Also used : ParameterResolver(org.mule.runtime.extension.api.runtime.parameter.ParameterResolver)

Example 3 with ParameterResolver

use of org.mule.runtime.extension.api.runtime.parameter.ParameterResolver 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']"));
}
Also used : NestedWrapperTypesConfig(org.mule.test.parameter.resolver.extension.extension.NestedWrapperTypesConfig) ParameterResolver(org.mule.runtime.extension.api.runtime.parameter.ParameterResolver) InputStream(java.io.InputStream) Literal(org.mule.runtime.extension.api.runtime.parameter.Literal) KnockeableDoor(org.mule.test.heisenberg.extension.model.KnockeableDoor) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Aggregations

ParameterResolver (org.mule.runtime.extension.api.runtime.parameter.ParameterResolver)3 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 TypedValue (org.mule.runtime.api.metadata.TypedValue)2 Literal (org.mule.runtime.extension.api.runtime.parameter.Literal)1 KnockeableDoor (org.mule.test.heisenberg.extension.model.KnockeableDoor)1 NestedWrapperTypesConfig (org.mule.test.parameter.resolver.extension.extension.NestedWrapperTypesConfig)1