Search in sources :

Example 21 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method getMapFromJsonCar.

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

Example 22 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method plainTextValue.

@Test
public void plainTextValue() {
    String staticValue = "attributeEvaluator";
    AttributeEvaluator attributeEvaluator = getAttributeEvaluator(staticValue);
    assertThat(attributeEvaluator.resolveValue(mockMuleEvent), is(staticValue));
}
Also used : AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 23 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method getJavaPojo.

@Test
public void getJavaPojo() throws MuleException {
    AttributeEvaluator attributeEvaluator = getAttributeEvaluator(DW_CAR, DataType.fromType(Car.class));
    Object car = attributeEvaluator.resolveValue(newEvent());
    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 24 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method getJavaInputStreamFromStringJsonProperty.

@Test
public void getJavaInputStreamFromStringJsonProperty() throws MuleException {
    AttributeEvaluator attributeEvaluator = getAttributeEvaluator("#[payload.host]", INPUT_STREAM);
    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 25 with AttributeEvaluator

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

the class DWAttributeEvaluatorTestCase method getListOfCarsFromJsonCar.

@Test
public void getListOfCarsFromJsonCar() throws MuleException {
    AttributeEvaluator attributeEvaluator = getAttributeEvaluator("#[[payload]]", CAR_LIST_DATA_TYPE);
    List<Car> cars = attributeEvaluator.resolveValue(newEvent(JSON_CAR, APPLICATION_JSON));
    Car car = cars.get(0);
    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)

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