EMMA Coverage Report (generated Tue Dec 20 11:01:01 KST 2005)
[all classes][org.apache.mina.io]

COVERAGE SUMMARY FOR SOURCE FILE [IoFilterChainTest.java]

nameclass, %method, %block, %line, %
IoFilterChainTest.java83%  (5/6)76%  (29/38)97%  (635/654)92%  (112/122)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class IoFilterChainTest$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class IoFilterChainTest$TestSession100% (1/1)18%  (2/11)48%  (15/31)25%  (3/12)
close (boolean): void 0%   (0/1)0%   (0/1)0%   (0/1)
getConfig (): SessionConfig 0%   (0/1)0%   (0/2)0%   (0/1)
getFilterChain (): IoFilterChain 0%   (0/1)0%   (0/2)0%   (0/1)
getLocalAddress (): SocketAddress 0%   (0/1)0%   (0/2)0%   (0/1)
getRemoteAddress (): SocketAddress 0%   (0/1)0%   (0/2)0%   (0/1)
getScheduledWriteRequests (): int 0%   (0/1)0%   (0/2)0%   (0/1)
getTransportType (): TransportType 0%   (0/1)0%   (0/2)0%   (0/1)
isConnected (): boolean 0%   (0/1)0%   (0/2)0%   (0/1)
write (ByteBuffer, Object): void 0%   (0/1)0%   (0/1)0%   (0/1)
IoFilterChainTest$TestSession (IoFilterChainTest): void 100% (1/1)100% (12/12)100% (2/2)
getHandler (): IoHandler 100% (1/1)100% (3/3)100% (1/1)
     
class IoFilterChainTest$TestSession$1100% (1/1)100% (7/7)95%  (59/62)93%  (14/15)
exceptionCaught (IoSession, Throwable): void 100% (1/1)86%  (18/21)75%  (3/4)
IoFilterChainTest$TestSession$1 (IoFilterChainTest$TestSession): void 100% (1/1)100% (6/6)100% (1/1)
dataRead (IoSession, ByteBuffer): void 100% (1/1)100% (7/7)100% (2/2)
dataWritten (IoSession, Object): void 100% (1/1)100% (7/7)100% (2/2)
sessionClosed (IoSession): void 100% (1/1)100% (7/7)100% (2/2)
sessionIdle (IoSession, IdleStatus): void 100% (1/1)100% (7/7)100% (2/2)
sessionOpened (IoSession): void 100% (1/1)100% (7/7)100% (2/2)
     
class IoFilterChainTest100% (1/1)100% (10/10)100% (419/419)100% (67/67)
IoFilterChainTest (): void 100% (1/1)100% (3/3)100% (2/2)
formatResult (String): String 100% (1/1)100% (41/41)100% (7/7)
run (String): void 100% (1/1)100% (75/75)100% (12/12)
setUp (): void 100% (1/1)100% (16/16)100% (4/4)
tearDown (): void 100% (1/1)100% (1/1)100% (1/1)
testAdd (): void 100% (1/1)100% (113/113)100% (15/15)
testChained (): void 100% (1/1)100% (24/24)100% (4/4)
testClear (): void 100% (1/1)100% (60/60)100% (8/8)
testDefault (): void 100% (1/1)100% (4/4)100% (2/2)
testRemove (): void 100% (1/1)100% (82/82)100% (12/12)
     
class IoFilterChainTest$IoFilterChainImpl100% (1/1)100% (2/2)100% (8/8)100% (4/4)
IoFilterChainTest$IoFilterChainImpl (): void 100% (1/1)100% (3/3)100% (2/2)
doWrite (IoSession, ByteBuffer, Object): void 100% (1/1)100% (5/5)100% (2/2)
     
class IoFilterChainTest$TestFilter100% (1/1)100% (8/8)100% (134/134)100% (24/24)
IoFilterChainTest$TestFilter (IoFilterChainTest, char): void 100% (1/1)100% (9/9)100% (3/3)
dataRead (IoFilter$NextFilter, IoSession, ByteBuffer): void 100% (1/1)100% (18/18)100% (3/3)
dataWritten (IoFilter$NextFilter, IoSession, Object): void 100% (1/1)100% (18/18)100% (3/3)
exceptionCaught (IoFilter$NextFilter, IoSession, Throwable): void 100% (1/1)100% (18/18)100% (3/3)
filterWrite (IoFilter$NextFilter, IoSession, ByteBuffer, Object): void 100% (1/1)100% (19/19)100% (3/3)
sessionClosed (IoFilter$NextFilter, IoSession): void 100% (1/1)100% (17/17)100% (3/3)
sessionIdle (IoFilter$NextFilter, IoSession, IdleStatus): void 100% (1/1)100% (18/18)100% (3/3)
sessionOpened (IoFilter$NextFilter, IoSession): void 100% (1/1)100% (17/17)100% (3/3)

