01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: PropUtilTest.java,v 1.18.2.3 2008/01/07 15:14:34 cwl Exp $
07: */
08:
09: package com.sleepycat.je.util;
10:
11: import java.util.HashSet;
12: import java.util.Properties;
13: import java.util.Set;
14:
15: import junit.framework.TestCase;
16:
17: import com.sleepycat.je.DatabaseException;
18: import com.sleepycat.je.utilint.PropUtil;
19:
20: public class PropUtilTest extends TestCase {
21: public void testGetBoolean() {
22: Properties props = new Properties();
23:
24: props.setProperty("foo", "true");
25: props.setProperty("bar", "True");
26: props.setProperty("baz", "false");
27:
28: assertTrue(PropUtil.getBoolean(props, "foo"));
29: assertTrue(PropUtil.getBoolean(props, "bar"));
30: assertFalse(PropUtil.getBoolean(props, "baz"));
31: }
32:
33: public void testValidate() throws DatabaseException {
34:
35: Properties props = new Properties();
36:
37: props.setProperty("foo", "true");
38: props.setProperty("bar", "True");
39: props.setProperty("baz", "false");
40:
41: Set allowedSet = new HashSet();
42: allowedSet.add("foo");
43: allowedSet.add("bar");
44: allowedSet.add("baz");
45:
46: PropUtil.validateProps(props, allowedSet, "test");
47:
48: // test negative case
49: allowedSet.remove("foo");
50:
51: try {
52: PropUtil.validateProps(props, allowedSet, "test");
53: fail();
54: } catch (DatabaseException e) {
55: //System.out.println(e);
56: assertEquals(DatabaseException.getVersionHeader()
57: + "foo is not a valid property for test", e
58: .getMessage());
59: }
60: }
61:
62: public void testMicrosToMillis() {
63:
64: assertEquals(0, PropUtil.microsToMillis(0));
65: assertEquals(1, PropUtil.microsToMillis(1));
66: assertEquals(1, PropUtil.microsToMillis(999));
67: assertEquals(1, PropUtil.microsToMillis(1000));
68: assertEquals(2, PropUtil.microsToMillis(1001));
69: }
70: }
|