1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.captcha;
17
18 import junit.framework.*;
19
20 import org.acegisecurity.captcha.TestOnceAfterMaxRequestsCaptchaChannelProcessor;
21
22
23 /***
24 * DOCUMENT ME!
25 *
26 * @author $author$
27 * @version $Revision: 1.2 $
28 */
29 public class TestOnceAfterMaxRequestsCaptchaChannelProcessorTests
30 extends TestCase {
31
32
33 TestOnceAfterMaxRequestsCaptchaChannelProcessor testOnceAfterMaxRequestsCaptchaChannelProcessor;
34
35
36
37 public void testIsContextValidConcerningHumanity()
38 throws Exception {
39 testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(1);
40
41 CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
42 assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor
43 .isContextValidConcerningHumanity(context));
44
45 context.incrementHumanRestrictedRessoucesRequestsCount();
46
47 testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(-1);
48 assertFalse(testOnceAfterMaxRequestsCaptchaChannelProcessor
49 .isContextValidConcerningHumanity(context));
50
51 testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(3);
52 assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor
53 .isContextValidConcerningHumanity(context));
54 context.incrementHumanRestrictedRessoucesRequestsCount();
55 assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor
56 .isContextValidConcerningHumanity(context));
57 context.incrementHumanRestrictedRessoucesRequestsCount();
58 assertFalse(testOnceAfterMaxRequestsCaptchaChannelProcessor
59 .isContextValidConcerningHumanity(context));
60 context.setHuman();
61
62 for (int i = 0;
63 i < (2 * testOnceAfterMaxRequestsCaptchaChannelProcessor
64 .getThresold()); i++) {
65 assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor
66 .isContextValidConcerningHumanity(context));
67 }
68 }
69
70 public void testNewContext() {
71 CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
72
73 assertFalse(testOnceAfterMaxRequestsCaptchaChannelProcessor
74 .isContextValidConcerningHumanity(context));
75 testOnceAfterMaxRequestsCaptchaChannelProcessor.setThresold(1);
76 assertTrue(testOnceAfterMaxRequestsCaptchaChannelProcessor
77 .isContextValidConcerningHumanity(context));
78 }
79
80 protected void setUp() throws Exception {
81 super.setUp();
82 testOnceAfterMaxRequestsCaptchaChannelProcessor = new TestOnceAfterMaxRequestsCaptchaChannelProcessor();
83 }
84 }