    1   /* Copyright 2004, 2005 Acegi Technology Pty Limited
    2    *
    3    * Licensed under the Apache License, Version 2.0 (the "License");
    4    * you may not use this file except in compliance with the License.
    5    * You may obtain a copy of the License at
    6    *
    7    *     http://www.apache.org/licenses/LICENSE-2.0
    8    *
    9    * 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  /***
    24   * DOCUMENT ME!
    25   *
    26   * @author $author$
    27   * @version $Revision: 1.2 $
    28   */
    29  public class AlwaysTestAfterMaxRequestsCaptchaChannelProcessorTests
    30      extends TestCase {
    31      //~ Instance fields ========================================================
    32
    33      AlwaysTestAfterMaxRequestsCaptchaChannelProcessor alwaysTestAfterMaxRequestsCaptchaChannelProcessor;
    34
    35      //~ Methods ================================================================
    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  }