Search in sources :

Example 1 with Literal

use of org.mule.runtime.extension.api.runtime.parameter.Literal 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"));
}
Also used : NestedWrapperTypesConfig(org.mule.test.parameter.resolver.extension.extension.NestedWrapperTypesConfig) 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)

Example 2 with Literal

use of org.mule.runtime.extension.api.runtime.parameter.Literal 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

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