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