use of org.springframework.integration.stream.CharacterStreamWritingMessageHandler in project spring-integration by spring-projects.
the class ConsoleOutboundChannelAdapterParserTests method stdoutInsideNestedChain.
// INT-2275
@Test
public void stdoutInsideNestedChain() throws IOException {
List<?> handlers = TestUtils.getPropertyValue(this.stdoutChainHandler, "handlers", List.class);
assertEquals(2, handlers.size());
Object chainHandler = handlers.get(1);
assertTrue(chainHandler instanceof MessageHandlerChain);
List<?> nestedChainHandlers = TestUtils.getPropertyValue(chainHandler, "handlers", List.class);
assertEquals(1, nestedChainHandlers.size());
Object stdoutHandler = nestedChainHandlers.get(0);
assertTrue(stdoutHandler instanceof CharacterStreamWritingMessageHandler);
BufferedWriter bufferedWriter = TestUtils.getPropertyValue(stdoutHandler, "writer", BufferedWriter.class);
Writer writer = TestUtils.getPropertyValue(bufferedWriter, "out", Writer.class);
assertEquals(OutputStreamWriter.class, writer.getClass());
Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding());
assertEquals(Charset.defaultCharset(), writerCharset);
Object lock = TestUtils.getPropertyValue(writer, "lock");
assertEquals(System.out, lock);
bufferedWriter = Mockito.spy(bufferedWriter);
DirectFieldAccessor dfa = new DirectFieldAccessor(stdoutHandler);
dfa.setPropertyValue("writer", bufferedWriter);
this.stdoutInsideNestedChain.send(new GenericMessage<String>("foo"));
verify(bufferedWriter, times(1)).write(eq("foobar"));
}
Aggregations