01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
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.common.DummySession;
26: import org.apache.mina.common.IoSession;
27:
28: /**
29: * A test case for {@link ChainedIoHandler}.
30: *
31: * @author The Apache MINA Project (dev@mina.apache.org)
32: * @version $Rev: 576217 $, $Date: 2007-09-16 17:55:27 -0600 (Sun, 16 Sep 2007) $
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(),
47: null);
48:
49: Assert.assertEquals("ABC", buf.toString());
50: }
51:
52: private class TestCommand implements IoHandlerCommand {
53: private final StringBuffer buf;
54:
55: private final char ch;
56:
57: private TestCommand(StringBuffer buf, char ch) {
58: this .buf = buf;
59: this .ch = ch;
60: }
61:
62: public void execute(NextCommand next, IoSession session,
63: Object message) throws Exception {
64: buf.append(ch);
65: next.execute(session, message);
66: }
67: }
68: }
|