Search in sources :

Example 56 with CoreEvent

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

the class ForeachTestCase method iterablePayload.

@Test
public void iterablePayload() throws Exception {
    Iterable<String> iterable = new DummySimpleIterableClass();
    final CoreEvent testEvent = eventBuilder(muleContext).message(of(iterable)).build();
    process(simpleForeach, testEvent);
    assertSimpleProcessedMessages();
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 57 with CoreEvent

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

the class ForeachTestCase method empty.

@Test
public void empty() throws Exception {
    CoreEvent input = eventBuilder(muleContext).message(of(emptyList())).build();
    CoreEvent result = process(simpleForeach, input);
    assertThat(result.getMessage(), equalTo(input.getMessage()));
    assertThat(processedEvents, hasSize(0));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 58 with CoreEvent

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

the class ForeachTestCase method variables.

@Test
public void variables() throws Exception {
    List<String> arrayList = new ArrayList<>();
    arrayList.add("bar");
    arrayList.add("zip");
    CoreEvent in = eventBuilder(muleContext).message(of(arrayList)).build();
    process(simpleForeach, in);
    assertSimpleProcessedMessages();
    assertThat(variables.keySet(), hasSize(2));
    assertThat(variables.keySet(), hasItems(DEFAULT_ROOT_MESSAGE_VARIABLE, DEFAULT_COUNTER_VARIABLE));
    assertThat(variables.get(DEFAULT_ROOT_MESSAGE_VARIABLE).getDataType(), is(assignableTo(MULE_MESSAGE)));
    assertThat(variables.get(DEFAULT_ROOT_MESSAGE_VARIABLE).getValue(), equalTo(in.getMessage()));
    assertThat(variables.get(DEFAULT_COUNTER_VARIABLE).getDataType(), equalTo(DataType.builder().type(Integer.class).build()));
    assertThat(variables.get(DEFAULT_COUNTER_VARIABLE).getValue(), equalTo(2));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 59 with CoreEvent

use of org.mule.runtime.core.api.event.CoreEvent 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 60 with CoreEvent

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

the class IdempotentMessageValidatorTestCase method idempotentReceiver.

@Test
public void idempotentReceiver() throws Exception {
    final BaseEventContext contextA = mock(BaseEventContext.class);
    when(contextA.getCorrelationId()).thenReturn("1");
    Message okMessage = InternalMessage.builder().value("OK").build();
    CoreEvent event = CoreEvent.builder(contextA).message(okMessage).build();
    // This one will process the event on the target endpoint
    CoreEvent processedEvent = idempotent.process(event);
    assertThat(processedEvent, sameInstance(event));
    final BaseEventContext contextB = mock(BaseEventContext.class);
    when(contextB.getCorrelationId()).thenReturn("1");
    // This will not process, because the ID is a duplicate
    event = CoreEvent.builder(contextB).message(okMessage).build();
    expected.expect(ValidationException.class);
    processedEvent = idempotent.process(event);
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) 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