Search in sources :

Example 1 with WeaveDefaultExpressionLanguageFactoryService

use of org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService in project mule by mulesoft.

the class GlobalBindingContextProviderTestCase method getStartUpRegistryObjects.

@Override
protected Map<String, Object> getStartUpRegistryObjects() {
    Map<String, Object> objects = new HashMap<>();
    DefaultExpressionLanguageFactoryService weaveExpressionExecutor = new WeaveDefaultExpressionLanguageFactoryService();
    objects.put(weaveExpressionExecutor.getName(), weaveExpressionExecutor);
    objects.put(KEY, new TestGlobalBindingContextProvider());
    return objects;
}
Also used : WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) HashMap(java.util.HashMap) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) DefaultExpressionLanguageFactoryService(org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService)

Example 2 with WeaveDefaultExpressionLanguageFactoryService

use of org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService in project mule by mulesoft.

the class AbstractWeaveExpressionLanguageTestCase method setUp.

@Before
public void setUp() {
    weaveExpressionExecutor = new WeaveDefaultExpressionLanguageFactoryService();
    when(registry.lookupByType(DefaultExpressionLanguageFactoryService.class)).thenReturn(of(weaveExpressionExecutor));
    expressionLanguage = DataWeaveExpressionLanguageAdaptor.create(muleContext, registry);
}
Also used : WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) Before(org.junit.Before)

Example 3 with WeaveDefaultExpressionLanguageFactoryService

use of org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService in project mule by mulesoft.

the class IdempotentMessageValidatorTestCase method testIdCheckWithHash.

