Search in sources :

Example 6 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method getListOfMapsFromJsonCar.

@Test
public void getListOfMapsFromJsonCar() throws MuleException {
    AttributeEvaluator attributeEvaluator = getAttributeEvaluator("#[[payload as Object]]", DataType.fromType(List.class));
    List<Map<String, String>> cars = attributeEvaluator.resolveValue(newEvent(JSON_CAR, APPLICATION_JSON));
    Map<String, String> car = cars.get(0);
    assertThat(car, hasEntry(is("price"), is(1000)));
    assertThat(car, hasEntry(is("color"), is("RED")));
}
Also used : List(java.util.List) AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) Map(java.util.Map) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 7 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method getJavaCarFromJsonCar.

@Test
public void getJavaCarFromJsonCar() throws MuleException {
    AttributeEvaluator attributeEvaluator = getAttributeEvaluator("#[payload]", CAR_DATA_TYPE);
    Object car = attributeEvaluator.resolveValue(newEvent(JSON_CAR, APPLICATION_JSON));
    assertThat(car, is(allOf(hasProperty("color", is("RED")), hasProperty("price", is(1000)))));
}
Also used : AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 8 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method getBooleanValue.

@Test
public void getBooleanValue() throws MuleException {
    AttributeEvaluator attributeEvaluator = getAttributeEvaluator("#[payload.ok]", BOOLEAN);
    Boolean bool = attributeEvaluator.resolveValue(newEvent("{\"ok\" : true}", APPLICATION_JSON));
    assertThat(bool, is(true));
}
Also used : AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 9 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method getJavaObjectFromStringJsonProperty.

@Test
public void getJavaObjectFromStringJsonProperty() throws MuleException {
    AttributeEvaluator attributeEvaluator = getAttributeEvaluator("#[payload.host]", OBJECT);
    CoreEvent event = newEvent(HOST_PORT_JSON, APPLICATION_JSON);
    Object resolveValue = attributeEvaluator.resolveValue(event);
    assertThat(IOUtils.toString((InputStream) ((CursorProvider) resolveValue).openCursor()), is("\"0.0.0.0\""));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) InputStream(java.io.InputStream) AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 10 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method resolveIntegerValueFromJsonObject.

@Test
public void resolveIntegerValueFromJsonObject() throws MuleException {
    AttributeEvaluator attributeEvaluator = getAttributeEvaluator("#[payload.port]", NUMBER);
    Integer port = attributeEvaluator.resolveValue(newEvent(HOST_PORT_JSON, APPLICATION_JSON));
    assertThat(port, is(8081));
}
Also used : AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

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