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