Search in sources :

Example 31 with AttributeEvaluator

use of org.mule.runtime.core.privileged.util.AttributeEvaluator in project mule by mulesoft.

the class MELAttributeEvaluatorTestCase method resolveIntegerWithNumericValue.

@Test
public void resolveIntegerWithNumericValue() {
    AttributeEvaluator attributeEvaluator = new AttributeEvaluator("#[mel:expression]", NUMBER);
    attributeEvaluator.initialize(mockExpressionManager);
    final long expectedValue = 1234l;
    doReturn(new TypedValue<>(expectedValue, fromObject(expectedValue))).when(mockExpressionManager).evaluate(anyString(), any(DataType.class), any(BindingContext.class), any(CoreEvent.class));
    assertThat(attributeEvaluator.resolveValue(event), is(expectedValue));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) BindingContext(org.mule.runtime.api.el.BindingContext) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 32 with AttributeEvaluator

use of org.mule.runtime.core.privileged.util.AttributeEvaluator in project mule by mulesoft.

the class MELAttributeEvaluatorTestCase method resolveIntegerWithNoNumericValue.

@Test(expected = ExpressionRuntimeException.class)
public void resolveIntegerWithNoNumericValue() {
    AttributeEvaluator attributeEvaluator = new AttributeEvaluator("#[mel:expression]", NUMBER);
    attributeEvaluator.initialize(mockExpressionManager);
    doThrow(ExpressionRuntimeException.class).when(mockExpressionManager).evaluate(anyString(), any(DataType.class), any(BindingContext.class), any(CoreEvent.class));
    attributeEvaluator.resolveValue(event);
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) BindingContext(org.mule.runtime.api.el.BindingContext) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 33 with AttributeEvaluator

use of org.mule.runtime.core.privileged.util.AttributeEvaluator in project mule by mulesoft.

the class MELAttributeEvaluatorTestCase method nullAttributeValue.

@Test
public void nullAttributeValue() {
    final AttributeEvaluator nullAttributeEvaluator = new AttributeEvaluator(null, OBJECT);
    nullAttributeEvaluator.initialize(mockExpressionManager);
    doReturn(new TypedValue<>(null, OBJECT)).when(mockExpressionManager).evaluate(anyString(), any(DataType.class), any(BindingContext.class), any(CoreEvent.class));
    assertThat(nullAttributeEvaluator.resolveValue(event), nullValue());
    verify(mockExpressionManager, never()).parse(anyString(), any(CoreEvent.class), any());
    verify(mockExpressionManager, never()).evaluate(anyString(), any(CoreEvent.class));
    verify(mockExpressionManager, never()).evaluate(anyString(), any(DataType.class), any(), any(CoreEvent.class));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) BindingContext(org.mule.runtime.api.el.BindingContext) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 34 with AttributeEvaluator

use of org.mule.runtime.core.privileged.util.AttributeEvaluator in project mule by mulesoft.

the class MELAttributeEvaluatorTestCase method resolveBooleanWithBooleanStringValue.

@Test
public void resolveBooleanWithBooleanStringValue() {
    AttributeEvaluator attributeEvaluator = new AttributeEvaluator("#[mel:expression]", BOOLEAN);
    attributeEvaluator.initialize(mockExpressionManager);
    final String expectedValue = "true";
    doReturn(new TypedValue<>(Boolean.valueOf(expectedValue), BOOLEAN)).when(mockExpressionManager).evaluate(anyString(), any(DataType.class), any(BindingContext.class), any(CoreEvent.class));
    assertThat(attributeEvaluator.resolveValue(event), is(Boolean.valueOf(expectedValue)));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) Matchers.anyString(org.mockito.Matchers.anyString) AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) BindingContext(org.mule.runtime.api.el.BindingContext) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 35 with AttributeEvaluator

use of org.mule.runtime.core.privileged.util.AttributeEvaluator in project mule by mulesoft.

the class AbstractAddVariablePropertyProcessor method initialise.

@Override
public void initialise() throws InitialisationException {
    identifierEvaluator.initialize(muleContext.getExpressionManager());
    valueEvaluator = new AttributeEvaluator(value, getReturnDataType());
    valueEvaluator.initialize(muleContext.getExpressionManager());
}
Also used : AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator)

Aggregations

AttributeEvaluator (org.mule.runtime.core.privileged.util.AttributeEvaluator)35 Test (org.junit.Test)30 SmallTest (org.mule.tck.size.SmallTest)30 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)18 DataType (org.mule.runtime.api.metadata.DataType)13 BindingContext (org.mule.runtime.api.el.BindingContext)6 Matchers.anyString (org.mockito.Matchers.anyString)4 TypedValue (org.mule.runtime.api.metadata.TypedValue)3 InputStream (java.io.InputStream)2 Map (java.util.Map)2 List (java.util.List)1 TestConnectorQueueHandler (org.mule.functional.api.component.TestConnectorQueueHandler)1 WildcardAttributeEvaluator (org.mule.runtime.core.api.util.WildcardAttributeEvaluator)1