Search in sources :

Example 1 with FunctionDataType

use of org.mule.runtime.api.metadata.FunctionDataType in project mule by mulesoft.

the class DataTypeBuilderTestCase method buildFunction.

@Test
public void buildFunction() {
    FunctionDataType dataType = (FunctionDataType) DataType.fromFunction(new SomeFunction());
    // Return type
    assertThat(dataType.getReturnType().isPresent(), is(true));
    assertThat(dataType.getReturnType().get(), equalTo(STRING));
    // Parameters
    assertThat(dataType.getParameters(), hasSize(2));
    FunctionParameter first = dataType.getParameters().get(0);
    assertThat(first.getName(), is("fst"));
    assertThat(first.getType(), equalTo(NUMBER));
    assertThat(first.getDefaultValueResolver(), nullValue());
    FunctionParameter second = dataType.getParameters().get(1);
    assertThat(second.getName(), is("snd"));
    assertThat(second.getType(), equalTo(OBJECT));
    // Default
    assertThat(second.getDefaultValueResolver().getDefaultValue(builder().build()), is("wow"));
}
Also used : DefaultFunctionDataType(org.mule.runtime.core.internal.metadata.DefaultFunctionDataType) FunctionDataType(org.mule.runtime.api.metadata.FunctionDataType) FunctionParameter(org.mule.runtime.api.metadata.FunctionParameter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 FunctionDataType (org.mule.runtime.api.metadata.FunctionDataType)1 FunctionParameter (org.mule.runtime.api.metadata.FunctionParameter)1 DefaultFunctionDataType (org.mule.runtime.core.internal.metadata.DefaultFunctionDataType)1