Search in sources :

Example 6 with CursorIteratorProvider

use of org.mule.runtime.api.streaming.object.CursorIteratorProvider in project mule by mulesoft.

the class ObjectStreamingExtensionTestCase method getObjectStreamWithTargetVariable.

@Test
@Description("Stores an object stream in a variable leaving without modifying the original payload")
public void getObjectStreamWithTargetVariable() throws Exception {
    CoreEvent event = flowRunner("getStreamWithTarget").keepStreamsOpen().withPayload(data).run();
    assertThat(event.getVariables().get(MY_STREAM_VAR).getValue(), is(instanceOf(CursorIteratorProvider.class)));
    assertThat(IteratorUtils.toList(((CursorIteratorProvider) event.getVariables().get(MY_STREAM_VAR).getValue()).openCursor()), equalTo(data));
    assertThat(event.getMessage().getPayload().getValue(), is(instanceOf(List.class)));
    assertThat(event.getMessage().getPayload().getValue(), equalTo(data));
}
Also used : CursorIteratorProvider(org.mule.runtime.api.streaming.object.CursorIteratorProvider) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 7 with CursorIteratorProvider

use of org.mule.runtime.api.streaming.object.CursorIteratorProvider in project mule by mulesoft.

the class StreamingUtilsTestCase method consumeTypedRepeatableIteratorPayload.

@Test
@Description("Test that repeatable iterator is consumed into a list while maintaining the collection data type")
public void consumeTypedRepeatableIteratorPayload() throws Exception {
    CursorIteratorProvider payload = asCursorProvider(TEST_LIST);
    DataType dataType = DataType.builder().collectionType(ArrayList.class).itemType(String.class).build();
    CoreEvent event = consumeRepeatablePayload(getEventBuilder().message(Message.builder().payload(new TypedValue<>(payload, dataType)).build()).build());
    assertConsumedObjectStream(payload, event);
    dataType = event.getMessage().getPayload().getDataType();
    assertThat(dataType, is(instanceOf(CollectionDataType.class)));
    assertThat(((CollectionDataType) dataType).getItemDataType(), equalTo(STRING));
}
Also used : InMemoryCursorIteratorProvider(org.mule.runtime.core.internal.streaming.object.InMemoryCursorIteratorProvider) CursorIteratorProvider(org.mule.runtime.api.streaming.object.CursorIteratorProvider) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) Description(io.qameta.allure.Description) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

CursorIteratorProvider (org.mule.runtime.api.streaming.object.CursorIteratorProvider)7 Test (org.junit.Test)4 Description (io.qameta.allure.Description)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 SmallTest (org.mule.tck.size.SmallTest)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 CollectionDataType (org.mule.runtime.api.metadata.CollectionDataType)2 DataType (org.mule.runtime.api.metadata.DataType)2 TypedValue (org.mule.runtime.api.metadata.TypedValue)2 CursorStreamProvider (org.mule.runtime.api.streaming.bytes.CursorStreamProvider)2 InMemoryCursorIteratorProvider (org.mule.runtime.core.internal.streaming.object.InMemoryCursorIteratorProvider)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 Message (org.mule.runtime.api.message.Message)1 CursorIterator (org.mule.runtime.api.streaming.object.CursorIterator)1