Search in sources :

Example 26 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class ConvertBodyTest method testConvertToStringCharset.

public void testConvertToStringCharset() throws Exception {
    String body = "Hello World";
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedBodiesReceived(body);
    template.sendBody("direct:charset3", new ByteArrayInputStream(body.getBytes("utf-16")));
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 27 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class ConvertBodyTest method testConvertToStringCharsetFail.

public void testConvertToStringCharsetFail() throws Exception {
    // does not work on AIX
    String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
    boolean aix = osName.indexOf("aix") > -1;
    if (aix) {
        return;
    }
    String body = "Hellö Wörld";
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedBodiesReceived(body);
    template.sendBody("direct:charset3", new ByteArrayInputStream(body.getBytes("utf-8")));
    // should NOT be okay as we expected utf-8 but got it in utf-16
    result.assertIsNotSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 28 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class DefaultTraceEventMessageTest method testDefaultTraceEventMessageBody.

public void testDefaultTraceEventMessageBody() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(new File("target/test"));
    DefaultTraceEventMessage em = new DefaultTraceEventMessage(new Date(), null, exchange);
    assertEquals("Get a wrong body string", "[Body is file based: target" + File.separator + "test]", em.getBody());
    exchange.getIn().setBody(new ByteArrayInputStream("target/test".getBytes()));
    em = new DefaultTraceEventMessage(new Date(), null, exchange);
    assertEquals("Get a wrong body string", "[Body is instance of java.io.InputStream]", em.getBody());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) Date(java.util.Date)

Example 29 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class NoStreamCachingTest method testNoStreamCache.

public void testNoStreamCache() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:a").noStreamCaching().to("mock:a");
        }
    });
    context.start();
    a.expectedMessageCount(1);
    InputStream message = new ByteArrayInputStream(MESSAGE.getBytes());
    template.sendBody("direct:a", message);
    assertMockEndpointsSatisfied();
    assertTrue(a.assertExchangeReceived(0).getIn().getBody() instanceof ByteArrayInputStream);
    assertEquals(a.assertExchangeReceived(0).getIn().getBody(String.class), MESSAGE);
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 30 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class StreamCachingInterceptorTest method testConvertInputStreamWithRouteBuilderStreamCaching.

public void testConvertInputStreamWithRouteBuilderStreamCaching() throws Exception {
    a.expectedMessageCount(1);
    InputStream message = new ByteArrayInputStream(MESSAGE.getBytes());
    template.sendBody("direct:a", message);
    assertMockEndpointsSatisfied();
    assertTrue(a.assertExchangeReceived(0).getIn().getBody() instanceof StreamCache);
    assertEquals(a.assertExchangeReceived(0).getIn().getBody(String.class), MESSAGE);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCache(org.apache.camel.StreamCache) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)6879 Test (org.junit.Test)2274 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1791 InputStream (java.io.InputStream)1531 IOException (java.io.IOException)1400 DataInputStream (java.io.DataInputStream)600 ObjectInputStream (java.io.ObjectInputStream)597 X509Certificate (java.security.cert.X509Certificate)397 CertificateFactory (java.security.cert.CertificateFactory)355 ObjectOutputStream (java.io.ObjectOutputStream)333 File (java.io.File)279 ArrayList (java.util.ArrayList)270 Certificate (java.security.cert.Certificate)234 HashMap (java.util.HashMap)212 DataOutputStream (java.io.DataOutputStream)200 FileInputStream (java.io.FileInputStream)182 InputStreamReader (java.io.InputStreamReader)180 Test (org.testng.annotations.Test)171 Document (org.w3c.dom.Document)143 Map (java.util.Map)138