@Test
public void testIdCheckWithHash() throws Exception {
    String dwHashExpression = "%dw 2.0\n" + "output text/plain\n" + "import dw::Crypto\n" + "---\n" + "Crypto::hashWith(payload,'SHA-256')";
    String payload = "payload to be hashed";
    final BaseEventContext context = mock(BaseEventContext.class);
    when(context.getCorrelationId()).thenReturn("1");
    Message message = of(payload);
    CoreEvent event = CoreEvent.builder(context).message(message).build();
    // Set DW expression to hash value
    idempotent.setIdExpression(dwHashExpression);
    // Evaluate DW expression outside MessageValidator
    ExpressionLanguageAdaptor expressionLanguageAdaptor = new DataWeaveExpressionLanguageAdaptor(muleContext, mock(Registry.class), new WeaveDefaultExpressionLanguageFactoryService());
    TypedValue hashedValue = expressionLanguageAdaptor.evaluate(dwHashExpression, event, NULL_BINDING_CONTEXT);
    // This one will process the event on the target endpoint
    CoreEvent processedEvent = idempotent.process(event);
    assertNotNull(processedEvent);
    assertEquals(idempotent.getObjectStore().retrieve(IOUtils.toString((ByteArrayBasedCursorStreamProvider) hashedValue.getValue())), "1");
    // This will not process, because the message is a duplicate
    message = of(payload);
    event = CoreEvent.builder(context).message(message).build();
    expected.expect(ValidationException.class);
    processedEvent = idempotent.process(event);
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpressionLanguageAdaptor(org.mule.runtime.core.internal.el.ExpressionLanguageAdaptor) DataWeaveExpressionLanguageAdaptor(org.mule.runtime.core.internal.el.dataweave.DataWeaveExpressionLanguageAdaptor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Registry(org.mule.runtime.api.artifact.Registry) DataWeaveExpressionLanguageAdaptor(org.mule.runtime.core.internal.el.dataweave.DataWeaveExpressionLanguageAdaptor) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 4 with WeaveDefaultExpressionLanguageFactoryService

use of org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService in project mule by mulesoft.

the class IdempotentMessageValidatorTestCase method differentIdsShouldBeStored.

@Test
public void differentIdsShouldBeStored() throws Exception {
    String dwHashExpression = "%dw 2.0\n" + "output text/plain\n" + "import dw::Crypto\n" + "---\n" + "Crypto::SHA1(payload)";
    String payload = "payload to be hashed";
    String otherPayload = "this is another payload to be hashed";
    final BaseEventContext context = mock(BaseEventContext.class);
    when(context.getCorrelationId()).thenReturn("1");
    Message message = of(payload);
    CoreEvent event = CoreEvent.builder(context).message(message).build();
    // Set DW expression to hash value
    idempotent.setIdExpression(dwHashExpression);
    // Evaluate DW expression outside MessageValidator
    ExpressionLanguageAdaptor expressionLanguageAdaptor = new DataWeaveExpressionLanguageAdaptor(muleContext, mock(Registry.class), new WeaveDefaultExpressionLanguageFactoryService());
    TypedValue hashedValue = expressionLanguageAdaptor.evaluate(dwHashExpression, event, NULL_BINDING_CONTEXT);
    // This one will process the event on the target endpoint
    CoreEvent processedEvent = idempotent.process(event);
    assertNotNull(processedEvent);
    assertEquals(idempotent.getObjectStore().retrieve(IOUtils.toString((ByteArrayBasedCursorStreamProvider) hashedValue.getValue())), "1");
    // This will process, because the message is a new one
    Message otherMessage = of(otherPayload);
    event = CoreEvent.builder(context).message(otherMessage).build();
    processedEvent = idempotent.process(event);
    assertNotNull(processedEvent);
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpressionLanguageAdaptor(org.mule.runtime.core.internal.el.ExpressionLanguageAdaptor) DataWeaveExpressionLanguageAdaptor(org.mule.runtime.core.internal.el.dataweave.DataWeaveExpressionLanguageAdaptor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Registry(org.mule.runtime.api.artifact.Registry) DataWeaveExpressionLanguageAdaptor(org.mule.runtime.core.internal.el.dataweave.DataWeaveExpressionLanguageAdaptor) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 5 with WeaveDefaultExpressionLanguageFactoryService

use of org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService in project mule by mulesoft.

the class OperationMessageProcessorTestCase method operationWithoutExpressionInTargetValueParameter.

@Test
public void operationWithoutExpressionInTargetValueParameter() throws Exception {
    String flowName = "flowName";
    expectedException.expect(IllegalOperationException.class);
    expectedException.expectMessage(format(INVALID_TARGET_MESSAGE, flowName, operationModel.getName(), "something that is not an expression", TARGET_VALUE_PARAMETER_NAME));
    target = TARGET_VAR;
    targetValue = TARGET_VAR;
    messageProcessor = createOperationMessageProcessor();
    when(context.getRegistry().lookupObject(OBJECT_EXPRESSION_LANGUAGE)).thenReturn(new MVELExpressionLanguage(context));
    when(context.getRegistry().lookupObject(DefaultExpressionLanguageFactoryService.class)).thenReturn(new WeaveDefaultExpressionLanguageFactoryService());
    doReturn(new DefaultExpressionManager()).when(context).getExpressionManager();
    FlowConstruct flowConstruct = mock(FlowConstruct.class);
    when(flowConstruct.getName()).thenReturn(flowName);
    messageProcessor.setMuleContext(context);
    messageProcessor.initialise();
}
Also used : WeaveDefaultExpressionLanguageFactoryService(org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService) DefaultExpressionManager(org.mule.runtime.core.internal.el.DefaultExpressionManager) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

WeaveDefaultExpressionLanguageFactoryService (org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService)8 Test (org.junit.Test)4 DefaultExpressionLanguageFactoryService (org.mule.runtime.api.el.DefaultExpressionLanguageFactoryService)3 Registry (org.mule.runtime.api.artifact.Registry)2 Message (org.mule.runtime.api.message.Message)2 TypedValue (org.mule.runtime.api.metadata.TypedValue)2 FlowConstruct (org.mule.runtime.core.api.construct.FlowConstruct)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 DefaultExpressionManager (org.mule.runtime.core.internal.el.DefaultExpressionManager)2 ExpressionLanguageAdaptor (org.mule.runtime.core.internal.el.ExpressionLanguageAdaptor)2 DataWeaveExpressionLanguageAdaptor (org.mule.runtime.core.internal.el.dataweave.DataWeaveExpressionLanguageAdaptor)2 MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)2 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)2 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)2 SmallTest (org.mule.tck.size.SmallTest)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 ExpressionLanguage (org.mule.runtime.api.el.ExpressionLanguage)1 MuleException (org.mule.runtime.api.exception.MuleException)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1