Search in sources :

Example 11 with CoreEvent

use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.

the class DataWeaveExpressionLanguageAdaptorTestCase method authenticationBindingWhenNullSecurityContext.

@Test
public void authenticationBindingWhenNullSecurityContext() throws Exception {
    CoreEvent event = spy(testEvent());
    TypedValue result = expressionLanguage.evaluate(AUTHENTICATION, event, BindingContext.builder().build());
    assertThat(result.getValue(), is(nullValue()));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 12 with CoreEvent

use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.

the class DataWeaveExpressionLanguageAdaptorTestCase method splitByJson.

@Test
public void splitByJson() throws Exception {
    CoreEvent jsonMessage = eventBuilder(muleContext).message(Message.builder().value("[1,2,3]").mediaType(APPLICATION_JSON).build()).build();
    Iterator<TypedValue<?>> payload = expressionLanguage.split("payload", jsonMessage, BindingContext.builder().build());
    assertThat(payload.hasNext(), is(true));
    assertThat(payload.next().getValue().toString(), is("1"));
    assertThat(payload.hasNext(), is(true));
    assertThat(payload.next().getValue().toString(), is("2"));
    assertThat(payload.hasNext(), is(true));
    assertThat(payload.next().getValue().toString(), is("3"));
    assertThat(payload.hasNext(), is(false));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 13 with CoreEvent

use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.

the class DataWeaveExpressionLanguageAdaptorTestCase method accessRegistryAnnotatedBean.

@Test
public void accessRegistryAnnotatedBean() throws MuleException {
    CoreEvent event = testEvent();
    when(registry.lookupByName("myBean")).thenReturn(of(new MyAnnotatedBean("DataWeave")));
    TypedValue evaluate = expressionLanguage.evaluate("app.registry.myBean", DataType.fromType(MyBean.class), event, fromSingleComponent("flow"), BindingContext.builder().build(), false);
    assertThat(evaluate.getValue(), is(instanceOf(MyAnnotatedBean.class)));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 14 with CoreEvent

use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.

the class DataWeaveExpressionLanguageAdaptorTestCase method attributesBinding.

@Test
public void attributesBinding() throws Exception {
    CoreEvent event = getEventWithError(empty());
    SomeAttributes attributes = new SomeAttributes();
    InternalMessage message = (InternalMessage) Message.builder().nullValue().attributesValue(attributes).build();
    when(event.getMessage()).thenReturn(message);
    TypedValue result = expressionLanguage.evaluate(ATTRIBUTES, event, BindingContext.builder().build());
    assertThat(result.getValue(), is(equalTo(attributes)));
    assertThat(result.getDataType().getType(), is((equalTo(SomeAttributes.class))));
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 15 with CoreEvent

use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.

the class ExtendedExpressionLanguageAdapterTestCase method enrichTypedValueCompatibility.

@Test
@Description("Verifies that enrichment using a TypedValue only works for MVEL.")
public void enrichTypedValueCompatibility() throws MuleException {
    CoreEvent event = testEvent();
    CoreEvent.Builder builder = builder(event);
    TypedValue myPayload = new TypedValue("myPayload", STRING);
    String expression = "payload";
    expressionLanguageAdapter.enrich(melify(expression), event, builder, TEST_CONNECTOR_LOCATION, myPayload);
    CoreEvent enrichedEvent = builder.build();
    assertThat(enrichedEvent.getMessage().getPayload().getValue(), is(myPayload.getValue()));
    assertThat(enrichedEvent.getMessage().getPayload().getDataType(), is(myPayload.getDataType()));
    expectedException.expect(UnsupportedOperationException.class);
    expressionLanguageAdapter.enrich(expression, event, builder, TEST_CONNECTOR_LOCATION, myPayload);
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Aggregations

CoreEvent (org.mule.runtime.core.api.event.CoreEvent)485 Test (org.junit.Test)394 Message (org.mule.runtime.api.message.Message)103 SmallTest (org.mule.tck.size.SmallTest)100 TypedValue (org.mule.runtime.api.metadata.TypedValue)44 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)39 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)38 Description (io.qameta.allure.Description)37 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)37 List (java.util.List)36 MuleException (org.mule.runtime.api.exception.MuleException)33 Processor (org.mule.runtime.core.api.processor.Processor)33 DataType (org.mule.runtime.api.metadata.DataType)28 InternalEvent (org.mule.runtime.core.internal.message.InternalEvent)28 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)27 ArrayList (java.util.ArrayList)26 Map (java.util.Map)26 Optional (java.util.Optional)25 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)23 InOrder (org.mockito.InOrder)22