View Javadoc

1   /*
2    * JCaptcha, the open source java framework for captcha definition and integration
3    * Copyright (c)  2007 jcaptcha.net. All Rights Reserved.
4    * See the LICENSE.txt file distributed with this package.
5    */
6   
7   /*
8    * jcaptcha, the open source java framework for captcha definition and integration
9    * copyright (c)  2007 jcaptcha.net. All Rights Reserved.
10   * See the LICENSE.txt file distributed with this package.
11   */
12  package com.octo.captcha.engine.bufferedengine;
13  
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  import org.springframework.beans.factory.config.ConfigurableBeanFactory;
17  import org.springframework.beans.factory.xml.XmlBeanFactory;
18  import org.springframework.core.io.ClassPathResource;
19  import org.springframework.core.io.Resource;
20  
21  /***
22   * @author Doumas Benoit
23   */
24  public class QuartzBufferedEngineContainerTest extends BufferedEngineContainerTestAbstract {
25      private static final Log log = LogFactory.getLog(QuartzBufferedEngineContainerTest.class
26              .getName());
27  
28      // loader init by default
29      //protected Class loader = DefaultEngineLoadTestHelper.class;
30  
31      public void testBasic() throws Exception {
32          Resource ressource = new ClassPathResource("testQuartzBufferedEngine.xml");
33          ConfigurableBeanFactory bf = new XmlBeanFactory(ressource);
34          BufferedEngineContainer container = (BufferedEngineContainer) bf.getBean("container");
35          Object scheduler = bf.getBean("quartz");
36          Thread.sleep(10000);
37          for (int i = 0; i < 100; i++) {
38              assertNotNull(container.getNextCaptcha());
39          }
40      }
41  
42      public void testMockFillingDisk() throws Exception {
43          Resource ressource = new ClassPathResource("testFillDiskMockQuartzBufferedEngine.xml");
44          ConfigurableBeanFactory bf = new XmlBeanFactory(ressource);
45          BufferedEngineContainer container = (BufferedEngineContainer) bf.getBean("container");
46          Object scheduler = bf.getBean("quartz");
47          Thread.sleep(100000);
48      }
49  
50      /***
51       * The buffer is never feed during the test (every 24h ...) the swap is every 3 second
52       */
53      public void testNoBufferdedCaptcha() throws Exception {
54          Resource ressource = new ClassPathResource("testNoBufferedCaptchaQuartzBufferedEngine.xml");
55          ConfigurableBeanFactory bf = new XmlBeanFactory(ressource);
56          BufferedEngineContainer container = (BufferedEngineContainer) bf.getBean("container");
57          Object scheduler = bf.getBean("quartz");
58          Thread.sleep(10000);
59          for (int i = 0; i < 100; i++) {
60              assertNotNull(container.getNextCaptcha());
61          }
62      }
63  
64      /***
65       * @see com.octo.captcha.engine.bufferedengine.BufferedEngineContainerTestAbstract#getEngine()
66       */
67      public BufferedEngineContainer getEngine() {
68          Resource ressource = new ClassPathResource("testQuartzBufferedEngine.xml");
69          ConfigurableBeanFactory bf = new XmlBeanFactory(ressource);
70          BufferedEngineContainer container = (BufferedEngineContainer) bf.getBean("container");
71          Object scheduler = bf.getBean("quartz");
72          return container;
73      }
74  
75      /***
76       * @see com.octo.captcha.engine.bufferedengine.BufferedEngineContainerTestAbstract#releaseEngine()
77       */
78      public void releaseEngine(BufferedEngineContainer engine) {
79  
80      }
81  
82  }