Search in sources :

Example 46 with ByteArrayInputStream

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

the class StreamCachingXPathRouteTest method testByteArrayInputStream.

public void testByteArrayInputStream() throws Exception {
    getMockEndpoint("mock:english").expectedBodiesReceived("<hello/>");
    getMockEndpoint("mock:dutch").expectedBodiesReceived("<hallo/>");
    getMockEndpoint("mock:german").expectedBodiesReceived("<hallo/>");
    getMockEndpoint("mock:french").expectedBodiesReceived("<hellos/>");
    template.sendBody("direct:a", new ByteArrayInputStream("<hello/>".getBytes()));
    template.sendBody("direct:a", new ByteArrayInputStream("<hallo/>".getBytes()));
    template.sendBody("direct:a", new ByteArrayInputStream("<hellos/>".getBytes()));
    assertMockEndpointsSatisfied();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 47 with ByteArrayInputStream

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

the class GZIPHelperTest method toGZIPInputStreamShouldReturnTheSameInputStream.

@Test
public void toGZIPInputStreamShouldReturnTheSameInputStream() throws IOException {
    InputStream inputStream = GZIPHelper.uncompressGzip("text", new ByteArrayInputStream(sampleBytes));
    byte[] bytes = new byte[6];
    inputStream.read(bytes);
    assertEquals(-1, inputStream.read());
    assertArrayEquals(sampleBytes, bytes);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 48 with ByteArrayInputStream

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

the class GroupTokenIteratorTest method testGroupIteratorWithDifferentEncodingFromDefault.

public void testGroupIteratorWithDifferentEncodingFromDefault() throws Exception {
    if (Charset.defaultCharset() == StandardCharsets.UTF_8) {
        // can't think of test case where having default charset set to UTF-8 is affected
        return;
    }
    byte[] buf = "£1\n£2\n".getBytes(StandardCharsets.UTF_8);
    ByteArrayInputStream in = new ByteArrayInputStream(buf);
    Scanner scanner = new Scanner(in, StandardCharsets.UTF_8.displayName());
    scanner.useDelimiter("\n");
    exchange.setProperty(Exchange.CHARSET_NAME, StandardCharsets.UTF_8.displayName());
    GroupTokenIterator gi = new GroupTokenIterator(exchange, scanner, "\n", 1, false);
    assertTrue(gi.hasNext());
    assertEquals("£1", gi.next());
    assertEquals("£2", gi.next());
    assertFalse(gi.hasNext());
    IOHelper.close(gi);
}
Also used : Scanner(java.util.Scanner) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 49 with ByteArrayInputStream

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

the class HipchatComponentConsumerTest method sendInOnly.

@Test
public void sendInOnly() throws Exception {
    result.expectedMessageCount(1);
    String expectedResponse = "{\n" + "  \"items\" : [\n" + "    {\n" + "      \"date\" : \"2015-01-19T22:07:11.030740+00:00\",\n" + "      \"from\" : {\n" + "        \"id\" : 1647095,\n" + "        \"links\" : {\n" + "          \"self\" : \"https://api.hipchat.com/v2/user/1647095\"\n" + "        },\n" + "        \"mention_name\" : \"notifier\",\n" + "        \"name\" : \"Message Notifier\"\n" + "      },\n" + "      \"id\" : \"6567c6f7-7c1b-43cf-bed0-792b1d092919\",\n" + "      \"mentions\" : [ ],\n" + "      \"message\" : \"Unit test Alert\",\n" + "      \"type\" : \"message\"\n" + "    }\n" + "  ],\n" + "  \"links\" : {\n" + "    \"self\" : \"https://api.hipchat.com/v2/user/%40ShreyasPurohit/history/latest\"\n" + "  },\n" + "  \"maxResults\" : 1,\n" + "  \"startIndex\" : 0\n" + "}";
    HttpEntity mockHttpEntity = mock(HttpEntity.class);
    when(mockHttpEntity.getContent()).thenReturn(new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8)));
    when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity);
    when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
    assertMockEndpointsSatisfied();
    assertCommonResultExchange(result.getExchanges().get(0));
}
Also used : HttpEntity(org.apache.http.HttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 50 with ByteArrayInputStream

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

the class HipchatComponentMultipleUsersTest method sendInOnlyMultipleUsers.

@Test
public void sendInOnlyMultipleUsers() throws Exception {
    result.expectedMessageCount(2);
    result.expectedHeaderValuesReceivedInAnyOrder(HipchatConstants.FROM_USER, Arrays.asList(new String[] { "@AUser", "@BUser" }));
    final String expectedResponse = "{\n" + "  \"items\" : [\n" + "    {\n" + "      \"date\" : \"2015-01-19T22:07:11.030740+00:00\",\n" + "      \"from\" : {\n" + "        \"id\" : 1647095,\n" + "        \"links\" : {\n" + "          \"self\" : \"https://api.hipchat.com/v2/user/1647095\"\n" + "        },\n" + "        \"mention_name\" : \"notifier\",\n" + "        \"name\" : \"Message Notifier\"\n" + "      },\n" + "      \"id\" : \"6567c6f7-7c1b-43cf-bed0-792b1d092919\",\n" + "      \"mentions\" : [ ],\n" + "      \"message\" : \"Unit test Alert\",\n" + "      \"type\" : \"message\"\n" + "    }\n" + "  ],\n" + "  \"links\" : {\n" + "    \"self\" : \"https://api.hipchat.com/v2/user/%40ShreyasPurohit/history/latest\"\n" + "  },\n" + "  \"maxResults\" : 1,\n" + "  \"startIndex\" : 0\n" + "}";
    HttpEntity mockHttpEntity = mock(HttpEntity.class);
    when(mockHttpEntity.getContent()).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8));
        }
    });
    when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity);
    when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
    assertMockEndpointsSatisfied();
}
Also used : HttpEntity(org.apache.http.HttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

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