1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.handler.chain;
21
22 import junit.framework.Assert;
23 import junit.framework.TestCase;
24
25 import org.apache.mina.core.session.DummySession;
26 import org.apache.mina.core.session.IoSession;
27
28
29
30
31
32
33
34 public class ChainedIoHandlerTest extends TestCase {
35 public static void main(String[] args) {
36 junit.textui.TestRunner.run(ChainedIoHandlerTest.class);
37 }
38
39 public void testChainedCommand() throws Exception {
40 IoHandlerChain chain = new IoHandlerChain();
41 StringBuffer buf = new StringBuffer();
42 chain.addLast("A", new TestCommand(buf, 'A'));
43 chain.addLast("B", new TestCommand(buf, 'B'));
44 chain.addLast("C", new TestCommand(buf, 'C'));
45
46 new ChainedIoHandler(chain).messageReceived(new DummySession(), null);
47
48 Assert.assertEquals("ABC", buf.toString());
49 }
50
51 private class TestCommand implements IoHandlerCommand {
52 private final StringBuffer buf;
53
54 private final char ch;
55
56 private TestCommand(StringBuffer buf, char ch) {
57 this.buf = buf;
58 this.ch = ch;
59 }
60
61 public void execute(NextCommand next, IoSession session, Object message)
62 throws Exception {
63 buf.append(ch);
64 next.execute(session, message);
65 }
66 }
67 }