1 20 package org.apache.mina.handler.chain; 21 22 import java.net.SocketAddress ; 23 24 import junit.framework.Assert; 25 import junit.framework.TestCase; 26 27 import org.apache.mina.common.IoFilterChain; 28 import org.apache.mina.common.IoHandler; 29 import org.apache.mina.common.IoServiceConfig; 30 import org.apache.mina.common.IoSession; 31 import org.apache.mina.common.IoService; 32 import org.apache.mina.common.IoSessionConfig; 33 import org.apache.mina.common.TransportType; 34 import org.apache.mina.common.support.BaseIoSession; 35 36 42 public class ChainedIoHandlerTest extends TestCase { 43 public static void main(String [] args) { 44 junit.textui.TestRunner.run(ChainedIoHandlerTest.class); 45 } 46 47 public void testChainedCommand() throws Exception { 48 IoHandlerChain chain = new IoHandlerChain(); 49 StringBuffer buf = new StringBuffer (); 50 chain.addLast("A", new TestCommand(buf, 'A')); 51 chain.addLast("B", new TestCommand(buf, 'B')); 52 chain.addLast("C", new TestCommand(buf, 'C')); 53 54 new ChainedIoHandler(chain).messageReceived(new BaseIoSession() { 55 protected void updateTrafficMask() { 56 } 57 58 public IoService getService() { 59 return null; 60 } 61 62 public IoServiceConfig getServiceConfig() { 63 return null; 64 } 65 66 public IoHandler getHandler() { 67 return null; 68 } 69 70 public IoFilterChain getFilterChain() { 71 return null; 72 } 73 74 public TransportType getTransportType() { 75 return null; 76 } 77 78 public SocketAddress getRemoteAddress() { 79 return null; 80 } 81 82 public SocketAddress getLocalAddress() { 83 return null; 84 } 85 86 public int getScheduledWriteRequests() { 87 return 0; 88 } 89 90 public IoSessionConfig getConfig() { 91 return null; 92 } 93 94 public SocketAddress getServiceAddress() { 95 return null; 96 } 97 98 public int getScheduledWriteBytes() { 99 return 0; 100 } 101 }, null); 102 103 Assert.assertEquals("ABC", buf.toString()); 104 } 105 106 private class TestCommand implements IoHandlerCommand { 107 private final StringBuffer buf; 108 109 private final char ch; 110 111 private TestCommand(StringBuffer buf, char ch) { 112 this.buf = buf; 113 this.ch = ch; 114 } 115 116 public void execute(NextCommand next, IoSession session, Object message) 117 throws Exception { 118 buf.append(ch); 119 next.execute(session, message); 120 } 121 } 122 } 123 | Popular Tags |