1/*
2 *   @(#) $Id: IoFilterChainTest.java 357871 2005-12-20 01:56:40Z trustin $
3 *
4 *   Copyright 2004 The Apache Software Foundation
5 *
6 *   Licensed under the Apache License, Version 2.0 (the "License");
7 *   you may not use this file except in compliance with the License.
8 *   You may obtain a copy of the License at
9 *
10 *       http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *   Unless required by applicable law or agreed to in writing, software
13 *   distributed under the License is distributed on an "AS IS" BASIS,
14 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *   See the License for the specific language governing permissions and
16 *   limitations under the License.
17 *
18 */
19package org.apache.mina.io;
20 
21import java.net.SocketAddress;
22import java.util.Iterator;
23 
24import junit.framework.Assert;
25import junit.framework.TestCase;
26 
27import org.apache.mina.common.BaseSession;
28import org.apache.mina.common.ByteBuffer;
29import org.apache.mina.common.IdleStatus;
30import org.apache.mina.common.SessionConfig;
31import org.apache.mina.common.TransportType;
32 
33/**
34 * Tests {@link AbstractIoFilterChain}.
35 * 
36 * @author The Apache Directory Project (dev@directory.apache.org)
37 * @version $Rev: 357871 $, $Date: 2005-12-20 10:56:40 +0900 (Tue, 20 Dec 2005) $ 
38 */
39public class IoFilterChainTest extends TestCase
40{
41    private IoFilterChainImpl chain;
42    private IoSession session;
43    private String result;
44 
45    public void setUp()
46    {
47        chain = new IoFilterChainImpl();
48        session = new TestSession();
49        result = "";
50    }
51    
52    public void tearDown()
53    {
54    }
55    
56    public void testAdd() throws Exception
57    {
58        chain.addFirst( "A", new TestFilter( 'A' ) );
59        chain.addLast( "B", new TestFilter( 'B' ) );
60        chain.addFirst( "C", new TestFilter( 'C' ) );
61        chain.addLast( "D", new TestFilter( 'D' ) );
62        chain.addBefore( "B", "E", new TestFilter( 'E' ) );
63        chain.addBefore( "C", "F", new TestFilter( 'F' ) );
64        chain.addAfter( "B", "G", new TestFilter( 'G' ) );
65        chain.addAfter( "D", "H", new TestFilter( 'H' ) );
66        
67        String actual = "";
68        for( Iterator i = chain.getChildren().iterator(); i.hasNext(); ) 
69        {
70            TestFilter f = ( TestFilter ) i.next();
71            actual += f.id;
72        }
73        
74        Assert.assertEquals( "FCAEBGDH", actual );
75    }
76    
77    public void testRemove() throws Exception
78    {
79        chain.addLast( "A", new TestFilter( 'A' ) );
80        chain.addLast( "B", new TestFilter( 'B' ) );
81        chain.addLast( "C", new TestFilter( 'C' ) );
82        chain.addLast( "D", new TestFilter( 'D' ) );
83        chain.addLast( "E", new TestFilter( 'E' ) );
84        
85        chain.remove( "A" );
86        chain.remove( "E" );
87        chain.remove( "C" );
88        chain.remove( "B" );
89        chain.remove( "D" );
90        
91        Assert.assertEquals( 0, chain.getChildren().size() );
92    }
93    
94    public void testClear() throws Exception
95    {
96        chain.addLast( "A", new TestFilter( 'A' ) );
97        chain.addLast( "B", new TestFilter( 'B' ) );
98        chain.addLast( "C", new TestFilter( 'C' ) );
99        chain.addLast( "D", new TestFilter( 'D' ) );
100        chain.addLast( "E", new TestFilter( 'E' ) );
101        
102        chain.clear();
103        
104        Assert.assertEquals( 0, chain.getChildren().size() );
105    }
106    
107    public void testDefault()
108    {
109        run( "HSO HDR HDW HSI HEC HSC" );
110    }
111    
112    public void testChained()
113    {
114        chain.addLast( "A", new TestFilter( 'A' ) );
115        chain.addLast( "B", new TestFilter( 'B' ) );
116        run( "ASO BSO HSO" +
117             "ADR BDR HDR" +
118             "BFW AFW ADW BDW HDW" +
119             "ASI BSI HSI" +
120             "AEC BEC HEC" +
121             "ASC BSC HSC" );
122    }
123    
124    private void run( String expectedResult )
125    {
126        chain.sessionOpened( session );
127        chain.dataRead( session, ByteBuffer.allocate( 16 ) );
128        chain.filterWrite( session, ByteBuffer.allocate( 16 ), null );
129        chain.sessionIdle( session, IdleStatus.READER_IDLE );
130        chain.exceptionCaught( session, new Exception() );
131        chain.sessionClosed( session );
132        
133        result = formatResult( result );
134        expectedResult = formatResult( expectedResult );
135        
136        System.out.println( "Expected: " + expectedResult );
137        System.out.println( "Actual:   " + result );
138        Assert.assertEquals( expectedResult, result );
139    }
140    
141    private String formatResult( String result )
142    {
143        result = result.replaceAll( "\\s", "" );
144        StringBuffer buf = new StringBuffer( result.length() * 4 / 3 );
145        for( int i = 0; i < result.length(); i++ )
146        {
147            buf.append( result.charAt( i ) );
148            if( i % 3 == 2 )
149            {
150                buf.append(' ');
151            }
152        }
153        
154        return buf.toString();
155    }
156 
157    private class TestSession extends BaseSession implements IoSession
158    {
159        private IoHandler handler = new IoHandlerAdapter()
160        {
161            public void sessionOpened(IoSession session) {
162                result += "HSO ";
163            }
164 
165            public void dataRead(IoSession session, ByteBuffer buf) {
166                result += "HDR ";
167            }
168 
169            public void dataWritten(IoSession session, Object marker) {
170                result += "HDW ";
171            }
172            
173            public void sessionIdle(IoSession session, IdleStatus status) {
174                result += "HSI ";
175            }
176 
177            public void exceptionCaught(IoSession session, Throwable cause) {
178                result += "HEC ";
179                if( cause.getClass() != Exception.class )
180                {
181                    cause.printStackTrace( System.out );
182                }
183            }
184 
185            public void sessionClosed(IoSession session) {
186                result += "HSC ";
187            }
188        };
189 
190        public IoHandler getHandler()
191        {
192            return handler;
193        }
194 
195        public void close( boolean wait )
196        {
197        }
198 
199        public void write(ByteBuffer buf, Object marker)
200        {
201        }
202 
203        public int getScheduledWriteRequests()
204        {
205            return 0;
206        }
207 
208        public TransportType getTransportType()
209        {
210            return null;
211        }
212 
213        public boolean isConnected()
214        {
215            return false;
216        }
217 
218        public SessionConfig getConfig()
219        {
220            return null;
221        }
222 
223        public SocketAddress getRemoteAddress()
224        {
225            return null;
226        }
227 
228        public SocketAddress getLocalAddress()
229        {
230            return null;
231        }
232 
233        public IoFilterChain getFilterChain()
234        {
235            return null;
236        }
237    }
238 
239    private class TestFilter implements IoFilter
240    {
241        private final char id;
242 
243        private TestFilter( char id )
244        {
245            this.id = id;
246        }
247        
248        public void sessionOpened(NextFilter nextFilter, IoSession session) {
249            result += id + "SO ";
250            nextFilter.sessionOpened( session );
251        }
252 
253        public void sessionClosed(NextFilter nextFilter, IoSession session) {
254            result += id + "SC ";
255            nextFilter.sessionClosed( session );
256        }
257 
258        public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) {
259            result += id + "SI ";
260            nextFilter.sessionIdle( session, status );
261        }
262 
263        public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) {
264            result += id + "EC ";
265            nextFilter.exceptionCaught( session, cause );
266        }
267 
268        public void dataRead(NextFilter nextFilter, IoSession session, ByteBuffer buf) {
269            result += id + "DR ";
270            nextFilter.dataRead( session, buf );
271        }
272 
273        public void dataWritten(NextFilter nextFilter, IoSession session, Object marker) {
274            result += id + "DW ";
275            nextFilter.dataWritten( session, marker );
276        }
277 
278        public void filterWrite(NextFilter nextFilter, IoSession session, ByteBuffer buf, Object marker) {
279            result += id + "FW ";
280            nextFilter.filterWrite( session, buf, marker );
281        }
282    }
283 
284    private static class IoFilterChainImpl extends AbstractIoFilterChain
285    {
286        protected IoFilterChainImpl()
287        {
288        }
289 
290        protected void doWrite(IoSession session, ByteBuffer buffer, Object marker)
291        {
292            dataWritten( session, marker );
293        }
294    }
295    
296}

[all classes][org.apache.mina.io]
EMMA 2.0.4217 (C) Vladimir Roubtsov