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