Search in sources :

Example 26 with TypedValue

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"));
}
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 27 with TypedValue

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}"));
}
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 28 with TypedValue

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));
}
Also used : InputStream(java.io.InputStream) KnockeableDoor(org.mule.test.heisenberg.extension.model.KnockeableDoor) NodeList(org.w3c.dom.NodeList) List(java.util.List) Matchers.containsString(org.hamcrest.Matchers.containsString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 29 with TypedValue

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));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DataType(org.mule.runtime.api.metadata.DataType) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 30 with TypedValue

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));
}
Also used : Message(org.mule.runtime.api.message.Message) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Aggregations

TypedValue (org.mule.runtime.api.metadata.TypedValue)97 Test (org.junit.Test)74 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)47 DataType (org.mule.runtime.api.metadata.DataType)17 Message (org.mule.runtime.api.message.Message)16 Description (io.qameta.allure.Description)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 List (java.util.List)11 SmallTest (org.mule.tck.size.SmallTest)10 BindingContext (org.mule.runtime.api.el.BindingContext)9 Map (java.util.Map)8 Optional (java.util.Optional)8 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)6 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)5 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 MuleException (org.mule.runtime.api.exception.MuleException)4 Error (org.mule.runtime.api.message.Error)4 ErrorType (org.mule.runtime.api.message.ErrorType)4