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

COVERAGE SUMMARY FOR SOURCE FILE [ProtocolFilterChainTest.java]

nameclass, %method, %block, %line, %
ProtocolFilterChainTest.java83%  (5/6)72%  (29/40)97%  (635/658)90%  (112/124)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProtocolFilterChainTest$TestSession$1100% (1/1)100% (7/7)95%  (59/62)93%  (14/15)
exceptionCaught (ProtocolSession, Throwable): void 100% (1/1)86%  (18/21)75%  (3/4)
ProtocolFilterChainTest$TestSession$1 (ProtocolFilterChainTest$TestSession): ... 100% (1/1)100% (6/6)100% (1/1)
messageReceived (ProtocolSession, Object): void 100% (1/1)100% (7/7)100% (2/2)
messageSent (ProtocolSession, Object): void 100% (1/1)100% (7/7)100% (2/2)
sessionClosed (ProtocolSession): void 100% (1/1)100% (7/7)100% (2/2)
sessionIdle (ProtocolSession, IdleStatus): void 100% (1/1)100% (7/7)100% (2/2)
sessionOpened (ProtocolSession): void 100% (1/1)100% (7/7)100% (2/2)
     
class ProtocolFilterChainTest100% (1/1)100% (10/10)100% (420/420)100% (67/67)
ProtocolFilterChainTest (): 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% (76/76)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 ProtocolFilterChainTest$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class ProtocolFilterChainTest$TestSession100% (1/1)15%  (2/13)43%  (15/35)21%  (3/14)
close (boolean): void 0%   (0/1)0%   (0/1)0%   (0/1)
getConfig (): SessionConfig 0%   (0/1)0%   (0/2)0%   (0/1)
getDecoder (): ProtocolDecoder 0%   (0/1)0%   (0/2)0%   (0/1)
getEncoder (): ProtocolEncoder 0%   (0/1)0%   (0/2)0%   (0/1)
getFilterChain (): ProtocolFilterChain 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 (Object): void 0%   (0/1)0%   (0/1)0%   (0/1)
ProtocolFilterChainTest$TestSession (ProtocolFilterChainTest): void 100% (1/1)100% (12/12)100% (2/2)
getHandler (): ProtocolHandler 100% (1/1)100% (3/3)100% (1/1)
     
class ProtocolFilterChainTest$ProtocolFilterChainImpl100% (1/1)100% (2/2)100% (8/8)100% (4/4)
ProtocolFilterChainTest$ProtocolFilterChainImpl (): void 100% (1/1)100% (3/3)100% (2/2)
doWrite (ProtocolSession, Object): void 100% (1/1)100% (5/5)100% (2/2)
     
class ProtocolFilterChainTest$TestFilter100% (1/1)100% (8/8)100% (133/133)100% (24/24)
ProtocolFilterChainTest$TestFilter (ProtocolFilterChainTest, char): void 100% (1/1)100% (9/9)100% (3/3)
exceptionCaught (ProtocolFilter$NextFilter, ProtocolSession, Throwable): void 100% (1/1)100% (18/18)100% (3/3)
filterWrite (ProtocolFilter$NextFilter, ProtocolSession, Object): void 100% (1/1)100% (18/18)100% (3/3)
messageReceived (ProtocolFilter$NextFilter, ProtocolSession, Object): void 100% (1/1)100% (18/18)100% (3/3)
messageSent (ProtocolFilter$NextFilter, ProtocolSession, Object): void 100% (1/1)100% (18/18)100% (3/3)
sessionClosed (ProtocolFilter$NextFilter, ProtocolSession): void 100% (1/1)100% (17/17)100% (3/3)
sessionIdle (ProtocolFilter$NextFilter, ProtocolSession, IdleStatus): void 100% (1/1)100% (18/18)100% (3/3)
sessionOpened (ProtocolFilter$NextFilter, ProtocolSession): void 100% (1/1)100% (17/17)100% (3/3)

