01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.captcha;
17:
18: import junit.framework.*;
19:
20: import org.acegisecurity.captcha.AlwaysTestAfterMaxRequestsCaptchaChannelProcessor;
21:
22: /**
23: * DOCUMENT ME!
24: *
25: * @author $author$
26: * @version $Revision: 1496 $
27: */
28: public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessorTests
29: extends TestCase {
30: //~ Instance fields ================================================================================================
31:
32: AlwaysTestAfterMaxRequestsCaptchaChannelProcessor alwaysTestAfterMaxRequestsCaptchaChannelProcessor;
33:
34: //~ Methods ========================================================================================================
35:
36: protected void setUp() throws Exception {
37: super .setUp();
38: alwaysTestAfterMaxRequestsCaptchaChannelProcessor = new AlwaysTestAfterMaxRequestsCaptchaChannelProcessor();
39: }
40:
41: public void testIsContextValidConcerningHumanity() throws Exception {
42: alwaysTestAfterMaxRequestsCaptchaChannelProcessor
43: .setThresold(1);
44:
45: CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
46: assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
47: .isContextValidConcerningHumanity(context));
48:
49: context.incrementHumanRestrictedRessoucesRequestsCount();
50:
51: alwaysTestAfterMaxRequestsCaptchaChannelProcessor
52: .setThresold(-1);
53: assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
54: .isContextValidConcerningHumanity(context));
55:
56: alwaysTestAfterMaxRequestsCaptchaChannelProcessor
57: .setThresold(3);
58: assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
59: .isContextValidConcerningHumanity(context));
60: context.incrementHumanRestrictedRessoucesRequestsCount();
61: assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
62: .isContextValidConcerningHumanity(context));
63: context.incrementHumanRestrictedRessoucesRequestsCount();
64: assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
65: .isContextValidConcerningHumanity(context));
66: }
67:
68: public void testNewContext() {
69: CaptchaSecurityContextImpl context = new CaptchaSecurityContextImpl();
70:
71: assertFalse(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
72: .isContextValidConcerningHumanity(context));
73: alwaysTestAfterMaxRequestsCaptchaChannelProcessor
74: .setThresold(1);
75: assertTrue(alwaysTestAfterMaxRequestsCaptchaChannelProcessor
76: .isContextValidConcerningHumanity(context));
77: }
78: }
|