Search in sources :

Example 1 with CharacterStreamWritingMessageHandler

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"));
}
Also used : MessageHandlerChain(org.springframework.integration.handler.MessageHandlerChain) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Charset(java.nio.charset.Charset) CharacterStreamWritingMessageHandler(org.springframework.integration.stream.CharacterStreamWritingMessageHandler) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Charset (java.nio.charset.Charset)1 Test (org.junit.Test)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 MessageHandlerChain (org.springframework.integration.handler.MessageHandlerChain)1 CharacterStreamWritingMessageHandler (org.springframework.integration.stream.CharacterStreamWritingMessageHandler)1