1/*
2 *   @(#) $Id: ProtocolFilterChainTest.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.protocol;
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.IdleStatus;
29import org.apache.mina.common.SessionConfig;
30import org.apache.mina.common.TransportType;
31 
32/**
33 * Tests {@link AbstractProtocolFilterChain}.
34 * 
35 * @author The Apache Directory Project (dev@directory.apache.org)
36 * @version $Rev: 357871 $, $Date: 2005-12-20 10:56:40 +0900 (Tue, 20 Dec 2005) $ 
37 */
38public class ProtocolFilterChainTest extends TestCase
39{
40    private ProtocolFilterChainImpl chain;
41    private ProtocolSession session;
42    private String result;
43 
44    public void setUp()
45    {
46        chain = new ProtocolFilterChainImpl();
47        session = new TestSession();
48        result = "";
49    }
50    
51    public void tearDown()
52    {
53    }
54    
55    public void testAdd() throws Exception
56    {
57        chain.addFirst( "A", new TestFilter( 'A' ) );
58        chain.addLast( "B", new TestFilter( 'B' ) );
59        chain.addFirst( "C", new TestFilter( 'C' ) );
60        chain.addLast( "D", new TestFilter( 'D' ) );
61        chain.addBefore( "B", "E", new TestFilter( 'E' ) );
62        chain.addBefore( "C", "F", new TestFilter( 'F' ) );
63        chain.addAfter( "B", "G", new TestFilter( 'G' ) );
64        chain.addAfter( "D", "H", new TestFilter( 'H' ) );
65        
66        String actual = "";
67        for( Iterator i = chain.getChildren().iterator(); i.hasNext(); ) 
68        {
69            TestFilter f = ( TestFilter ) i.next();
70            actual += f.id;
71        }
72        
73        Assert.assertEquals( "FCAEBGDH", actual );
74    }
75    
76    public void testRemove() throws Exception
77    {
78        chain.addLast( "A", new TestFilter( 'A' ) );
79        chain.addLast( "B", new TestFilter( 'B' ) );
80        chain.addLast( "C", new TestFilter( 'C' ) );
81        chain.addLast( "D", new TestFilter( 'D' ) );
82        chain.addLast( "E", new TestFilter( 'E' ) );
83        
84        chain.remove( "A" );
85        chain.remove( "E" );
86        chain.remove( "C" );
87        chain.remove( "B" );
88        chain.remove( "D" );
89        
90        Assert.assertEquals( 0, chain.getChildren().size() );
91    }
92    
93    public void testClear() throws Exception
94    {
95        chain.addLast( "A", new TestFilter( 'A' ) );
96        chain.addLast( "B", new TestFilter( 'B' ) );
97        chain.addLast( "C", new TestFilter( 'C' ) );
98        chain.addLast( "D", new TestFilter( 'D' ) );
99        chain.addLast( "E", new TestFilter( 'E' ) );
100        
101        chain.clear();
102        
103        Assert.assertEquals( 0, chain.getChildren().size() );
104    }
105    
106    public void testDefault()
107    {
108        run( "HSO HMR HMS HSI HEC HSC" );
109    }
110    
111    public void testChained()
112    {
113        chain.addLast( "A", new TestFilter( 'A' ) );
114        chain.addLast( "B", new TestFilter( 'B' ) );
115        run( "ASO BSO HSO" +
116             "AMR BMR HMR" +
117             "BFW AFW AMS BMS HMS" +
118             "ASI BSI HSI" +
119             "AEC BEC HEC" +
120             "ASC BSC HSC" );
121    }
122    
123    private void run( String expectedResult )
124    {
125        chain.sessionOpened( session );
126        chain.messageReceived( session, new Object() );
127        chain.filterWrite( session, new Object() );
128        chain.sessionIdle( session, IdleStatus.READER_IDLE );
129        chain.exceptionCaught( session, new Exception() );
130        chain.sessionClosed( session );
131        
132        result = formatResult( result );
133        expectedResult = formatResult( expectedResult );
134        
135        System.out.println( "Expected: " + expectedResult );
136        System.out.println( "Actual:   " + result );
137        Assert.assertEquals( expectedResult, result );
138    }
139    
140    private String formatResult( String result )
141    {
142        result = result.replaceAll( "\\s", "" );
143        StringBuffer buf = new StringBuffer( result.length() * 4 / 3 );
144        for( int i = 0; i < result.length(); i++ )
145        {
146            buf.append( result.charAt( i ) );
147            if( i % 3 == 2 )
148            {
149                buf.append(' ');
150            }
151        }
152        
153        return buf.toString();
154    }
155 
156    private class TestSession extends BaseSession implements ProtocolSession
157    {
158        private ProtocolHandler handler = new ProtocolHandlerAdapter()
159        {
160            public void sessionOpened(ProtocolSession session) {
161                result += "HSO";
162            }
163 
164            public void sessionClosed(ProtocolSession session) {
165                result += "HSC";
166            }
167 
168            public void sessionIdle(ProtocolSession session, IdleStatus status) {
169                result += "HSI";
170            }
171 
172            public void exceptionCaught(ProtocolSession session, Throwable cause) {
173                result += "HEC";
174                if( cause.getClass() != Exception.class )
175                {
176                    cause.printStackTrace( System.out );
177                }
178            }
179 
180            public void messageReceived(ProtocolSession session, Object message) {
181                result += "HMR";
182            }
183 
184            public void messageSent(ProtocolSession session, Object message) {
185                result += "HMS";
186            }
187        };
188 
189        public ProtocolHandler getHandler() {
190            return handler;
191        }
192 
193        public ProtocolEncoder getEncoder() {
194            return null;
195        }
196 
197        public ProtocolDecoder getDecoder() {
198            return null;
199        }
200 
201        public void close( boolean wait ) {
202        }
203 
204        public void write(Object message) {
205        }
206 
207        public int getScheduledWriteRequests()
208        {
209            return 0;
210        }
211 
212        public TransportType getTransportType() {
213            return null;
214        }
215 
216        public boolean isConnected() {
217            return false;
218        }
219 
220        public SessionConfig getConfig() {
221            return null;
222        }
223 
224        public SocketAddress getRemoteAddress() {
225            return null;
226        }
227 
228        public SocketAddress getLocalAddress() {
229            return null;
230        }
231 
232        public ProtocolFilterChain getFilterChain()
233        {
234            return null;
235        }
236    }
237 
238    private class TestFilter implements ProtocolFilter
239    {
240        private final char id;
241 
242        private TestFilter( char id )
243        {
244            this.id = id;
245        }
246        
247        public void sessionOpened(NextFilter nextFilter, ProtocolSession session) {
248            result += id + "SO";
249            nextFilter.sessionOpened( session );
250        }
251 
252        public void sessionClosed(NextFilter nextFilter, ProtocolSession session) {
253            result += id + "SC";
254            nextFilter.sessionClosed( session );
255        }
256 
257        public void sessionIdle(NextFilter nextFilter, ProtocolSession session, IdleStatus status) {
258            result += id + "SI";
259            nextFilter.sessionIdle( session, status );
260        }
261 
262        public void exceptionCaught(NextFilter nextFilter, ProtocolSession session, Throwable cause) {
263            result += id + "EC";
264            nextFilter.exceptionCaught( session, cause );
265        }
266 
267        public void filterWrite(NextFilter nextFilter, ProtocolSession session, Object message) {
268            result += id + "FW";
269            nextFilter.filterWrite( session, message );
270        }
271 
272        public void messageReceived(NextFilter nextFilter, org.apache.mina.protocol.ProtocolSession session, Object message) {
273            result += id + "MR";
274            nextFilter.messageReceived( session, message );
275        }
276 
277        public void messageSent(NextFilter nextFilter, org.apache.mina.protocol.ProtocolSession session, Object message) {
278            result += id + "MS";
279            nextFilter.messageSent( session, message );
280        }
281    }
282 
283    private static class ProtocolFilterChainImpl extends AbstractProtocolFilterChain
284    {
285        protected ProtocolFilterChainImpl()
286        {
287        }
288 
289        protected void doWrite( ProtocolSession session, Object message )
290        {
291            messageSent( session, message );
292        }
293    }
294    
295}

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