mirror of https://github.com/apache/openjpa.git
move openjpa-lib tests to junit4 style
No more junit3 extends TestCase stuff ^^
This commit is contained in:
parent
12ec80cd8c
commit
08bb3a5a0e
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.apache.openjpa.meta;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
|
@ -24,18 +24,22 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
public class TestConfigurationProviderPrefixes
|
||||
extends TestCase {
|
||||
public class TestConfigurationProviderPrefixes {
|
||||
|
||||
private static final String CUSTOM_PREFIX =
|
||||
TestConfigurationProviderPrefixes.class.getName();
|
||||
|
||||
private String[] _origPrefixes;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
_origPrefixes = ProductDerivations.getConfigurationPrefixes();
|
||||
List l = new ArrayList(Arrays.asList(_origPrefixes));
|
||||
|
@ -44,45 +48,52 @@ public class TestConfigurationProviderPrefixes
|
|||
(String[]) l.toArray(new String[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() {
|
||||
ProductDerivations.setConfigurationPrefixes(_origPrefixes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixContents() {
|
||||
String[] prefixes = ProductDerivations.getConfigurationPrefixes();
|
||||
assertEquals(CUSTOM_PREFIX, prefixes[prefixes.length - 1]);
|
||||
assertEquals("openjpa", prefixes[0]);
|
||||
Assert.assertEquals(CUSTOM_PREFIX, prefixes[prefixes.length - 1]);
|
||||
Assert.assertEquals("openjpa", prefixes[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialKeyAndNullMap() {
|
||||
assertEquals("openjpa.Foo", "Foo", (Map) null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialKeyWithInvalidPrefix() {
|
||||
Map map = new HashMap();
|
||||
map.put("bar.Foo", "value");
|
||||
assertEquals("openjpa.Foo", "Foo", map, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialKeyWithoutMatch() {
|
||||
Map map = new HashMap();
|
||||
map.put("bar.Baz", "value");
|
||||
assertEquals("openjpa.Foo", "Foo", map, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialKeyWithOpenJPAMatch() {
|
||||
Map map = new HashMap();
|
||||
map.put("openjpa.Foo", "value");
|
||||
assertEquals("openjpa.Foo", "Foo", map, "value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialKeyWithCustomMatch() {
|
||||
Map map = new HashMap();
|
||||
map.put(CUSTOM_PREFIX + ".Foo", "value");
|
||||
assertEquals(CUSTOM_PREFIX + ".Foo", "Foo", map, "value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialKeyDuplicateFullKeys() {
|
||||
Map map = new HashMap();
|
||||
map.put(CUSTOM_PREFIX + ".Foo", "value");
|
||||
|
@ -97,9 +108,9 @@ public class TestConfigurationProviderPrefixes
|
|||
|
||||
private static void assertEquals(String fullKey, String partialKey,
|
||||
Map map, Object value) {
|
||||
assertEquals(fullKey, ProductDerivations.getConfigurationKey(
|
||||
Assert.assertEquals(fullKey, ProductDerivations.getConfigurationKey(
|
||||
partialKey, map));
|
||||
if (map != null)
|
||||
assertEquals(value, map.get(fullKey));
|
||||
Assert.assertEquals(value, map.get(fullKey));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@ import java.util.Map;
|
|||
|
||||
import org.apache.openjpa.lib.test.AbstractTestCase;
|
||||
import org.apache.openjpa.lib.util.Options;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the {@link Configurations} class.
|
||||
|
@ -31,10 +35,7 @@ import org.apache.openjpa.lib.util.Options;
|
|||
*/
|
||||
public class TestConfigurations extends AbstractTestCase {
|
||||
|
||||
public TestConfigurations(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsePlugin() {
|
||||
String str = null;
|
||||
assertNull(Configurations.getClassName(str));
|
||||
|
@ -59,6 +60,7 @@ public class TestConfigurations extends AbstractTestCase {
|
|||
assertEquals("a='b,c d', c='d'", Configurations.getProperties(str));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseProperties() {
|
||||
Options opts = Configurations.parseProperties(null);
|
||||
assertEquals(0, opts.size());
|
||||
|
@ -86,6 +88,7 @@ public class TestConfigurations extends AbstractTestCase {
|
|||
assertEquals("baz baz", opts.getProperty("biz"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCombinePlugins() {
|
||||
assertPluginsCombined("jpa", null,
|
||||
null, null,
|
||||
|
@ -142,7 +145,4 @@ public class TestConfigurations extends AbstractTestCase {
|
|||
return map;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main(TestConfigurations.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
*/
|
||||
package org.apache.openjpa.lib.conf;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestValue extends TestCase {
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestValue {
|
||||
|
||||
private static class SimpleValue extends Value {
|
||||
|
||||
|
@ -50,6 +52,7 @@ public class TestValue extends TestCase {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAliasesByValue() {
|
||||
String alias = "alias";
|
||||
String aName = "Johnny";
|
||||
|
@ -64,6 +67,7 @@ public class TestValue extends TestCase {
|
|||
assertEquals("Array of aliases not set by value", aName, aStrings[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquivalentValueCanBeSet() {
|
||||
SimpleValue v = new SimpleValue();
|
||||
v.setProperty("main");
|
||||
|
@ -79,6 +83,7 @@ public class TestValue extends TestCase {
|
|||
assertFalse(v.matches("eqivalent3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquivalentValuesAreUnmodifable() {
|
||||
SimpleValue v = new SimpleValue();
|
||||
v.setProperty("main");
|
||||
|
|
|
@ -23,11 +23,14 @@ import java.io.File;
|
|||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class TestXMLCaseConversions extends TestCase {
|
||||
public class TestXMLCaseConversions {
|
||||
|
||||
@Test
|
||||
public void testToXMLName() {
|
||||
assertEquals("easy-xml-conversion",
|
||||
ConfigurationImpl.toXMLName("easyXmlConversion"));
|
||||
|
|
|
@ -32,6 +32,13 @@ import org.apache.openjpa.lib.conf.StringValue;
|
|||
import org.apache.openjpa.lib.conf.Value;
|
||||
import org.apache.openjpa.lib.test.AbstractTestCase;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the {@link ConfigurationImpl} type. This needs to be placed
|
||||
* in a sub-package so that it can have its own localizer.properties
|
||||
|
@ -49,24 +56,20 @@ public class TestConfigurationImpl extends AbstractTestCase {
|
|||
|
||||
private ConfigurationTest _conf = new ConfigurationTest();
|
||||
|
||||
public TestConfigurationImpl(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
System.setProperty("openjpatest.properties", "test.properties");
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.setProperty("openjpatest.properties", "");
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that global properties are found and loaded.
|
||||
*/
|
||||
@Test
|
||||
public void testGlobals() {
|
||||
System.setProperty("openjpa.sysKey", "sysvalue");
|
||||
assertNull(_conf.getTestKey());
|
||||
|
@ -103,6 +106,7 @@ public class TestConfigurationImpl extends AbstractTestCase {
|
|||
/**
|
||||
* Test that the configuration is serialized to properties correctly.
|
||||
*/
|
||||
@Test
|
||||
public void testToProperties() {
|
||||
assertTrue(_conf.loadGlobals());
|
||||
assertEquals("testvalue", _conf.getTestKey());
|
||||
|
@ -121,6 +125,7 @@ public class TestConfigurationImpl extends AbstractTestCase {
|
|||
/**
|
||||
* Tests properties caching.
|
||||
*/
|
||||
@Test
|
||||
public void testPropertiesCaching() {
|
||||
_conf.setTestKey("val");
|
||||
_conf.setPluginKey("java.lang.Object");
|
||||
|
@ -142,6 +147,7 @@ public class TestConfigurationImpl extends AbstractTestCase {
|
|||
/**
|
||||
* Test the equals method.
|
||||
*/
|
||||
@Test
|
||||
public void testEquals() {
|
||||
ConfigurationTest conf = new ConfigurationTest();
|
||||
conf.setTestKey(_conf.getTestKey());
|
||||
|
@ -165,6 +171,7 @@ public class TestConfigurationImpl extends AbstractTestCase {
|
|||
/**
|
||||
* Test using bean introspection.
|
||||
*/
|
||||
@Test
|
||||
public void testBeanAccessors() throws Exception {
|
||||
PropertyDescriptor[] pds = _conf.getPropertyDescriptors();
|
||||
for (int i = 0; i < pds.length; i++) {
|
||||
|
@ -201,6 +208,7 @@ public class TestConfigurationImpl extends AbstractTestCase {
|
|||
/**
|
||||
* Test freezing.
|
||||
*/
|
||||
@Test
|
||||
public void testFreezing() {
|
||||
assertTrue(!_conf.isReadOnly());
|
||||
_conf.setReadOnly(Configuration.INIT_STATE_FROZEN);
|
||||
|
@ -222,6 +230,7 @@ public class TestConfigurationImpl extends AbstractTestCase {
|
|||
/**
|
||||
* Test serialization.
|
||||
*/
|
||||
@Test
|
||||
public void testSerialization() throws Exception {
|
||||
assertTrue(_conf.loadGlobals());
|
||||
_conf.setTestKey("testvalue");
|
||||
|
@ -248,6 +257,7 @@ public class TestConfigurationImpl extends AbstractTestCase {
|
|||
assertEquals("", copy2.getPluginKeyInstance().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProductDerivationCloseCallback() {
|
||||
// toggle the static. This will be reset by the close invocation.
|
||||
ConfigurationTestProductDerivation.closed = false;
|
||||
|
@ -255,10 +265,6 @@ public class TestConfigurationImpl extends AbstractTestCase {
|
|||
assertTrue(ConfigurationTestProductDerivation.closed);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
|
||||
private static class ConfigurationTest extends ConfigurationImpl {
|
||||
|
||||
private final StringValue _testKey;
|
||||
|
|
|
@ -23,6 +23,9 @@ import org.apache.openjpa.lib.conf.PluginValue;
|
|||
import org.apache.openjpa.lib.conf.StringValue;
|
||||
import org.apache.openjpa.lib.conf.Value;
|
||||
import org.apache.openjpa.lib.test.AbstractTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests the {@link Value}, {@link PluginValue}, and
|
||||
|
@ -32,10 +35,7 @@ import org.apache.openjpa.lib.test.AbstractTestCase;
|
|||
*/
|
||||
public class TestPluginValue extends AbstractTestCase {
|
||||
|
||||
public TestPluginValue(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
defaultTest(new StringValue("testKey"));
|
||||
defaultTest(new PluginValue("testKey", true));
|
||||
|
@ -74,6 +74,7 @@ public class TestPluginValue extends AbstractTestCase {
|
|||
assertEquals(null, val.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlias() {
|
||||
aliasTest(new StringValue("testKey"));
|
||||
aliasTest(new PluginValue("testKey", true));
|
||||
|
@ -131,6 +132,7 @@ public class TestPluginValue extends AbstractTestCase {
|
|||
assertTrue(((PluginListValue) val).getClassNames().length == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPluginListParsing() {
|
||||
PluginListValue val = new PluginListValue("testKey");
|
||||
assertEquals(0, val.getClassNames().length);
|
||||
|
@ -175,7 +177,4 @@ public class TestPluginValue extends AbstractTestCase {
|
|||
public void setTestKey(String key) {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,11 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.openjpa.lib.test.AbstractTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Tests the {@link DepthFirstAnalysis} type.</p>
|
||||
|
@ -34,7 +39,7 @@ public class TestDepthFirstAnalysis
|
|||
|
||||
private DepthFirstAnalysis _dfa = null;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
setUpGraph1();
|
||||
}
|
||||
|
@ -79,6 +84,7 @@ public class TestDepthFirstAnalysis
|
|||
_dfa = new DepthFirstAnalysis(graph);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNodeSorting() {
|
||||
Collection nodes = _dfa.getSortedNodes();
|
||||
assertEquals(4, nodes.size());
|
||||
|
@ -92,6 +98,7 @@ public class TestDepthFirstAnalysis
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEdgeTyping() {
|
||||
Collection edges = _dfa.getEdges(Edge.TYPE_BACK);
|
||||
assertEquals(2, edges.size());
|
||||
|
@ -102,6 +109,7 @@ public class TestDepthFirstAnalysis
|
|||
|| edge1.getTo().equals(edge1.getFrom()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackEdges() {
|
||||
setUpGraph2();
|
||||
Collection edges = _dfa.getEdges(Edge.TYPE_BACK);
|
||||
|
@ -130,6 +138,7 @@ public class TestDepthFirstAnalysis
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForwardEdges() {
|
||||
setUpGraph2();
|
||||
Collection edges = _dfa.getEdges(Edge.TYPE_FORWARD);
|
||||
|
@ -153,7 +162,4 @@ public class TestDepthFirstAnalysis
|
|||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main(TestDepthFirstAnalysis.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@ import java.util.Collection;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.apache.openjpa.lib.test.AbstractTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* <p>Tests the {@link Graph} type, and in so doing implicitly tests the
|
||||
|
@ -41,7 +45,7 @@ public class TestGraph
|
|||
private Edge _edge3 = new Edge(_node1, _node3, false);
|
||||
private Edge _edge4 = new Edge(_node2, _node2, false);
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
_graph.addNode(_node1);
|
||||
_graph.addNode(_node2);
|
||||
|
@ -55,6 +59,7 @@ public class TestGraph
|
|||
/**
|
||||
* Tests adding and retrieving nodes and edges.
|
||||
*/
|
||||
@Test
|
||||
public void testAddRetrieve() {
|
||||
assertEquals(3, _graph.getNodes().size());
|
||||
assertEquals(4, _graph.getEdges().size());
|
||||
|
@ -106,6 +111,7 @@ public class TestGraph
|
|||
/**
|
||||
* Test removing edges.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveEdges() {
|
||||
assertTrue(_graph.removeEdge(_edge2));
|
||||
Collection edges = _graph.getEdgesFrom(_node2);
|
||||
|
@ -127,6 +133,7 @@ public class TestGraph
|
|||
/**
|
||||
* Test removing nodes.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveNodes() {
|
||||
assertTrue(_graph.removeNode(_node3));
|
||||
Collection edges = _graph.getEdges();
|
||||
|
@ -143,7 +150,4 @@ public class TestGraph
|
|||
assertEquals(0, edges.size());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main(TestGraph.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,13 @@
|
|||
package org.apache.openjpa.lib.identifier;
|
||||
|
||||
import org.apache.openjpa.lib.test.AbstractTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TestIdentifiers extends AbstractTestCase {
|
||||
|
||||
@Test
|
||||
public void testIdentifierConversion() {
|
||||
|
||||
// Create a naming configs used for testing.
|
||||
|
|
|
@ -27,6 +27,10 @@ import java.util.ListIterator;
|
|||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.apache.openjpa.lib.test.AbstractTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link ResultList} implementations.
|
||||
|
@ -39,12 +43,12 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
|
||||
protected boolean subListSupported = false;
|
||||
|
||||
public ResultListTest(String test) {
|
||||
super(test);
|
||||
|
||||
public ResultListTest() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public ResultListTest(String test, boolean supportSubList) {
|
||||
super(test);
|
||||
public ResultListTest(boolean supportSubList) {
|
||||
subListSupported = supportSubList;
|
||||
}
|
||||
|
||||
|
@ -63,7 +67,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
List results = new ArrayList(100);
|
||||
for (int i = 0; i < 100; i++)
|
||||
|
@ -74,6 +78,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
_lists[i] = getResultList(rops[i]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIterator() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
Iterator itr = _lists[i].iterator();
|
||||
|
@ -90,6 +95,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIteratorModification() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
try {
|
||||
|
@ -102,6 +108,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListIteratorForward() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
ListIterator itr = _lists[i].listIterator();
|
||||
|
@ -120,6 +127,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListIteratorIndex() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
ListIterator itr = _lists[i].listIterator(50);
|
||||
|
@ -138,6 +146,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListIteratorReverse() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
ListIterator itr = _lists[i].listIterator(100);
|
||||
|
@ -156,6 +165,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListIteratorModification() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
try {
|
||||
|
@ -168,12 +178,14 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleIterations() {
|
||||
testListIteratorIndex();
|
||||
testListIteratorForward();
|
||||
testListIteratorReverse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
assertTrue(_lists[i].contains("0"));
|
||||
|
@ -189,6 +201,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModification() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
try {
|
||||
|
@ -209,6 +222,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBegin() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
for (int j = 0; j < 10; j++)
|
||||
|
@ -222,12 +236,14 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMiddle() {
|
||||
for (int i = 0; i < _lists.length; i++)
|
||||
for (int j = 50; j < 60; j++)
|
||||
assertEquals(String.valueOf(j), _lists[i].get(j));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEnd() {
|
||||
for (int i = 0; i < _lists.length; i++) {
|
||||
for (int j = 90; j < 100; j++)
|
||||
|
@ -241,12 +257,14 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetReverse() {
|
||||
for (int i = 0; i < _lists.length; i++)
|
||||
for (int j = 99; j > -1; j--)
|
||||
assertEquals(String.valueOf(j), _lists[i].get(j));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleGet() {
|
||||
testGetMiddle();
|
||||
testGetBegin();
|
||||
|
@ -262,12 +280,14 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
testGetEnd();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSize() {
|
||||
for (int i = 0; i < _lists.length; i++)
|
||||
assertTrue(_lists[i].size() == 100
|
||||
|| _lists[i].size() == Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmpty() {
|
||||
ResultObjectProvider[] rops = getResultObjectProviders
|
||||
(Collections.EMPTY_LIST);
|
||||
|
@ -278,6 +298,7 @@ public abstract class ResultListTest extends AbstractTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubList() {
|
||||
ResultObjectProvider[] rops = getResultObjectProviders
|
||||
(Collections.EMPTY_LIST);
|
||||
|
|
|
@ -25,8 +25,8 @@ package org.apache.openjpa.lib.rop;
|
|||
*/
|
||||
public class TestEagerResultList extends ResultListTest {
|
||||
|
||||
public TestEagerResultList(String test) {
|
||||
super(test, true);
|
||||
public TestEagerResultList() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,7 +34,4 @@ public class TestEagerResultList extends ResultListTest {
|
|||
return new EagerResultList(provider);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,16 +25,12 @@ package org.apache.openjpa.lib.rop;
|
|||
*/
|
||||
public class TestLazyForwardResultList extends ResultListTest {
|
||||
|
||||
public TestLazyForwardResultList(String test) {
|
||||
super(test, true);
|
||||
public TestLazyForwardResultList() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResultList getResultList(ResultObjectProvider provider) {
|
||||
return new LazyForwardResultList(provider);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ package org.apache.openjpa.lib.rop;
|
|||
*/
|
||||
public class TestListResultList extends ResultListTest {
|
||||
|
||||
public TestListResultList(String test) {
|
||||
super(test, true);
|
||||
public TestListResultList() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,7 +35,4 @@ public class TestListResultList extends ResultListTest {
|
|||
getDelegate());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,6 @@ import java.util.List;
|
|||
*/
|
||||
public class TestMergedResultObjectProvider extends ResultListTest {
|
||||
|
||||
public TestMergedResultObjectProvider(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResultList getResultList(ResultObjectProvider provider) {
|
||||
return new WindowResultList(provider, 10);
|
||||
|
@ -62,7 +58,4 @@ public class TestMergedResultObjectProvider extends ResultListTest {
|
|||
return merges;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,6 @@ import java.util.List;
|
|||
*/
|
||||
public class TestOrderedMergedResultObjectProvider extends ResultListTest {
|
||||
|
||||
public TestOrderedMergedResultObjectProvider(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResultList getResultList(ResultObjectProvider provider) {
|
||||
return new WindowResultList(provider, 10);
|
||||
|
@ -64,10 +60,6 @@ public class TestOrderedMergedResultObjectProvider extends ResultListTest {
|
|||
};
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
|
||||
private static class IntValueComparator implements Comparator {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,16 +25,9 @@ package org.apache.openjpa.lib.rop;
|
|||
*/
|
||||
public class TestRandomAccessResultList extends ResultListTest {
|
||||
|
||||
public TestRandomAccessResultList(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResultList getResultList(ResultObjectProvider provider) {
|
||||
return new RandomAccessResultList(provider);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,6 @@ import java.util.List;
|
|||
*/
|
||||
public class TestRangeResultObjectProvider extends ResultListTest {
|
||||
|
||||
public TestRangeResultObjectProvider(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResultList getResultList(ResultObjectProvider provider) {
|
||||
|
@ -66,7 +63,4 @@ public class TestRangeResultObjectProvider extends ResultListTest {
|
|||
return ranges;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,16 +25,9 @@ package org.apache.openjpa.lib.rop;
|
|||
*/
|
||||
public class TestSimpleResultList extends ResultListTest {
|
||||
|
||||
public TestSimpleResultList(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResultList getResultList(ResultObjectProvider provider) {
|
||||
return new SimpleResultList(provider);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,16 +25,9 @@ package org.apache.openjpa.lib.rop;
|
|||
*/
|
||||
public class TestSoftRandomAccessResultList extends ResultListTest {
|
||||
|
||||
public TestSoftRandomAccessResultList(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResultList getResultList(ResultObjectProvider provider) {
|
||||
return new SoftRandomAccessResultList(provider);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,16 +25,10 @@ package org.apache.openjpa.lib.rop;
|
|||
*/
|
||||
public class TestWindowResultList extends ResultListTest {
|
||||
|
||||
public TestWindowResultList(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResultList getResultList(ResultObjectProvider provider) {
|
||||
return new WindowResultList(provider, 10);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
main();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,40 +18,20 @@
|
|||
*/
|
||||
package org.apache.openjpa.lib.test;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.openjpa.lib.log.Log;
|
||||
import org.apache.openjpa.lib.log.LogFactoryImpl;
|
||||
|
@ -59,13 +39,9 @@ import org.apache.openjpa.lib.util.Localizer;
|
|||
import org.apache.regexp.RE;
|
||||
import org.apache.regexp.RESyntaxException;
|
||||
import org.apache.regexp.REUtil;
|
||||
import org.apache.tools.ant.AntClassLoader;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.ProjectHelper;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestResult;
|
||||
import junit.textui.TestRunner;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* TestCase framework to run various tests against solarmetric code.
|
||||
|
@ -80,37 +56,13 @@ import junit.textui.TestRunner;
|
|||
* @author Marc Prud'hommeaux
|
||||
* @author Patrick Linskey
|
||||
*/
|
||||
public abstract class AbstractTestCase extends TestCase {
|
||||
|
||||
public static final String TEST_METHODS =
|
||||
System.getProperty(AbstractTestCase.class.getName() + ".testMethods");
|
||||
public static final long PLATFORM_ALL = 2 << 1;
|
||||
public static final long PLATFORM_UNKNOWN = 2 << 2;
|
||||
|
||||
public static final String SKIP_TOKEN = "SOLARSKIP";
|
||||
public static final String SKIP_DELIMITER = "|";
|
||||
public abstract class AbstractTestCase {
|
||||
|
||||
private static final Localizer _loc =
|
||||
Localizer.forPackage(AbstractTestCase.class);
|
||||
|
||||
private Log log = null;
|
||||
|
||||
private static Map _times = new HashMap();
|
||||
|
||||
private static AbstractTestCase _lastTest = null;
|
||||
|
||||
private static WatchdogThread _watchdog = new WatchdogThread();
|
||||
private long _timeout;
|
||||
|
||||
/**
|
||||
* Constructor. Create a test case with the specified name.
|
||||
*/
|
||||
public AbstractTestCase(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
public AbstractTestCase() {
|
||||
}
|
||||
|
||||
protected final Log getLog() {
|
||||
if (log == null)
|
||||
|
@ -122,112 +74,17 @@ public abstract class AbstractTestCase extends TestCase {
|
|||
// this implementation leaves much to be desired, as it just
|
||||
// creates a new LogFactoryImpl each time, and does not apply
|
||||
// any configurations.
|
||||
return new LogFactoryImpl().getLog(getLogName());
|
||||
return new LogFactoryImpl().getLog(this.getClass().getName());
|
||||
}
|
||||
|
||||
protected String getLogName() {
|
||||
return "com.solarmetric.Runtime";
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before the watchdog thread is about to kill the entire
|
||||
* JVM due to a test case's timeout. This method offers the
|
||||
* ability to try to resolve whatever contention is taking place
|
||||
* in the test. It will be given 10 seconds to try to end the
|
||||
* test peacefully before the watchdog exits the JVM.
|
||||
*/
|
||||
protected void preTimeout() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(TestResult result) {
|
||||
if (skipTest()) {
|
||||
// keep track of the tests we skip so that we can get an
|
||||
// idea in the autobuild status
|
||||
System.err.println(SKIP_TOKEN + SKIP_DELIMITER
|
||||
+ ("" + getClass().getName())
|
||||
+ "." + getName() + SKIP_DELIMITER);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_lastTest != null && _lastTest.getClass() != getClass()) {
|
||||
try {
|
||||
_lastTest.tearDownTestClass();
|
||||
} catch (Throwable t) {
|
||||
getLog().error(null, t);
|
||||
}
|
||||
}
|
||||
|
||||
if (_lastTest == null || _lastTest.getClass() != getClass()) {
|
||||
try {
|
||||
setUpTestClass();
|
||||
} catch (Throwable t) {
|
||||
getLog().error(null, t);
|
||||
}
|
||||
}
|
||||
|
||||
_lastTest = this;
|
||||
|
||||
// inform the watchdog thread that we are entering the test
|
||||
_watchdog.enteringTest(this);
|
||||
try {
|
||||
super.run(result);
|
||||
} finally {
|
||||
_watchdog.leavingTest(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If this test should be skipped given the current
|
||||
* environment, return <code>true</code>. This allows a unit test
|
||||
* class to disable test cases on a per-method granularity, and
|
||||
* prevents the test from showing up as a passed test just
|
||||
* because it was skipped.
|
||||
* For example, if a particular test case method should not be
|
||||
* run against a certain database, this method could check the
|
||||
* name of the test result and the current database configuration
|
||||
* in order to make the decision:
|
||||
* <p/>
|
||||
* <code> protected boolean skipTest() {
|
||||
* // don't run with pointbase: it uses a DataSource, which
|
||||
* // can't be translated into a JBoss DataSource configuration.
|
||||
* if ("testJBoss".equals(getName()) &&
|
||||
* getCurrentPlatform() == PLATFORM_POINTBASE)
|
||||
* return true;
|
||||
* }
|
||||
* </code>
|
||||
* If you want to disable execution of an entire test case
|
||||
* class for a given database, you might want to add the class to
|
||||
* the excluded test list in that database's properties file.
|
||||
*/
|
||||
protected boolean skipTest() {
|
||||
if (TEST_METHODS != null && TEST_METHODS.length() > 0)
|
||||
return TEST_METHODS.indexOf(getName()) == -1;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called before the first test in this test class
|
||||
* is executed.
|
||||
*/
|
||||
public void setUpTestClass() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called after the last test in this test class
|
||||
* is executed. It can be used to do things like clean up
|
||||
* large, slow processes that may have been started.
|
||||
*/
|
||||
public void tearDownTestClass() throws Exception {
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if ("true".equals(System.getProperty("meminfo")))
|
||||
printMemoryInfo();
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
|
@ -262,54 +119,6 @@ public abstract class AbstractTestCase extends TestCase {
|
|||
return new Long((long) (Math.random() * Long.MAX_VALUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random Short for testing.
|
||||
*/
|
||||
public static Short randomShort() {
|
||||
return new Short((short) (Math.random() * Short.MAX_VALUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random Double for testing.
|
||||
*/
|
||||
public static Double randomDouble() {
|
||||
return new Double((double) (Math.round(Math.random() * 5000d)) / 1000d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random Float for testing.
|
||||
*/
|
||||
public static Float randomFloat() {
|
||||
return new Float((float) (Math.round(Math.random() * 5000f)) / 1000f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random Byte for testing.
|
||||
*/
|
||||
public static Byte randomByte() {
|
||||
return new Byte((byte) (Math.random() * Byte.MAX_VALUE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random Boolean for testing.
|
||||
*/
|
||||
public static Boolean randomBoolean() {
|
||||
return new Boolean(Math.random() > 0.5 ? true : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random Date for testing.
|
||||
*/
|
||||
public static Date randomDate() {
|
||||
long millis = (long) (Math.random() * System.currentTimeMillis());
|
||||
|
||||
// round millis to the nearest 1000: this is because some
|
||||
// databases do not store the milliseconds correctly(e.g., MySQL).
|
||||
// This is a really a bug we should fix. FC #27.
|
||||
millis -= (millis % 1000);
|
||||
|
||||
return new Date(millis);
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random String for testing.
|
||||
|
@ -330,408 +139,11 @@ public abstract class AbstractTestCase extends TestCase {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random clob for testing.
|
||||
*/
|
||||
public static String randomClob() {
|
||||
StringBuffer sbuf = new StringBuffer();
|
||||
while (sbuf.length() < (5 * 1024)) { // at least 5K
|
||||
sbuf.append(randomString(1024));
|
||||
}
|
||||
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random BigInteger for testing.
|
||||
*/
|
||||
public static BigInteger randomBigInteger() {
|
||||
// too many of our test databases don't support bigints > MAX_LONG:
|
||||
// I don't like it, but for now, let's only test below MAX_LONG
|
||||
BigInteger lng = new BigInteger(
|
||||
((long) (Math.random() * Long.MAX_VALUE)) + "");
|
||||
|
||||
BigInteger multiplier = new BigInteger("1");
|
||||
// (1 + (int)(Math.random() * 10000)) + "");
|
||||
if (Math.random() < 0.5)
|
||||
multiplier = multiplier.multiply(new BigInteger("-1"));
|
||||
|
||||
return lng.multiply(multiplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random BigDecimal for testing.
|
||||
*/
|
||||
public static BigDecimal randomBigDecimal() {
|
||||
BigInteger start = randomBigInteger();
|
||||
String str = start.toString();
|
||||
// truncate off the last 8 digits: we still get some
|
||||
// overflows with lame databases.
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (str.length() > 2)
|
||||
str = str.substring(0, str.length() - 1);
|
||||
start = new BigInteger(str);
|
||||
|
||||
String val = start + "." + ((int) (Math.random() * 10))
|
||||
+ ((int) (Math.random() * 10))
|
||||
+ ((int) (Math.random() * 10))
|
||||
+ ((int) (Math.random() * 10))
|
||||
+ ((int) (Math.random() * 10))
|
||||
+ ((int) (Math.random() * 10))
|
||||
+ ((int) (Math.random() * 10))
|
||||
+ ((int) (Math.random() * 10))
|
||||
+ ((int) (Math.random() * 10))
|
||||
+ ((int) (Math.random() * 10));
|
||||
|
||||
return new BigDecimal(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Support method to get a random blob for testing.
|
||||
*/
|
||||
public static byte[] randomBlob() {
|
||||
// up to 100K blob
|
||||
byte [] blob = new byte [(int) (Math.random() * 1024 * 100)];
|
||||
for (int i = 0; i < blob.length; i++)
|
||||
blob[i] = randomByte().byteValue();
|
||||
|
||||
return blob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke setters for pimitives and primitive wrappers on the
|
||||
* specified object.
|
||||
*/
|
||||
public static Object randomizeBean(Object bean)
|
||||
throws IntrospectionException, IllegalAccessException,
|
||||
InvocationTargetException {
|
||||
BeanInfo info = Introspector.getBeanInfo(bean.getClass());
|
||||
PropertyDescriptor [] props = info.getPropertyDescriptors();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Method write = props[i].getWriteMethod();
|
||||
if (write == null)
|
||||
continue;
|
||||
|
||||
Class [] params = write.getParameterTypes();
|
||||
if (params == null || params.length != 1)
|
||||
continue;
|
||||
|
||||
Class paramType = params[0];
|
||||
Object arg = null;
|
||||
|
||||
if (paramType == boolean.class || paramType == Boolean.class)
|
||||
arg = randomBoolean();
|
||||
else if (paramType == byte.class || paramType == Byte.class)
|
||||
arg = randomByte();
|
||||
else if (paramType == char.class || paramType == Character.class)
|
||||
arg = randomChar();
|
||||
else if (paramType == short.class || paramType == Short.class)
|
||||
arg = randomShort();
|
||||
else if (paramType == int.class || paramType == Integer.class)
|
||||
arg = randomInt();
|
||||
else if (paramType == long.class || paramType == Long.class)
|
||||
arg = randomLong();
|
||||
else if (paramType == double.class || paramType == Double.class)
|
||||
arg = randomDouble();
|
||||
else if (paramType == float.class || paramType == Float.class)
|
||||
arg = randomFloat();
|
||||
else if (paramType == String.class)
|
||||
arg = randomString();
|
||||
else if (paramType == BigInteger.class)
|
||||
arg = randomBigInteger();
|
||||
else if (paramType == BigDecimal.class)
|
||||
arg = randomBigDecimal();
|
||||
else if (paramType == Date.class)
|
||||
arg = randomDate();
|
||||
|
||||
if (arg != null)
|
||||
write.invoke(bean, new Object []{ arg });
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to start a profile.
|
||||
*
|
||||
* @see #endProfile(String)
|
||||
*/
|
||||
public void startProfile(String name) {
|
||||
_times.put(name, new Long(System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to end the profile and print out the time. Example usage:
|
||||
* <p/>
|
||||
* <pre><code> startProfile("Some long task"); doSomeLongTask();
|
||||
* endProfile("Some long task");
|
||||
* </code></pre>
|
||||
*
|
||||
* @param name
|
||||
* @return the amount of time that this profile invocation took, or
|
||||
* -1 if <code>name</code> was never started.
|
||||
*/
|
||||
public long endProfile(String name) {
|
||||
Long time = (Long) _times.remove(name);
|
||||
|
||||
long elapsed = -1;
|
||||
if (time != null)
|
||||
elapsed = System.currentTimeMillis() - time.longValue();
|
||||
|
||||
getLog().info(_loc.get("profile-info", name,
|
||||
(time == null ? "???" : "" + elapsed)));
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
// ClassLoader functions
|
||||
/////////////////////////
|
||||
|
||||
/**
|
||||
* Create a ClassLoader that will not use the parent
|
||||
* ClassLoader to resolve classes. This is useful for
|
||||
* testing interactions between Kodo in running
|
||||
* in ClassLoaderA and instances in ClassLoaderB.
|
||||
*/
|
||||
public ClassLoader createIsolatedClassLoader() {
|
||||
return new IsolatedClassLoader();
|
||||
}
|
||||
|
||||
public NestedClassLoader createNestedClassLoader() {
|
||||
return new NestedClassLoader(false);
|
||||
}
|
||||
|
||||
public NestedClassLoader createNestedParentClassLoader() {
|
||||
return new NestedClassLoader(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the specified class in an isolated ClassLoader.
|
||||
*
|
||||
* @param target the target class to load
|
||||
* @return the Class as reloaded in an new ClassLoader
|
||||
*/
|
||||
public Class isolate(Class target) throws ClassNotFoundException {
|
||||
Class result = isolate(target.getName());
|
||||
assertTrue(result != target);
|
||||
assertNotEquals(result, target);
|
||||
assertTrue(result.getClassLoader() != target.getClassLoader());
|
||||
return result;
|
||||
}
|
||||
|
||||
public Class isolate(String target) throws ClassNotFoundException {
|
||||
ClassLoader il = createIsolatedClassLoader();
|
||||
Class result = il.loadClass(target);
|
||||
assertEquals(result.getName(), target);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Class nest(Class target) throws ClassNotFoundException {
|
||||
ClassLoader il = createNestedClassLoader();
|
||||
Class result = il.loadClass(target.getName());
|
||||
assertTrue(result != target);
|
||||
assertNotEquals(result, target);
|
||||
assertTrue(result.getClassLoader() != target.getClassLoader());
|
||||
assertEquals(result.getName(), target.getName());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object isolateNew(Class target)
|
||||
throws ClassNotFoundException, IllegalAccessException,
|
||||
InstantiationException {
|
||||
return isolate(target).newInstance();
|
||||
}
|
||||
|
||||
private static class NestedClassLoader extends AntClassLoader {
|
||||
|
||||
public NestedClassLoader(boolean useParent) {
|
||||
super(ClassLoader.getSystemClassLoader(), useParent);
|
||||
|
||||
for (StringTokenizer cltok = new StringTokenizer(
|
||||
System.getProperty("java.class.path"), File.pathSeparator);
|
||||
cltok.hasMoreTokens();) {
|
||||
String path = cltok.nextToken();
|
||||
|
||||
// only load test paths, not jar files
|
||||
if (path.indexOf(".jar") != -1)
|
||||
continue;
|
||||
if (path.indexOf(".zip") != -1)
|
||||
continue;
|
||||
|
||||
addPathElement(path);
|
||||
}
|
||||
|
||||
try {
|
||||
if (!useParent) {
|
||||
assertTrue(loadClass
|
||||
(AbstractTestCase.class.getName()).getClassLoader()
|
||||
!= AbstractTestCase.class.getClassLoader());
|
||||
}
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
fail(cnfe.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class findClass(String name) throws ClassNotFoundException {
|
||||
// don't isolate PC and related classes in kodo.enhnace
|
||||
if (name.indexOf(".enhance.") != -1)
|
||||
throw new ClassNotFoundException(name);
|
||||
if (name.indexOf("/enhance/") != -1)
|
||||
throw new ClassNotFoundException(name);
|
||||
return super.findClass(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A ClassLoader that is completely isolated with respect to
|
||||
* any classes that are loaded in the System ClassLoader.
|
||||
*
|
||||
* @author Marc Prud'hommeaux
|
||||
*/
|
||||
private static class IsolatedClassLoader extends NestedClassLoader {
|
||||
|
||||
public IsolatedClassLoader() {
|
||||
super(false);
|
||||
setIsolated(false);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////
|
||||
// Collections
|
||||
///////////////
|
||||
|
||||
/**
|
||||
* Validate that the specified {@link Collection} fulfills the
|
||||
* Collection contract as specified by the Collections API.
|
||||
* <p/>
|
||||
* <strong>Note</strong>: does not validate mutable operations
|
||||
*/
|
||||
public static void validateCollection(Collection collection) {
|
||||
int size = collection.size();
|
||||
int iterated = 0;
|
||||
// ensure we can walk along the iterator
|
||||
for (Iterator i = collection.iterator(); i.hasNext();) {
|
||||
iterated++;
|
||||
i.next();
|
||||
}
|
||||
|
||||
// ensure the number of values iterated is the same as the list size
|
||||
assertEquals(size, iterated);
|
||||
|
||||
// also validate the list
|
||||
if (collection instanceof List) {
|
||||
List ll = new ArrayList();
|
||||
for (int i = 0; i < 100; i++)
|
||||
ll.add(new Integer(i));
|
||||
validateList((List) ll);
|
||||
validateList((List) collection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the specified {@link List} fulfills the
|
||||
* List contract as specified by the Collections API.
|
||||
* <p/>
|
||||
* <strong>Note</strong>: does not validate mutable operations
|
||||
*/
|
||||
public static void validateList(List list) {
|
||||
Object [] coreValues = list.toArray();
|
||||
Object [] values1 = new Object [list.size()];
|
||||
Object [] values2 = new Object [list.size()];
|
||||
Object [] values3 = new Object [list.size()];
|
||||
Object [] values4 = new Object [list.size()];
|
||||
|
||||
// fill sequential index access list
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
values1[i] = list.get(i);
|
||||
|
||||
// fill sequential list
|
||||
int index = 0;
|
||||
ListIterator iter;
|
||||
for (iter = list.listIterator(0); iter.hasNext();) {
|
||||
assertEquals(index, iter.nextIndex());
|
||||
assertEquals(index, iter.previousIndex() + 1);
|
||||
values2[index] = iter.next();
|
||||
assertTrue(list.contains(values2[index]));
|
||||
index++;
|
||||
}
|
||||
|
||||
// ensure NoSuchElementException is thrown as appropriate
|
||||
try {
|
||||
iter.next();
|
||||
fail("next() should have resulted in a NoSuchElementException");
|
||||
} catch (NoSuchElementException e) {
|
||||
} // as expected
|
||||
|
||||
// fill reverse sequential list
|
||||
int back = 0;
|
||||
for (iter = list.listIterator(list.size()); iter.hasPrevious();) {
|
||||
assertEquals(index, iter.previousIndex() + 1);
|
||||
assertEquals(index, iter.nextIndex());
|
||||
values3[--index] = iter.previous();
|
||||
back++;
|
||||
}
|
||||
assertEquals(list.size(), back);
|
||||
|
||||
// ensure NoSuchElementException is thrown as appropriate
|
||||
try {
|
||||
iter.previous();
|
||||
fail("previous() should have resulted in a "
|
||||
+ "NoSuchElementException");
|
||||
} catch (NoSuchElementException e) {
|
||||
} // as expected
|
||||
|
||||
// fill random access list
|
||||
List indices = new LinkedList();
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
indices.add(new Integer(i));
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
int rand = (int) (Math.random() * indices.size());
|
||||
Integer randIndex = (Integer) indices.remove(rand);
|
||||
values4[randIndex.intValue()] = list.get(randIndex.intValue());
|
||||
}
|
||||
|
||||
assertEquals(Arrays.asList(coreValues), Arrays.asList(values1));
|
||||
assertIdentical(Arrays.asList(coreValues), Arrays.asList(values1));
|
||||
assertEquals(Arrays.asList(coreValues), Arrays.asList(values2));
|
||||
assertIdentical(Arrays.asList(coreValues), Arrays.asList(values2));
|
||||
assertEquals(Arrays.asList(coreValues), Arrays.asList(values4));
|
||||
assertIdentical(Arrays.asList(coreValues), Arrays.asList(values4));
|
||||
assertEquals(Arrays.asList(coreValues), Arrays.asList(values3));
|
||||
assertIdentical(Arrays.asList(coreValues), Arrays.asList(values3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the given List contain the exact same
|
||||
* elements. This is different than the normal List contract, which
|
||||
* states that list1.equals(list2) if each element e1.equals(e2).
|
||||
* This method asserts that e1 == n2.
|
||||
*/
|
||||
public static void assertIdentical(List c1, List c2) {
|
||||
assertEquals(c1.size(), c2.size());
|
||||
for (Iterator i1 = c1.iterator(), i2 = c2.iterator();
|
||||
i1.hasNext() && i2.hasNext();)
|
||||
assertTrue(i1.next() == i2.next());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the collection parameter is already ordered
|
||||
* according to the specified comparator.
|
||||
*/
|
||||
public void assertOrdered(Collection c, Comparator comp) {
|
||||
List l1 = new LinkedList(c);
|
||||
List l2 = new LinkedList(c);
|
||||
assertEquals(l1, l2);
|
||||
Collections.sort(l2, comp);
|
||||
assertEquals(l1, l2);
|
||||
Collections.sort(l1, comp);
|
||||
assertEquals(l1, l2);
|
||||
}
|
||||
|
||||
////////////////////
|
||||
// Assertion Helpers
|
||||
////////////////////
|
||||
|
@ -804,39 +216,6 @@ public abstract class AbstractTestCase extends TestCase {
|
|||
nf.format(free)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all values iterated by the given iterator.
|
||||
*/
|
||||
public static List iteratorToList(Iterator i) {
|
||||
LinkedList list = new LinkedList();
|
||||
while (i.hasNext())
|
||||
list.add(i.next());
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of the objects iterated by the given iterator.
|
||||
*/
|
||||
public static Object [] iteratorToArray(Iterator i, Class [] clazz) {
|
||||
return iteratorToList(i).toArray(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run ant on the specified build file.
|
||||
*
|
||||
* @param buildFile the build file to use
|
||||
* @param target the name of the target to invoke
|
||||
*/
|
||||
public void ant(File buildFile, String target) {
|
||||
assertTrue(buildFile.isFile());
|
||||
|
||||
Project project = new Project();
|
||||
project.init();
|
||||
project.setUserProperty("ant.file", buildFile.getAbsolutePath());
|
||||
ProjectHelper.configureProject(project, buildFile);
|
||||
project.executeTarget(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize and deserialize the object.
|
||||
*
|
||||
|
@ -872,25 +251,6 @@ public abstract class AbstractTestCase extends TestCase {
|
|||
return re.match(input);
|
||||
}
|
||||
|
||||
public static void assertMatches(String regex, String input) {
|
||||
try {
|
||||
if (!(matches(regex, input)))
|
||||
fail("Expected regular expression: <" + regex + ">"
|
||||
+ " did not match: <" + input + ">");
|
||||
} catch (RESyntaxException e) {
|
||||
throw new IllegalArgumentException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertNotMatches(String regex, String input) {
|
||||
try {
|
||||
if (matches(regex, input))
|
||||
fail("Regular expression: <" + regex + ">"
|
||||
+ " should not match: <" + input + ">");
|
||||
} catch (RESyntaxException e) {
|
||||
throw new IllegalArgumentException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the list if strings and return the ones that match
|
||||
|
@ -908,212 +268,4 @@ public abstract class AbstractTestCase extends TestCase {
|
|||
return matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the specified collection of Strings contains at least
|
||||
* one string that matches the specified regular expression.
|
||||
*/
|
||||
public static void assertMatches(String regex, Collection input) {
|
||||
try {
|
||||
if (matches(regex, input).size() == 0)
|
||||
fail("The specified list of size " + input.size()
|
||||
+ " did not contain any strings that match the"
|
||||
+ " specified regular expression(\"" + regex + "\")");
|
||||
} catch (RESyntaxException e) {
|
||||
throw new IllegalArgumentException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the specified collection of Strings does not match
|
||||
* the specified regular expression.
|
||||
*/
|
||||
public static void assertNotMatches(String regex, Collection input) {
|
||||
try {
|
||||
List matches;
|
||||
|
||||
if (((matches = matches(regex, input))).size() > 0)
|
||||
fail("The specified list of size " + input.size()
|
||||
+ " did contain one or more strings that matchs the"
|
||||
+ " specified illegal regular expression"
|
||||
+ " (\"" + regex + "\")."
|
||||
+ " First example of a matching message is: "
|
||||
+ matches.iterator().next());
|
||||
} catch (RESyntaxException e) {
|
||||
throw new IllegalArgumentException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To be called by the child. E.g.:
|
||||
* <code> public static void main(String [] args) { main(TestBug375.class);
|
||||
* }
|
||||
* </code>
|
||||
*/
|
||||
public static void main(Class c) {
|
||||
TestRunner.run(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* To be called by child. Figures out the class from the calling context.
|
||||
*/
|
||||
public static void main() {
|
||||
String caller = new SecurityManager() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClassContext()[2].getName();
|
||||
}
|
||||
}.toString();
|
||||
|
||||
try {
|
||||
main(Class.forName(caller));
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new RuntimeException(cnfe.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the jar file in which the class is contained.
|
||||
*
|
||||
* @return the jar file, or none if the class is not in a jar
|
||||
* @throws FileNotFoundException if the jar file cannot located
|
||||
*/
|
||||
public static File getJarFile(Class clazz) throws FileNotFoundException {
|
||||
URL url = clazz.getResource(clazz.getName().substring(
|
||||
clazz.getName().lastIndexOf(".") + 1) + ".class");
|
||||
if (url == null)
|
||||
throw new FileNotFoundException(clazz.toString());
|
||||
|
||||
String file = url.getFile();
|
||||
if (file == null)
|
||||
throw new FileNotFoundException(url.toString());
|
||||
int index = file.indexOf("!");
|
||||
if (index == -1)
|
||||
throw new FileNotFoundException(file);
|
||||
|
||||
file = file.substring(0, index);
|
||||
file = file.substring("file:".length());
|
||||
|
||||
File f = new File(file);
|
||||
if (!(f.isFile()))
|
||||
throw new FileNotFoundException(file);
|
||||
|
||||
return f.getAbsoluteFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of milliseconds each test case will have for a timeout.
|
||||
*/
|
||||
public void setTimeout(long timeout) {
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of milliseconds each test case will have for a timeout.
|
||||
*/
|
||||
public long getTimeout() {
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* A watchdog that just exits the JVM if a test has not completed in
|
||||
* a certain amount of time. This speeds up the mechanism of determining
|
||||
* if a timeout has occurred, since we can exit the entire test run
|
||||
* if a test hasn't completed in a shorted amount of time than
|
||||
* the global test timeout.
|
||||
*
|
||||
* @author Marc Prud'hommeaux
|
||||
*/
|
||||
private static class WatchdogThread extends Thread {
|
||||
|
||||
private final long _timeoutms;
|
||||
private long _endtime = -1;
|
||||
private AbstractTestCase _curtest = null;
|
||||
|
||||
public WatchdogThread() {
|
||||
super("Kodo test case watchdog thread");
|
||||
setDaemon(true);
|
||||
|
||||
int timeoutMin = new Integer
|
||||
(System.getProperty("autobuild.testcase.timeout", "20"))
|
||||
.intValue();
|
||||
|
||||
_timeoutms = timeoutMin * 60 * 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
sleep(200);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
|
||||
if (_endtime > 0 && System.currentTimeMillis() > _endtime) {
|
||||
Thread preTimeout = new Thread
|
||||
("Attempting pre-timeout for " + _curtest) {
|
||||
@Override
|
||||
public void run() {
|
||||
_curtest.preTimeout();
|
||||
}
|
||||
};
|
||||
preTimeout.start();
|
||||
|
||||
// wait a little while for the pre-timeout
|
||||
// thread to complete
|
||||
try {
|
||||
preTimeout.join(10 * 1000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// give it a few more seconds...
|
||||
try {
|
||||
sleep(5 * 1000);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// new endtime? resume...
|
||||
if (System.currentTimeMillis() < _endtime)
|
||||
continue;
|
||||
|
||||
new Exception("test case "
|
||||
+ (_curtest != null ? _curtest.getName()
|
||||
: "UNKNOWN") + " timed out after "
|
||||
+ _timeoutms + "ms").printStackTrace();
|
||||
|
||||
// also run "killall -QUIT java" to try to grab
|
||||
// a stack trace
|
||||
try {
|
||||
Runtime.getRuntime().exec
|
||||
(new String[]{ "killall", "-QUIT", "java" });
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
try {
|
||||
sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
|
||||
// now actually exit
|
||||
System.exit(111);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void enteringTest(AbstractTestCase test) {
|
||||
long timeout = test.getTimeout();
|
||||
if (timeout <= 0)
|
||||
timeout = _timeoutms;
|
||||
|
||||
_endtime = System.currentTimeMillis() + timeout;
|
||||
_curtest = test;
|
||||
|
||||
if (!isAlive())
|
||||
start();
|
||||
}
|
||||
|
||||
public synchronized void leavingTest(AbstractTestCase test) {
|
||||
_endtime = -1;
|
||||
_curtest = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,24 +20,19 @@ package org.apache.openjpa.lib.util;
|
|||
|
||||
import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests the {@link AbstractConcurrentEventManager}.
|
||||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestAbstractEventManager extends TestCase {
|
||||
public class TestAbstractEventManager {
|
||||
|
||||
private EventManager _em = new EventManager();
|
||||
|
||||
public TestAbstractEventManager(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReentrantAdd() {
|
||||
Listener l1 = new Listener(Listener.ADD);
|
||||
Listener l2 = new Listener(Listener.NONE);
|
||||
|
@ -49,6 +44,7 @@ public class TestAbstractEventManager extends TestCase {
|
|||
assertEquals(3, _em.getListeners().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReentrantRemove() {
|
||||
Listener l1 = new Listener(Listener.REMOVE);
|
||||
Listener l2 = new Listener(Listener.NONE);
|
||||
|
@ -61,14 +57,6 @@ public class TestAbstractEventManager extends TestCase {
|
|||
assertFalse(_em.getListeners().contains(l1));
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestAbstractEventManager.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
|
||||
private static class EventManager extends AbstractConcurrentEventManager {
|
||||
|
||||
|
||||
|
|
|
@ -24,25 +24,21 @@ import java.util.MissingResourceException;
|
|||
import org.apache.openjpa.lib.util.Localizer.Message;
|
||||
import org.apache.openjpa.lib.util.testlocalizer.LocalizerTestHelper;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests the Localizer.
|
||||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestLocalizer extends TestCase {
|
||||
public class TestLocalizer {
|
||||
|
||||
private Localizer _locals = null;
|
||||
|
||||
public TestLocalizer(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
_locals = Localizer.forPackage(LocalizerTestHelper.class);
|
||||
}
|
||||
|
@ -50,27 +46,30 @@ public class TestLocalizer extends TestCase {
|
|||
/**
|
||||
* Test getting a string for a class.
|
||||
*/
|
||||
@Test
|
||||
public void testForClass() {
|
||||
assertEquals(Locale.getDefault().equals(Locale.GERMANY)
|
||||
assertEqualsMSg(Locale.getDefault().equals(Locale.GERMANY)
|
||||
? "value1_de" : "value1", _locals.get("test.local1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting a string for a non-default locale.
|
||||
*/
|
||||
@Test
|
||||
public void testForLocale() {
|
||||
Localizer locl = Localizer.forPackage(LocalizerTestHelper.class,
|
||||
Locale.GERMANY);
|
||||
assertEquals("value1_de", locl.get("test.local1"));
|
||||
assertEqualsMSg("value1_de", locl.get("test.local1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that if a locale is missing the system falls back to the default.
|
||||
*/
|
||||
@Test
|
||||
public void testFallbackLocale() {
|
||||
Localizer locl = Localizer.forPackage(LocalizerTestHelper.class,
|
||||
Locale.FRANCE);
|
||||
assertEquals(Locale.getDefault().equals(Locale.GERMANY)
|
||||
assertEqualsMSg(Locale.getDefault().equals(Locale.GERMANY)
|
||||
? "value1_de" : "value1", locl.get("test.local1"));
|
||||
}
|
||||
|
||||
|
@ -78,22 +77,24 @@ public class TestLocalizer extends TestCase {
|
|||
* Tests that a null class accesses the localizer.properties file
|
||||
* for the top-level(no package).
|
||||
*/
|
||||
@Test
|
||||
public void testTopLevel() {
|
||||
Localizer system = Localizer.forPackage(null);
|
||||
assertEquals("systemvalue1", system.get("test.systemlocal"));
|
||||
assertEqualsMSg("systemvalue1", system.get("test.systemlocal"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the message formatting works correctly.
|
||||
*/
|
||||
@Test
|
||||
public void testMessageFormat() {
|
||||
String suffix = Locale.getDefault().equals(Locale.GERMANY) ? "_de" : "";
|
||||
|
||||
assertEquals("value2" + suffix + " x sep y", _locals.get("test.local2",
|
||||
assertEqualsMSg("value2" + suffix + " x sep y", _locals.get("test.local2",
|
||||
new String[]{ "x", "y" }));
|
||||
|
||||
// test that it treates single objects as single-element arrays
|
||||
assertEquals("value2" + suffix + " x sep {1}",
|
||||
assertEqualsMSg("value2" + suffix + " x sep {1}",
|
||||
_locals.get("test.local2", "x"));
|
||||
}
|
||||
|
||||
|
@ -101,10 +102,11 @@ public class TestLocalizer extends TestCase {
|
|||
* Test that a {@link MissingResourceException} is thrown for missing
|
||||
* resource bundles.
|
||||
*/
|
||||
@Test
|
||||
public void testMissingBundle() {
|
||||
Localizer missing = Localizer.forPackage(String.class);
|
||||
assertEquals("localized message key: foo.bar", missing.get("foo.bar"));
|
||||
assertEquals("localized message key: foo.bar; substitutions: [baz, 1]", missing.get("foo.bar", "baz", 1));
|
||||
assertEqualsMSg("localized message key: foo.bar", missing.get("foo.bar"));
|
||||
assertEqualsMSg("localized message key: foo.bar; substitutions: [baz, 1]", missing.get("foo.bar", "baz", 1));
|
||||
try {
|
||||
missing.getFatal("foo.bar");
|
||||
fail("No exception for fatal get on missing bundle.");
|
||||
|
@ -115,9 +117,10 @@ public class TestLocalizer extends TestCase {
|
|||
/**
|
||||
* Test that a {@link MissingResourceException} is thrown for missing keys.
|
||||
*/
|
||||
@Test
|
||||
public void testMissingKey() {
|
||||
assertEquals("localized message key: foo.bar", _locals.get("foo.bar"));
|
||||
assertEquals("localized message key: foo.bar; substitutions: [baz, 1]", _locals.get("foo.bar", "baz", 1));
|
||||
assertEqualsMSg("localized message key: foo.bar", _locals.get("foo.bar"));
|
||||
assertEqualsMSg("localized message key: foo.bar; substitutions: [baz, 1]", _locals.get("foo.bar", "baz", 1));
|
||||
try {
|
||||
_locals.getFatal("foo.bar");
|
||||
fail("No exception for fatal get on missing key.");
|
||||
|
@ -125,15 +128,8 @@ public class TestLocalizer extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public static void assertEquals(String s, Message m) {
|
||||
public static void assertEqualsMSg(String s, Message m) {
|
||||
assertEquals(s, m.getMessage());
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestLocalizer.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,27 +20,23 @@ package org.apache.openjpa.lib.util;
|
|||
|
||||
import java.net.URL;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests the {@link MultiClassLoader}.
|
||||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestMultiClassLoader extends TestCase {
|
||||
public class TestMultiClassLoader {
|
||||
|
||||
private ClassLoader SYSTEM_LOADER = MultiClassLoader.class.getClassLoader();
|
||||
|
||||
private MultiClassLoader _loader = new MultiClassLoader();
|
||||
|
||||
public TestMultiClassLoader(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
_loader.addClassLoader(MultiClassLoader.THREAD_LOADER);
|
||||
_loader.addClassLoader(SYSTEM_LOADER);
|
||||
|
@ -49,6 +45,7 @@ public class TestMultiClassLoader extends TestCase {
|
|||
/**
|
||||
* Tests basic add/remove functionality.
|
||||
*/
|
||||
@Test
|
||||
public void testBasic() {
|
||||
assertEquals(2, _loader.size());
|
||||
assertTrue(!_loader.isEmpty());
|
||||
|
@ -91,54 +88,17 @@ public class TestMultiClassLoader extends TestCase {
|
|||
assertEquals(foo2, loaders[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test finding classes.
|
||||
*/
|
||||
/*
|
||||
public void testClassForName()
|
||||
throws Exception
|
||||
{
|
||||
assertEquals(MultiClassLoader.class,
|
||||
Class.forName(MultiClassLoader.class.getName(), true, _loader));
|
||||
assertTrue(_loader.removeClassLoader(SYSTEM_LOADER));
|
||||
assertTrue(_loader.removeClassLoader(MultiClassLoader.THREAD_LOADER));
|
||||
try
|
||||
{
|
||||
// have to switch classes here b/c other is now cached
|
||||
assertEquals(TestMultiClassLoader.class, Class.forName
|
||||
(TestMultiClassLoader.class.getName(), true, _loader));
|
||||
fail("System class laoder still working.");
|
||||
} catch (ClassNotFoundException cnfe)
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
Class.forName("foo", true, _loader);
|
||||
fail("Somehow found 'foo'???");
|
||||
} catch (ClassNotFoundException cnfe)
|
||||
{
|
||||
}
|
||||
_loader.addClassLoader(new FooLoader());
|
||||
assertEquals(Integer.class, Class.forName("foo", true, _loader));
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test finding resources.
|
||||
*/
|
||||
@Test
|
||||
public void testGetResource() {
|
||||
assertNull(_loader.getResource("foo"));
|
||||
_loader.addClassLoader(new FooLoader());
|
||||
assertNotNull(_loader.getResource("foo"));
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestMultiClassLoader.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
|
||||
private static final class FooLoader extends ClassLoader {
|
||||
|
||||
|
|
|
@ -20,17 +20,17 @@ package org.apache.openjpa.lib.util;
|
|||
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the {@link Options} type.
|
||||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestOptions extends TestCase {
|
||||
public class TestOptions {
|
||||
|
||||
private Options _opts = null;
|
||||
|
||||
|
@ -39,11 +39,7 @@ public class TestOptions extends TestCase {
|
|||
"-range2", "10", "-fieldVal", "20", "-FieldVal2", "30",
|
||||
"-inner.nullInner.range1", "10,100", "arg1", "arg2", "arg3" };
|
||||
|
||||
public TestOptions(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
Properties defs = new Properties();
|
||||
defs.setProperty("default", "value");
|
||||
|
@ -54,6 +50,7 @@ public class TestOptions extends TestCase {
|
|||
/**
|
||||
* Test command-line parsing.
|
||||
*/
|
||||
@Test
|
||||
public void testCmdLineParsing() {
|
||||
assertEquals(3, _args.length);
|
||||
assertEquals("arg1", _args[0]);
|
||||
|
@ -78,6 +75,7 @@ public class TestOptions extends TestCase {
|
|||
/**
|
||||
* Tests the setting of option values into bean objects.
|
||||
*/
|
||||
@Test
|
||||
public void testSetObject() {
|
||||
Inner inner = new Inner();
|
||||
_opts.setInto(inner);
|
||||
|
@ -110,14 +108,6 @@ public class TestOptions extends TestCase {
|
|||
assertEquals("STR", inner.getString());
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestOptions.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
|
||||
/**
|
||||
* Used internally for testing; must be public so Options can construct it.
|
||||
*/
|
||||
|
|
|
@ -18,24 +18,21 @@
|
|||
*/
|
||||
package org.apache.openjpa.lib.util;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests the {@link ParameterTemplate} utility class.
|
||||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestParameterTemplate extends TestCase {
|
||||
public class TestParameterTemplate {
|
||||
|
||||
private ParameterTemplate templ = new ParameterTemplate();
|
||||
|
||||
public TestParameterTemplate(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameters() {
|
||||
templ.append("{foo$${foo}bar{${bar}}biz baz$");
|
||||
templ.append("{booz}booz${java.io.tmpdir}{ack}");
|
||||
|
@ -55,12 +52,5 @@ public class TestParameterTemplate extends TestCase {
|
|||
templ.toString());
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestParameterTemplate.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,9 @@ import java.util.Properties;
|
|||
import org.apache.openjpa.lib.util.FormatPreservingProperties.
|
||||
DuplicateKeyException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
// things to test:
|
||||
// - delimiters in keys
|
||||
|
@ -45,10 +47,11 @@ import junit.framework.TestCase;
|
|||
// - non-String keys / vals
|
||||
// - list() method behavior
|
||||
|
||||
public class TestPropertiesParser extends TestCase {
|
||||
public class TestPropertiesParser {
|
||||
|
||||
private static final String LS = System.getProperty( "line.separator" );
|
||||
|
||||
@Test
|
||||
public void testSimpleProperties() throws IOException {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("key: value" + LS);
|
||||
|
@ -58,6 +61,7 @@ public class TestPropertiesParser extends TestCase {
|
|||
{ "key", "value" }, { "key2", "value2" } }, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComments() throws IOException {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("# this is a comment" + LS);
|
||||
|
@ -70,6 +74,7 @@ public class TestPropertiesParser extends TestCase {
|
|||
assertEquals(0, p.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedContent() throws IOException {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("# this is a comment" + LS);
|
||||
|
@ -81,6 +86,7 @@ public class TestPropertiesParser extends TestCase {
|
|||
assertProperties(new String[][]{ { "foo", "bar#baz" } }, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiLineInput() throws IOException {
|
||||
String s = "foo: bar\\" + LS + "more line goes here";
|
||||
Properties p = toProperties(s);
|
||||
|
@ -88,12 +94,14 @@ public class TestPropertiesParser extends TestCase {
|
|||
new String[][]{ { "foo", "barmore line goes here" } }, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyLines() throws IOException {
|
||||
Properties p = toProperties(LS + "foo: bar" + LS + LS + "baz: val");
|
||||
assertProperties(new String[][]{ { "foo", "bar" }, { "baz", "val" } },
|
||||
p);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddProperties() throws IOException {
|
||||
// intentionally left out the trailing end line
|
||||
String s = "foo: bar" + LS + "baz: val";
|
||||
|
@ -108,6 +116,7 @@ public class TestPropertiesParser extends TestCase {
|
|||
"another-new-key: val3" + LS, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAndMutateProperties() throws IOException {
|
||||
// intentionally left out the trailing end line
|
||||
Properties p = toProperties("foo: bar" + LS + "baz: val");
|
||||
|
@ -120,11 +129,13 @@ public class TestPropertiesParser extends TestCase {
|
|||
+ "new-key: new value" + LS, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscapedEquals() throws IOException {
|
||||
Properties p = toProperties("foo=bar\\=WARN,baz\\=TRACE");
|
||||
assertProperties(new String[][]{ { "foo", "bar=WARN,baz=TRACE" } }, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLineTypes() throws IOException {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append(" !comment" + LS + " \t " + LS + "name = no" + LS + " "
|
||||
|
@ -140,6 +151,7 @@ public class TestPropertiesParser extends TestCase {
|
|||
}, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialChars() throws Throwable {
|
||||
testSpecialChars(false, true);
|
||||
testSpecialChars(true, true);
|
||||
|
@ -155,7 +167,7 @@ public class TestPropertiesParser extends TestCase {
|
|||
* against a normal Properties instance(for validation of the test case).
|
||||
* @param value whether to test the key or the value
|
||||
*/
|
||||
public void testSpecialChars(boolean formattingProps, boolean value)
|
||||
private void testSpecialChars(boolean formattingProps, boolean value)
|
||||
throws Throwable {
|
||||
List valueList = new ArrayList(Arrays.asList(new String[]{
|
||||
"xxyy", "xx\\yy", "xx" + LS + "yy", "xx\\nyy", "xx\tyy", "xx\\tyy",
|
||||
|
@ -246,6 +258,7 @@ public class TestPropertiesParser extends TestCase {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquivalentStore() throws IOException {
|
||||
Properties p1 = new Properties();
|
||||
FormatPreservingProperties p2 = new FormatPreservingProperties();
|
||||
|
@ -308,6 +321,7 @@ public class TestPropertiesParser extends TestCase {
|
|||
return sbuf.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateProperties() throws IOException {
|
||||
FormatPreservingProperties p = new FormatPreservingProperties();
|
||||
try {
|
||||
|
@ -324,6 +338,7 @@ public class TestPropertiesParser extends TestCase {
|
|||
assertProperties(new String[][]{ { "foo", "baz" } }, p);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleLoads() throws IOException {
|
||||
String props = "foo=bar" + LS + "baz=quux";
|
||||
String props2 = "a=b" + LS + "c=d";
|
||||
|
@ -381,13 +396,6 @@ public class TestPropertiesParser extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public static void assertEquals(String expected, String actual) {
|
||||
if (expected == actual)
|
||||
return;
|
||||
|
||||
if (expected == null || !expected.equals(actual))
|
||||
fail("Expected <" + expected + "> but was <" + actual + ">");
|
||||
}
|
||||
|
||||
private void assertPropertiesSame(Properties vanilla, Properties p) {
|
||||
assertEquals(vanilla, p);
|
||||
|
|
|
@ -23,24 +23,23 @@ import java.util.Iterator;
|
|||
|
||||
import org.apache.commons.collections4.map.AbstractReferenceMap.ReferenceStrength;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests the {@link ReferenceHashSet}.
|
||||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestReferenceSet extends TestCase {
|
||||
public class TestReferenceSet {
|
||||
|
||||
private ReferenceHashSet _coll = new ReferenceHashSet(ReferenceStrength.WEAK);
|
||||
|
||||
private Object _heldValue = new Integer(2);
|
||||
|
||||
public TestReferenceSet(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
_coll.add(_heldValue);
|
||||
_coll.add(new Integer(1));
|
||||
|
@ -49,6 +48,7 @@ public class TestReferenceSet extends TestCase {
|
|||
/**
|
||||
* Tests basic add/contains/remove functionality.
|
||||
*/
|
||||
@Test
|
||||
public void testBasics() {
|
||||
Collection coll = new ReferenceHashSet(ReferenceStrength.WEAK);
|
||||
assertEquals(0, coll.size());
|
||||
|
@ -69,6 +69,7 @@ public class TestReferenceSet extends TestCase {
|
|||
/**
|
||||
* Test that values with strong references are not gc'd.
|
||||
*/
|
||||
@Test
|
||||
public void testHeldReference() {
|
||||
if (JavaVersions.VERSION >= 5)
|
||||
return;
|
||||
|
@ -81,6 +82,7 @@ public class TestReferenceSet extends TestCase {
|
|||
/**
|
||||
* Test that weak references are gc'd.
|
||||
*/
|
||||
@Test
|
||||
public void testWeakReference() {
|
||||
if (JavaVersions.VERSION >= 5)
|
||||
return;
|
||||
|
@ -106,6 +108,7 @@ public class TestReferenceSet extends TestCase {
|
|||
/**
|
||||
* Test that values that have been replaced aren't expired.
|
||||
*/
|
||||
@Test
|
||||
public void testChangeValue() {
|
||||
if (JavaVersions.VERSION >= 5)
|
||||
return;
|
||||
|
|
|
@ -18,21 +18,23 @@
|
|||
*/
|
||||
package org.apache.openjpa.lib.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.textui.TestRunner;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests simple regex for use in in-memory query execution.
|
||||
*
|
||||
* @author Greg Campbell
|
||||
*/
|
||||
public class TestSimpleRegex extends TestCase {
|
||||
public class TestSimpleRegex {
|
||||
|
||||
private boolean matchExpr(String target, String expr, boolean caseInsens) {
|
||||
SimpleRegex re = new SimpleRegex(expr, caseInsens);
|
||||
return re.matches(target);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWildcards() {
|
||||
assertTrue(matchExpr("Hello", "Hello", false));
|
||||
assertFalse(matchExpr("Hello", "Bye", false));
|
||||
|
@ -66,7 +68,4 @@ public class TestSimpleRegex extends TestCase {
|
|||
assertFalse(matchExpr("Hellow", ".*YoHello", false));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(TestSimpleRegex.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,13 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestTemporaryClassLoader extends TestCase {
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestTemporaryClassLoader {
|
||||
|
||||
@Test
|
||||
public void testTemporaryClassLoader() throws Exception {
|
||||
Set s = new HashSet();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
|
|
@ -18,26 +18,22 @@
|
|||
*/
|
||||
package org.apache.openjpa.lib.util;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests the {@link TypedProperties} type.
|
||||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestTypedProperties extends TestCase {
|
||||
public class TestTypedProperties {
|
||||
|
||||
private TypedProperties _props = null;
|
||||
private TypedProperties _defs = null;
|
||||
|
||||
public TestTypedProperties(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
_props = new TypedProperties();
|
||||
_props.setProperty("bool", "true");
|
||||
|
@ -52,6 +48,7 @@ public class TestTypedProperties extends TestCase {
|
|||
/**
|
||||
* Tests basic typed gets.
|
||||
*/
|
||||
@Test
|
||||
public void testTypes() {
|
||||
assertTrue(_props.getBooleanProperty("bool"));
|
||||
assertEquals(1, _props.getIntProperty("int"));
|
||||
|
@ -64,6 +61,7 @@ public class TestTypedProperties extends TestCase {
|
|||
/**
|
||||
* Tests the defaults returned for missing keys.
|
||||
*/
|
||||
@Test
|
||||
public void testNoDefaults() {
|
||||
assertTrue(!_props.getBooleanProperty("bool2"));
|
||||
assertEquals(0, _props.getIntProperty("int2"));
|
||||
|
@ -77,6 +75,7 @@ public class TestTypedProperties extends TestCase {
|
|||
* Tests the defaults returned by keys found in the default
|
||||
* backing properties instance.
|
||||
*/
|
||||
@Test
|
||||
public void testDefaults() {
|
||||
assertTrue(_defs.getBooleanProperty("bool"));
|
||||
assertEquals(1, _defs.getIntProperty("int"));
|
||||
|
@ -89,6 +88,7 @@ public class TestTypedProperties extends TestCase {
|
|||
/**
|
||||
* Tests that given defaults works.
|
||||
*/
|
||||
@Test
|
||||
public void testGivenDefaults() {
|
||||
assertTrue(_props.getBooleanProperty("bool2", true));
|
||||
assertEquals(1, _props.getIntProperty("int2", 1));
|
||||
|
@ -105,11 +105,4 @@ public class TestTypedProperties extends TestCase {
|
|||
assertEquals("2.2", _defs.getProperty("double", "3.3"));
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestTypedProperties.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,15 +24,18 @@ import java.security.PrivilegedExceptionAction;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test UUID generation.
|
||||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestUUIDGenerator extends TestCase {
|
||||
public class TestUUIDGenerator {
|
||||
|
||||
@Test
|
||||
public void testUniqueString() {
|
||||
Set seen = new HashSet();
|
||||
for (int i = 0; i < 10000; i++)
|
||||
|
@ -40,6 +43,7 @@ public class TestUUIDGenerator extends TestCase {
|
|||
UUIDGenerator.nextString(UUIDGenerator.TYPE1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueHex() {
|
||||
Set seen = new HashSet();
|
||||
for (int i = 0; i < 10000; i++)
|
||||
|
@ -47,6 +51,7 @@ public class TestUUIDGenerator extends TestCase {
|
|||
UUIDGenerator.nextHex(UUIDGenerator.TYPE1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueType4String() {
|
||||
Set seen = new HashSet();
|
||||
for (int i = 0; i < 10000; i++)
|
||||
|
@ -54,6 +59,7 @@ public class TestUUIDGenerator extends TestCase {
|
|||
UUIDGenerator.nextString(UUIDGenerator.TYPE4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueType4Hex() {
|
||||
Set seen = new HashSet();
|
||||
for (int i = 0; i < 10000; i++)
|
||||
|
@ -61,6 +67,7 @@ public class TestUUIDGenerator extends TestCase {
|
|||
UUIDGenerator.nextHex(UUIDGenerator.TYPE4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueMixedTypesHex() {
|
||||
Set seen = new HashSet();
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
|
@ -71,6 +78,7 @@ public class TestUUIDGenerator extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTime() {
|
||||
long time = 0;
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
|
@ -80,6 +88,7 @@ public class TestUUIDGenerator extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitType1MultiThreaded() throws Exception {
|
||||
// This test method depends IP and RANDOM in UUIDGenerator to be null
|
||||
// and type1Initialized to be false. Using reflection to ensure that
|
||||
|
|
|
@ -18,50 +18,46 @@
|
|||
*/
|
||||
package org.apache.openjpa.lib.util.svn;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
public class TestSVNUtils extends TestCase {
|
||||
public TestSVNUtils(String s) {
|
||||
super(s);
|
||||
}
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestSVNUtils {
|
||||
|
||||
@Test
|
||||
public void testNull() {
|
||||
assertEquals(-1, SVNUtils.svnInfoToInteger(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic() {
|
||||
int i = 12345678;
|
||||
assertEquals(i, SVNUtils.svnInfoToInteger(i + ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGoodTrailingString() {
|
||||
int i = 12345678;
|
||||
assertEquals(i, SVNUtils.svnInfoToInteger(i + "m"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedRevision() {
|
||||
int i = 12345678;
|
||||
assertEquals(i, SVNUtils.svnInfoToInteger("55555:" + i));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedRevisionTrailingString() {
|
||||
int i = 12345678;
|
||||
assertEquals(i, SVNUtils.svnInfoToInteger("55555:" + i + "MS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBad() {
|
||||
int i = 12345678;
|
||||
assertEquals(-1, SVNUtils.svnInfoToInteger("55555:aa" + i + "ms"));
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestSVNUtils.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,15 +26,15 @@ import java.io.Writer;
|
|||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the {@link DocTypeReader} by comparing the results of passing
|
||||
|
@ -42,7 +42,7 @@ import junit.textui.TestRunner;
|
|||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestDocTypeReader extends TestCase {
|
||||
public class TestDocTypeReader {
|
||||
|
||||
private String _docType = null;
|
||||
private String _validXML = null;
|
||||
|
@ -52,11 +52,8 @@ public class TestDocTypeReader extends TestCase {
|
|||
private String _expectedHTML = null;
|
||||
private String _xmlWithDocType = null;
|
||||
|
||||
public TestDocTypeReader(String test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
StringBuffer docType = new StringBuffer();
|
||||
docType.append("<!DOCTYPE foo [\n");
|
||||
|
@ -110,6 +107,7 @@ public class TestDocTypeReader extends TestCase {
|
|||
/**
|
||||
* Test against expected doc type inclusion behavior.
|
||||
*/
|
||||
@Test
|
||||
public void testIncludesDocType() throws IOException {
|
||||
assertEquals(_validXML, getIncludedString(_validXML, null, 1));
|
||||
assertEquals(_validXML, getIncludedString(_validXML, null, 7));
|
||||
|
@ -131,6 +129,7 @@ public class TestDocTypeReader extends TestCase {
|
|||
* Test that the doc type declaration is not included in files with
|
||||
* doc types.
|
||||
*/
|
||||
@Test
|
||||
public void testStreamWithDocType() throws IOException {
|
||||
assertEquals(_xmlWithDocType, getIncludedString
|
||||
(_xmlWithDocType, null, 1));
|
||||
|
@ -176,6 +175,7 @@ public class TestDocTypeReader extends TestCase {
|
|||
/**
|
||||
* Test that validation occurs correctly.
|
||||
*/
|
||||
@Test
|
||||
public void testValidation() throws IOException, SAXException {
|
||||
SAXParser parser = XMLFactory.getSAXParser(false, false);
|
||||
InputSource source = new InputSource();
|
||||
|
@ -199,13 +199,6 @@ public class TestDocTypeReader extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestDocTypeReader.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
|
||||
private static class Handler extends DefaultHandler {
|
||||
|
||||
|
|
|
@ -27,11 +27,10 @@ import javax.xml.transform.stream.StreamResult;
|
|||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.apache.openjpa.lib.util.StringUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
/**
|
||||
* Tests the {@link XMLWriter} by comparing the results of passing the
|
||||
|
@ -40,15 +39,12 @@ import junit.textui.TestRunner;
|
|||
*
|
||||
* @author Abe White
|
||||
*/
|
||||
public class TestXMLWriter extends TestCase {
|
||||
|
||||
public TestXMLWriter(String test) {
|
||||
super(test);
|
||||
}
|
||||
public class TestXMLWriter {
|
||||
|
||||
/**
|
||||
* Tests the formatting works.
|
||||
*/
|
||||
@Test
|
||||
public void testPrettyPrint() throws Exception {
|
||||
// get the raw xml from a file
|
||||
StreamSource source = new StreamSource
|
||||
|
@ -76,11 +72,4 @@ public class TestXMLWriter extends TestCase {
|
|||
return StringUtil.join(StringUtil.split(str, "\r\n", -1), "\n");
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(TestXMLWriter.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(suite());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue