Search in sources :

Example 1 with InMemoryCursorStreamProvider

use of org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider in project mule by mulesoft.

the class CursorStreamProviderTestCase method dataLengthMatchesMaxBufferSizeExactly.

@Test
public void dataLengthMatchesMaxBufferSizeExactly() throws Exception {
    data = randomAlphabetic(maxBufferSize);
    final ByteArrayInputStream dataStream = new ByteArrayInputStream(data.getBytes());
    InMemoryCursorStreamConfig config = new InMemoryCursorStreamConfig(new DataSize(maxBufferSize, BYTE), new DataSize(0, BYTE), new DataSize(maxBufferSize, BYTE));
    streamProvider = new InMemoryCursorStreamProvider(dataStream, config, bufferManager);
    withCursor(cursor -> assertThat(IOUtils.toString(cursor), equalTo(data)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataSize(org.mule.runtime.api.util.DataSize) InMemoryCursorStreamConfig(org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamConfig) InMemoryCursorStreamProvider(org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with InMemoryCursorStreamProvider

use of org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider in project mule by mulesoft.

the class InputStreamToByteArrayTestCase method transformCursorStreamProvider.

@Test
public void transformCursorStreamProvider() throws Exception {
    InputStream inputStream = new ByteArrayInputStream(DONKEY.getBytes());
    CursorStreamProvider provider = new InMemoryCursorStreamProvider(inputStream, InMemoryCursorStreamConfig.getDefault(), new SimpleByteBufferManager());
    assertThat(transformer.transform(provider), equalTo(DONKEY.getBytes()));
}
Also used : InMemoryCursorStreamProvider(org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider) CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) SimpleByteBufferManager(org.mule.tck.core.streaming.SimpleByteBufferManager) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InMemoryCursorStreamProvider(org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with InMemoryCursorStreamProvider

use of org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider in project mule by mulesoft.

the class InMemoryCursorStreamProviderFactory method resolve.

/**
 * {@inheritDoc}
 *
 * @return a new {@link InMemoryCursorStreamProvider} wrapped in an {@link Either}
 */
@Override
protected Object resolve(InputStream inputStream, CoreEvent event) {
    InMemoryCursorStreamProvider inMemoryCursorStreamProvider = new InMemoryCursorStreamProvider(inputStream, config, getBufferManager());
    inMemoryCursorStreamProvider.setAnnotations(getAnnotations());
    return inMemoryCursorStreamProvider;
}
Also used : InMemoryCursorStreamProvider(org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider)

Example 4 with InMemoryCursorStreamProvider

use of org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider in project mule by mulesoft.

the class FunctionExecutionTestCase method xpathWithDefaultNode.

@Test
public void xpathWithDefaultNode() throws Exception {
    InputStream stream = getDocumentStream();
    InMemoryCursorStreamProvider streamProvider = new InMemoryCursorStreamProvider(stream, InMemoryCursorStreamConfig.getDefault(), new SimpleByteBufferManager());
    Object value = flowRunner("xpathWithDefaultNode").withVariable("xmlPayload", streamProvider).run().getMessage().getPayload().getValue();
    assertThat(value, is("xpathWithDefaultNode"));
}
Also used : SimpleByteBufferManager(org.mule.tck.core.streaming.SimpleByteBufferManager) InputStream(java.io.InputStream) InMemoryCursorStreamProvider(org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider) Test(org.junit.Test)

Example 5 with InMemoryCursorStreamProvider

use of org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider in project mule by mulesoft.

the class PetStoreSerializableParameterTestCase method cursorStreamProviderParameter.

@Test
public void cursorStreamProviderParameter() throws Exception {
    InputStream inputStream = new ByteArrayInputStream(DONKEY.getBytes());
    CursorStreamProvider provider = new InMemoryCursorStreamProvider(inputStream, InMemoryCursorStreamConfig.getDefault(), new SimpleByteBufferManager());
    Message message = flowRunner("dynamicSerializableParameter").withVariable("animal", provider).run().getMessage();
    assertThat(message.getPayload().getValue(), is(DONKEY));
}
Also used : InMemoryCursorStreamProvider(org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider) CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) SimpleByteBufferManager(org.mule.tck.core.streaming.SimpleByteBufferManager) Message(org.mule.runtime.api.message.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InMemoryCursorStreamProvider(org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider) Test(org.junit.Test)

Aggregations

InMemoryCursorStreamProvider (org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamProvider)5 Test (org.junit.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 SimpleByteBufferManager (org.mule.tck.core.streaming.SimpleByteBufferManager)3 CursorStreamProvider (org.mule.runtime.api.streaming.bytes.CursorStreamProvider)2 SmallTest (org.mule.tck.size.SmallTest)2 Message (org.mule.runtime.api.message.Message)1 DataSize (org.mule.runtime.api.util.DataSize)1 InMemoryCursorStreamConfig (org.mule.runtime.core.api.streaming.bytes.InMemoryCursorStreamConfig)1