1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.mina.filter.firewall;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25
26 import java.net.InetSocketAddress;
27
28 import org.apache.mina.core.session.DummySession;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32
33
34
35
36
37
38
39 public class ConnectionThrottleFilterTest
40 {
41 private ConnectionThrottleFilter filter;
42
43 private DummySession sessionOne;
44 private DummySession sessionTwo;
45
46 @Before
47 public void setUp() throws Exception
48 {
49 filter = new ConnectionThrottleFilter();
50
51 sessionOne = new DummySession();
52 sessionOne.setRemoteAddress( new InetSocketAddress(1234) );
53 sessionTwo = new DummySession();
54 sessionTwo.setRemoteAddress( new InetSocketAddress(1235) );
55 }
56
57 @After
58 public void tearDown() throws Exception
59 {
60 filter = null;
61 }
62
63 @Test
64 public void testGoodConnection(){
65 filter.setAllowedInterval( 100 );
66 filter.isConnectionOk( sessionOne );
67
68 try
69 {
70 Thread.sleep( 1000 );
71 }
72 catch ( InterruptedException e )
73 {
74
75 }
76
77 boolean result = filter.isConnectionOk( sessionOne );
78 assertTrue( result );
79 }
80
81 @Test
82 public void testBadConnection(){
83 filter.setAllowedInterval( 1000 );
84 filter.isConnectionOk( sessionTwo );
85 assertFalse(filter.isConnectionOk( sessionTwo ));
86 }
87 }