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();
}
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));
}
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));
}
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);
}
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);
}
Aggregations