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.AlwaysTestAfterMaxRequestsCaptchaChannelProcessor;
21
22
23 /***
24 * DOCUMENT ME!
25 *
26 * @author $author$
27 * @version $Revision: 1.2 $
28 */
29 public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessorTests
30 extends TestCase {
31
32
33 AlwaysTestAfterMaxRequestsCaptchaChannelProcessor alwaysTestAfterMaxRequestsCaptchaChannelProcessor;
34
35
36
37 public void testIsContextValidConcerningHumanity()
38 throws Exception {
39 alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(1);
40
41 CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
42 assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
43 .isContextValidConcerningHumanity(context));
44
45 context.incrementHumanRestrictedRessoucesRequestsCount();
46
47 alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(-1);
48 assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
49 .isContextValidConcerningHumanity(context));
50
51 alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(3);
52 assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
53 .isContextValidConcerningHumanity(context));
54 context.incrementHumanRestrictedRessoucesRequestsCount();
55 assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
56 .isContextValidConcerningHumanity(context));
57 context.incrementHumanRestrictedRessoucesRequestsCount();
58 assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
59 .isContextValidConcerningHumanity(context));
60 }
61
62 public void testNewContext() {
63 CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
64
65 assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
66 .isContextValidConcerningHumanity(context));
67 alwaysTestAfterMaxRequestsCaptchaChannelProcessor.setThresold(1);
68 assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
69 .isContextValidConcerningHumanity(context));
70 }
71
72 protected void setUp() throws Exception {
73 super.setUp();
74 alwaysTestAfterMaxRequestsCaptchaChannelProcessor = new AlwaysTestAfterMaxRequestsCaptchaChannelProcessor();
75 }
76 }