Search in sources :

Example 31 with TypedValue

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

the class IdempotentRedeliveryPolicyTestCase method testMessageRedeliveryUsingSerializationStore.

@Test
public void testMessageRedeliveryUsingSerializationStore() throws Exception {
    when(expressionManager.evaluate(eq(format(SECURE_HASH_EXPR_FORMAT, "SHA-256")), eq(STRING), eq(NULL_BINDING_CONTEXT), any())).thenAnswer(inv -> {
        return new TypedValue<>("" + inv.getArgumentAt(3, CoreEvent.class).getMessage().getPayload().hashCode(), STRING);
    });
    when(message.getPayload()).thenReturn(new TypedValue<>(STRING_MESSAGE, STRING));
    reset(mockObjectStoreManager);
    final ObjectStore serializationObjectStore = new SerializationObjectStore();
    when(mockObjectStoreManager.createObjectStore(any(), any())).thenReturn(serializationObjectStore);
    irp.initialise();
    processUntilFailure();
    assertThat(count.get(), equalTo(MAX_REDELIVERY_COUNT + 1));
}
Also used : TemplateObjectStore(org.mule.runtime.api.store.TemplateObjectStore) ObjectStore(org.mule.runtime.api.store.ObjectStore) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 32 with TypedValue

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

the class ExpressionEvaluatorTestCase method handleNullEvent.

@Test
public void handleNullEvent() throws MuleException {
    TypedValue evaluate = muleContext.getExpressionManager().evaluate("%dw 2.0\noutput application/json\n---\n{a: 1}");
    ByteArrayBasedCursorStreamProvider value = (ByteArrayBasedCursorStreamProvider) evaluate.getValue();
    String expected = "{\n" + "  \"a\": 1\n" + "}";
    assertThat(IOUtils.toString(value), is(expected));
}
Also used : ByteArrayBasedCursorStreamProvider(org.mule.weave.v2.el.ByteArrayBasedCursorStreamProvider) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 33 with TypedValue

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

the class MELAttributeEvaluatorTestCase method parenthesesInExpression.

@Test
public void parenthesesInExpression() {
    when(mockExpressionManager.evaluate(anyString(), any(CoreEvent.class))).thenReturn(new TypedValue(null, OBJECT));
    AttributeEvaluator attributeEvaluator = new AttributeEvaluator("#[mel:(1)]");
    attributeEvaluator.initialize(mockExpressionManager);
    attributeEvaluator.resolveValue(event);
    verify(mockExpressionManager, never()).parse(anyString(), any(CoreEvent.class), any());
    verify(mockExpressionManager).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) TypedValue(org.mule.runtime.api.metadata.TypedValue) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 34 with TypedValue

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

the class MELAttributeEvaluatorTestCase method expressionValueNoEvaluator.

@Test
public void expressionValueNoEvaluator() {
    String attributeValue = "#[mel:express]";
    when(mockExpressionManager.evaluate(eq(attributeValue), any(CoreEvent.class))).thenReturn(new TypedValue(null, OBJECT));
    when(mockExpressionManager.isExpression(attributeValue)).thenReturn(true);
    AttributeEvaluator attributeEvaluator = new AttributeEvaluator(attributeValue);
    attributeEvaluator.initialize(mockExpressionManager);
    attributeEvaluator.resolveValue(event);
    verify(mockExpressionManager, never()).parse(anyString(), any(CoreEvent.class), any());
    verify(mockExpressionManager).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) Matchers.anyString(org.mockito.Matchers.anyString) AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) TypedValue(org.mule.runtime.api.metadata.TypedValue) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 35 with TypedValue

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

the class MELAttributeEvaluatorTestCase method expressionValue.

@Test
public void expressionValue() {
    String attributeValue = "#[mel:eval:express]";
    when(mockExpressionManager.evaluate(eq(attributeValue), any(CoreEvent.class))).thenReturn(new TypedValue(null, OBJECT));
    when(mockExpressionManager.isExpression(attributeValue)).thenReturn(true);
    AttributeEvaluator attributeEvaluator = new AttributeEvaluator(attributeValue);
    attributeEvaluator.initialize(mockExpressionManager);
    attributeEvaluator.resolveValue(event);
    verify(mockExpressionManager, never()).parse(anyString(), any(CoreEvent.class), any());
    verify(mockExpressionManager).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) Matchers.anyString(org.mockito.Matchers.anyString) AttributeEvaluator(org.mule.runtime.core.privileged.util.AttributeEvaluator) TypedValue(org.mule.runtime.api.metadata.TypedValue) SmallTest(org.mule.tck.size.SmallTest) 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