Search in sources :

Example 16 with TypedValue

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

the class ExtendedExpressionLanguageAdapterTestCase method flowNameVariable.

@Test
@Description("Verifies that the Flow name variable works for MVEL and DW.")
public void flowNameVariable() throws MuleException {
    String expression = "flow.name";
    String myFlowName = "myFlowName";
    TypedValue mvelResult = expressionLanguageAdapter.evaluate(melify(expression), testEvent(), fromSingleComponent(myFlowName), emptyBindingContext);
    assertThat(mvelResult.getValue(), is(myFlowName));
    TypedValue dwResult = expressionLanguageAdapter.evaluate(expression, testEvent(), fromSingleComponent(myFlowName), emptyBindingContext);
    assertThat(dwResult.getValue(), is(myFlowName));
}
Also used : TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 17 with TypedValue

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

the class DefaultExpressionManagerMelDefaultTestCase method transformation.

@Test
@Description("Verifies that a simple transformation works. MVEL ignores expectedDataType")
public void transformation() throws MuleException {
    String expression = "payload";
    TypedValue result = expressionManager.evaluate(expression, BYTE_ARRAY, builder().build(), testEvent());
    assertThat(result.getValue(), is(TEST_PAYLOAD));
    assertThat(result.getDataType(), is(STRING));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 18 with TypedValue

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

the class DefaultExpressionManagerMelDefaultTestCase method transformationNotNeeded.

@Test
@Description("Verifies that a simple transformation works even when it's not required.")
public void transformationNotNeeded() throws MuleException {
    String expression = "payload";
    TypedValue result = expressionManager.evaluate(expression, STRING, builder().build(), testEvent());
    assertThat(result.getValue(), is(TEST_PAYLOAD));
    assertThat(result.getDataType(), is(STRING));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 19 with TypedValue

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

the class GlobalBindingContextProviderTestCase method variable.

@Test
public void variable() {
    TypedValue result = muleContext.getExpressionManager().evaluate("number");
    assertThat(result.getValue(), is(1));
    assertThat(result.getDataType(), is(assignableTo(NUMBER)));
}
Also used : TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 20 with TypedValue

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

the class MessageContextTestCase method payloadAsType.

@Test
public void payloadAsType() throws Exception {
    InternalMessage transformedMessage = mock(InternalMessage.class, RETURNS_DEEP_STUBS);
    final TypedValue<Object> expectedPayload = new TypedValue<>(new Object(), OBJECT);
    when(transformedMessage.getPayload()).thenReturn(expectedPayload);
    TransformationService transformationService = mock(TransformationService.class);
    muleContext.setTransformationService(transformationService);
    when(transformationService.transform(any(InternalMessage.class), any(DataType.class))).thenReturn(transformedMessage);
    assertSame(transformedMessage.getPayload().getValue(), evaluate("message.payloadAs(org.mule.tck.testmodels.fruit.Banana)", event));
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) DataType(org.mule.runtime.api.metadata.DataType) TransformationService(org.mule.runtime.api.transformation.TransformationService) 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