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 junit.framework.TestCase;
15  
16  import java.util.HashMap;
17  import java.util.Locale;
18  
19  /***
20   * Unit test the ContainerConfiguration
21   *
22   * @author Benoit Doumas
23   */
24  public class ContainerConfigurationTest extends TestCase {
25      ContainerConfiguration config = null;
26  
27      HashMap localRatio = null;
28  
29      int maxMemSize = 10;
30  
31      int maxPersistentSize = 100;
32  
33      int swapSize = 10;
34  
35      int feedSize = 100;
36  
37      /*
38       * @see TestCase#setUp()
39       */
40      protected void setUp() throws Exception {
41          super.setUp();
42          localRatio = new HashMap(2);
43  
44          localRatio.put(Locale.FRANCE, new Double(0.2));
45          localRatio.put(Locale.US, new Double(0.8));
46          config = new ContainerConfiguration(localRatio, 0, 0, 10, 40);
47      }
48  
49      public void testSetFeedSize() {
50          config.setFeedSize(new Integer(feedSize));
51  
52          assertEquals(feedSize, config.getFeedSize().intValue());
53      }
54  
55      public void testSetLocaleRatio() {
56          HashMap localRatio2 = new HashMap(3);
57          localRatio2.put(Locale.GERMAN, new Double(0.1));
58          localRatio2.put(Locale.CHINA, new Double(0.8));
59          localRatio2.put(Locale.ITALY, new Double(0.1));
60  
61          config.setLocaleRatio(localRatio2);
62  
63          assertEquals(3, config.getLocaleRatio().size());
64      }
65  
66      public void testServeOnlyConfiguredLocales() {
67          HashMap localRatio2 = new HashMap(3);
68          localRatio2.put(Locale.GERMAN, new Double(0.1));
69          localRatio2.put(Locale.CHINA, new Double(0.8));
70          localRatio2.put(Locale.ITALY, new Double(0.1));
71  
72          try {
73              config = new ContainerConfiguration(localRatio2, 0, 0, 10, 40, true, Locale.getDefault());
74              fail("should have thown an exception concerning the default locale");
75          } catch (Exception e) {
76  
77          }
78  
79          config = new ContainerConfiguration(localRatio2, 0, 0, 10, 40, false, Locale.KOREAN);
80          try {
81              config.setServeOnlyConfiguredLocales(true);
82              fail("should have thown an exception concerning the default locale");
83          } catch (Exception e) {
84  
85          }
86          config = new ContainerConfiguration(localRatio2, 0, 0, 10, 40, true, Locale.GERMAN);
87          config = new ContainerConfiguration(localRatio2, 0, 0, 10, 40);
88          config.setDefaultLocale(Locale.GERMAN);
89          config.setServeOnlyConfiguredLocales(true);
90  
91          try {
92              config.setDefaultLocale(Locale.JAPAN);
93              fail("should have thown an exception concerning the default locale");
94          } catch (Exception e) {
95  
96          }
97  
98  
99      }
100 
101     public void testSetMaxPersistentMemorySize() {
102         config.setMaxPersistentMemorySize(new Integer(maxPersistentSize));
103 
104         assertEquals(maxPersistentSize, config.getMaxPersistentMemorySize().intValue());
105     }
106 
107     public void testSetMaxVolatileMemorySize() {
108         config.setMaxVolatileMemorySize(new Integer(maxMemSize));
109 
110         assertEquals(maxMemSize, config.getMaxVolatileMemorySize().intValue());
111     }
112 
113     public void testSetSwapSize() {
114         config.setSwapSize(new Integer(swapSize));
115 
116         assertEquals(swapSize, config.getSwapSize().intValue());
117     }
118 
119 }