KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > EnvironmentConfigTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: EnvironmentConfigTest.java,v 1.10 2006/10/30 21:14:41 bostic Exp $
7  */

8
9 package com.sleepycat.je;
10
11 import java.io.File JavaDoc;
12 import java.util.Properties JavaDoc;
13
14 import junit.framework.TestCase;
15
16 import com.sleepycat.je.Environment;
17 import com.sleepycat.je.config.EnvironmentParams;
18 import com.sleepycat.je.util.TestUtils;
19
20 public class EnvironmentConfigTest extends TestCase {
21
22     /**
23      * Try out the validation in EnvironmentConfig.
24      */

25     public void testValidation()
26     throws DatabaseException {
27
28         /*
29          * This validation should be successfull
30          */

31         Properties JavaDoc props = new Properties JavaDoc();
32         props.setProperty("java.util.logging.FileHandler.limit", "2000");
33         props.setProperty("java.util.logging.FileHandler.on", "false");
34         new EnvironmentConfig(props); // Just instantiate a config object.
35

36         /*
37          * Should fail: we should throw because leftover.param is not
38          * a valid parameter.
39          */

40         props.clear();
41         props.setProperty("leftover.param", "foo");
42         checkEnvironmentConfigValidation(props);
43                                            
44         /*
45          * Should fail: we should throw because FileHandlerLimit
46          * is less than its minimum
47          */

48         props.clear();
49         props.setProperty("java.util.logging.FileHandler.limit", "1");
50         checkEnvironmentConfigValidation(props);
51
52         /*
53          * Should fail: we should throw because FileHandler.on is not
54          * a valid value.
55          */

56         props.clear();
57         props.setProperty("java.util.logging.FileHandler.on", "xxx");
58         checkEnvironmentConfigValidation(props);
59     }
60
61     /**
62      * Test single parameter setting.
63      */

64     public void testSingleParam()
65         throws Exception JavaDoc {
66
67         try {
68             EnvironmentConfig config = new EnvironmentConfig();
69             config.setConfigParam("foo", "7");
70             fail("Should fail because of invalid param name");
71         } catch (IllegalArgumentException JavaDoc e) {
72             // expected.
73
}
74
75         EnvironmentConfig config = new EnvironmentConfig();
76         config.setConfigParam(EnvironmentParams.MAX_MEMORY_PERCENT.getName(),
77                               "81");
78         assertEquals(81, config.getCachePercent());
79     }
80
81     public void testInconsistentParams()
82     throws Exception JavaDoc {
83
84     try {
85             EnvironmentConfig config = new EnvironmentConfig();
86         config.setAllowCreate(true);
87         config.setLocking(false);
88         config.setTransactional(true);
89         File JavaDoc envHome = new File JavaDoc(System.getProperty(TestUtils.DEST_DIR));
90         Environment env = new Environment(envHome, config);
91             fail("Should fail because of inconsistent param values");
92         } catch (IllegalArgumentException JavaDoc e) {
93             // expected.
94
}
95     }
96
97     /* Helper to catch expected exceptions. */
98     private void checkEnvironmentConfigValidation(Properties JavaDoc props) {
99         try {
100             new EnvironmentConfig(props);
101             fail("Should fail because of a parameter validation problem");
102         } catch (IllegalArgumentException JavaDoc e) {
103             // expected.
104
}
105     }
106 }
107
108
Popular Tags