libjboss-common-java-0.0+svn2938.orig/ 0000755 0001750 0001750 00000000000 11105642377 017420 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/ 0000755 0001750 0001750 00000000000 11105642366 021634 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/ 0000755 0001750 0001750 00000000000 11105642362 022417 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/test/ 0000755 0001750 0001750 00000000000 11105642362 023376 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/ 0000755 0001750 0001750 00000000000 11105642361 024316 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/ 0000755 0001750 0001750 00000000000 11105642361 025105 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/ 0000755 0001750 0001750 00000000000 11105642361 026225 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/ 0000755 0001750 0001750 00000000000 11105642361 027204 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/ 0000755 0001750 0001750 00000000000 11105642361 030161 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/ 0000755 0001750 0001750 00000000000 11105642362 031141 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/xml/ 0000755 0001750 0001750 00000000000 11105642361 031740 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011567 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/xml/resolver/ libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/xml/resolve0000755 0001750 0001750 00000000000 11105642361 033340 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000213 00000000000 011561 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/xml/resolver/JBossEntityResolverUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/xml/resolve0000644 0001750 0001750 00000011441 10776055124 033353 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.xml.resolver;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.jboss.util.xml.JBossEntityResolver;
import org.xml.sax.InputSource;
import junit.framework.TestCase;
/**
* A JBossEntityResolverUnitTestCase.
*
* @author Alexey Loubyansky
* @version $Revision: 1.1 $
*/
public class JBossEntityResolverUnitTestCase
extends TestCase
{
public JBossEntityResolverUnitTestCase(String arg0)
{
super(arg0);
}
/**
* The spcial thing about the resolution of xsd:redefine is that
* the parser passes the namespace of the redefining schema as publicId
* and the schema location of the redefined schema as systemId. Now, if
* the redefining schema's namespace has already been mapped
* to a schema location of the redefining schema then schema location
* argument is ignored and the redefining schema is returned instead of the
* redefined schema.
*
* @throws Exception
*/
public void testResolveRedefine() throws Exception
{
String baseName = getRootName() + "_" + getName() + "_";
String redefiningName = baseName + "redefining.xsd";
InputStream redefiningStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(redefiningName);
assertNotNull("Expected to find " + redefiningName + " in the classpath", redefiningStream);
int redefiningSize = bytesTotal(redefiningStream);
String redefinedName = baseName + "redefined.xsd";
InputStream redefinedStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(redefinedName);
assertNotNull("Expected to find " + redefinedName + " in the classpath", redefinedStream);
int redefinedSize = bytesTotal(redefinedStream);
assertTrue(redefiningSize != redefinedSize);
JBossEntityResolver resolver = new JBossEntityResolver();
resolver.registerLocalEntity("urn:jboss:xml:test", redefiningName);
InputSource resolvedSource = resolver.resolveEntity("urn:jboss:xml:test", redefinedName);
assertNotNull(resolvedSource);
InputStream resolvedStream = resolvedSource.getByteStream();
assertNotNull(resolvedStream);
int resolvedSize = bytesTotal(resolvedStream);
assertEquals("Schema sizes: redefined=" + redefinedSize + ", redefining=" + redefiningSize, redefinedSize, resolvedSize);
}
public void testSystemPropertyInSystemID()
throws Exception
{
JBossEntityResolver resolver = new JBossEntityResolver();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL tstConfig = loader.getResource("tst-config_5.xsd");
assertNotNull(tstConfig);
System.setProperty("tst.config_5.xsd", tstConfig.toExternalForm());
InputSource resolvedSource = resolver.resolveEntity("urn:jboss:xml:test", "${tst.config_5.xsd}");
assertNotNull(resolvedSource);
InputStream resolvedStream = resolvedSource.getByteStream();
assertNotNull(resolvedStream);
int resolvedSize = bytesTotal(resolvedStream);
assertEquals(280, resolvedSize);
}
private int bytesTotal(InputStream redefinedStream) throws IOException
{
byte[] bytes = new byte[1024];
int redefinedSize = 0;
try
{
for(int i = 0; (i = redefinedStream.read(bytes)) > 0; redefinedSize += i);
}
finally
{
redefinedStream.close();
}
return redefinedSize;
}
protected String getRootName()
{
String longName = getClass().getName();
int dot = longName.lastIndexOf('.');
if (dot != -1)
return longName.substring(dot + 1);
return longName;
}
}
././@LongLink 0000000 0000000 0000000 00000000164 00000000000 011566 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/xml/DOMWriterTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/xml/DOMWrit0000644 0001750 0001750 00000023241 11044361066 033154 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.xml;
// $Id: DOMWriterTestCase.java 2891 2008-07-31 16:03:02Z thomas.diesler@jboss.com $
import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import javax.xml.namespace.QName;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stream.StreamSource;
import junit.framework.TestCase;
import org.jboss.util.xml.DOMUtils;
import org.jboss.util.xml.DOMWriter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Test the DOMWriter
*
* @author Thomas.Diesler@jboss.org
* @since 10-Aug-2006
*/
public class DOMWriterTestCase extends TestCase
{
/** The element does not contain the required ns declaration.
*/
public void testNamespaceCompletionOne() throws Exception
{
String inStr =
"" +
"" +
"" +
"env:Client" +
"Endpoint {http://webmethod.jsr181.ws.test.jboss.org/jaws}TestEndpointPort does not contain operation meta data for: {http://webmethod.jsr181.ws.test.jboss.org/jaws}noWebMethod" +
"" +
"" +
"";
Element env = DOMUtils.parse(inStr);
Element body = DOMUtils.getFirstChildElement(env);
Element fault = DOMUtils.getFirstChildElement(body);
String expStr =
"" +
"env:Client" +
"Endpoint {http://webmethod.jsr181.ws.test.jboss.org/jaws}TestEndpointPort does not contain operation meta data for: {http://webmethod.jsr181.ws.test.jboss.org/jaws}noWebMethod" +
"";
String wasStr = DOMWriter.printNode(fault, false);
assertEquals(expStr, wasStr);
}
/** The element already contains the required ns declaration.
*/
public void testNamespaceCompletionTwo() throws Exception
{
String inStr =
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
Element env = DOMUtils.parse(inStr);
Element body = DOMUtils.getFirstChildElement(env);
Element rpc = DOMUtils.getFirstChildElement(body);
String expStr =
"" +
"" +
"" +
"";
String wasStr = DOMWriter.printNode(rpc, false);
assertEquals(expStr, wasStr);
}
/** The element does not contain the required ns declaration, the child does.
*/
public void testNamespaceCompletionThree() throws Exception
{
String inStr =
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
Element env = DOMUtils.parse(inStr);
Element body = DOMUtils.getFirstChildElement(env);
String expStr =
"" +
"" +
"" +
"" +
"" +
"";
String wasStr = DOMWriter.printNode(body, false);
assertEquals(expStr, wasStr);
}
/** The envelope defines a default namespace
*/
public void testNamespaceCompletionDefault() throws Exception
{
String inStr =
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"";
Element env = DOMUtils.parse(inStr);
Element body = DOMUtils.getFirstChildElement(env);
Element rpc = DOMUtils.getFirstChildElement(body);
String expStr =
"" +
"" +
"" +
"";
String wasStr = DOMWriter.printNode(rpc, false);
assertEquals(expStr, wasStr);
}
/** The element does not contain the required attribute ns declaration.
*/
public void testNamespaceCompletionAttribute() throws Exception
{
String inStr =
"" +
"" +
"" +
"" +
"" +
"";
Element env = DOMUtils.parse(inStr);
Element header = DOMUtils.getFirstChildElement(env);
Element headerElement = DOMUtils.getFirstChildElement(header);
String expStr =
"";
String wasStr = DOMWriter.printNode(headerElement, false);
assertEquals(expStr, wasStr);
}
public void testEntity() throws Exception
{
String expStr =
"" +
"" +
"" +
"" +
"" +
"";
Element domEl = DOMUtils.parse(expStr);
String wasStr = DOMWriter.printNode(domEl, false);
assertEquals(expStr, wasStr);
}
// [JBWS-762] DOMUtils.parse skips peer comments on Document node
public void testDocumentComments() throws Exception
{
String expStr =
"" +
"" +
"" +
"" +
"some value" +
"";
Document doc = DOMUtils.parse(expStr).getOwnerDocument();
StringWriter strwr = new StringWriter();
new DOMWriter(strwr, "UTF-8").print(doc);
String wasStr = strwr.toString();
assertEquals(expStr, wasStr);
}
public void testElementNamespaceURIElementNS() throws Exception
{
String xmlIn = "World";
Element root = DOMUtils.createElement(new QName("http://somens", "Hello"));
assertEquals("http://somens", root.getNamespaceURI());
Element child = (Element)root.appendChild(DOMUtils.createElement(new QName("Sub")));
child.appendChild(DOMUtils.createTextNode("World"));
String xmlOut = DOMWriter.printNode(root, false);
assertEquals(xmlIn, xmlOut);
}
public void testElementNamespaceURIDocumentParse() throws Exception
{
String xmlIn = "World";
Element root = DOMUtils.parse(xmlIn);
assertEquals("http://somens", root.getNamespaceURI());
String xmlOut = DOMWriter.printNode(root, false);
assertEquals(xmlIn, xmlOut);
}
public void testElementNamespaceURITransformer() throws Exception
{
String xmlIn = "World";
StreamSource source = new StreamSource(new ByteArrayInputStream(xmlIn.getBytes()));
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
DOMResult result = new DOMResult();
transformer.transform(source, result);
Element root = ((Document)result.getNode()).getDocumentElement();
assertEquals("http://somens", root.getNamespaceURI());
String xmlOut = DOMWriter.printNode(root, false);
assertEquals(xmlIn, xmlOut);
}
public void testWhiteSpaceRemove() throws Exception
{
String xmlIn = " World ";
Element root = DOMUtils.parse(xmlIn);
root.normalize();
StringWriter strwr = new StringWriter();
new DOMWriter(strwr).setIgnoreWhitespace(true).print(root);
String xmlOut = strwr.toString();
assertEquals("World", xmlOut);
}
}
libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/graph/ 0000755 0001750 0001750 00000000000 11105642361 032241 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000162 00000000000 011564 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/graph/GraphTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/graph/Graph0000644 0001750 0001750 00000022526 10774222622 033241 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.graph;
import java.util.ArrayList;
import java.util.Comparator;
import junit.framework.TestCase;
import org.jboss.util.graph.Graph;
import org.jboss.util.graph.Edge;
import org.jboss.util.graph.Vertex;
import org.jboss.util.graph.Visitor;
/**
* Tests of the graph package
*
* @author Scott.Stark@jboss.org
* @version $Revision: 1.1 $
*/
@SuppressWarnings("unchecked")
public class GraphTestCase extends TestCase
{
Vertex a = new Vertex("A", "x.ear");
Vertex b = new Vertex("B");
Vertex c = new Vertex("C");
Vertex d = new Vertex("D");
Vertex e = new Vertex("E");
Vertex f = new Vertex("F");
Vertex g = new Vertex("G");
Vertex h = new Vertex("H");
Vertex i = new Vertex("I");
Vertex ear = new Vertex("x", "x.ear");
Vertex e1 = new Vertex("e1", "e1.jar");
Vertex e2 = new Vertex("e2", "e2.jar");
Vertex w1 = new Vertex("w1", "w1.war");
public GraphTestCase(String name)
{
super(name);
}
/** Depth first search of digraph1
* @throws Exception
*/
public void testDFS()
throws Exception
{
Graph graph = buildGraph1();
final ArrayList order = new ArrayList();
Visitor visitor = new Visitor()
{
public void visit(Graph g, Vertex v)
{
System.out.println("visit "+v.getName());
order.add(v);
}
};
graph.depthFirstSearch(a, visitor);
assertTrue("Visted count == 8("+order.size()+")", order.size() == 8);
// Validate the expected order and visited state
for(int n = 0; n < order.size(); n ++)
{
Vertex v = (Vertex) order.get(n);
System.out.println(v);
assertTrue(v.getName()+" is visited", v.visited());
}
String[] names = {"A", "B", "C", "H", "G", "I", "E", "F"};
for(int n = 0; n < order.size(); n ++)
{
Vertex v = (Vertex) order.get(n);
assertTrue("#"+n+" is "+names[n]+"("+v.getName()+")",
v.getName().equals(names[n]));
}
}
/** Breadth first search of digraph1
* @throws Exception
*/
public void testBFS()
throws Exception
{
Graph graph = buildGraph1();
final ArrayList order = new ArrayList();
Visitor visitor = new Visitor()
{
public void visit(Graph g, Vertex v)
{
System.out.println("visit "+v.getName());
order.add(v);
}
};
graph.breadthFirstSearch(a, visitor);
assertTrue("Visted count == 8("+order.size()+")", order.size() == 8);
// Validate the expected order and visited state
for(int n = 0; n < order.size(); n ++)
{
Vertex v = order.get(n);
System.out.println(v);
assertTrue(v.getName()+" is visited", v.visited());
}
String[] names = {"A", "B", "F", "C", "G", "E", "I", "H"};
for(int n = 0; n < order.size(); n ++)
{
Vertex v = order.get(n);
assertTrue("#"+n+" is "+names[n]+"("+v.getName()+")",
v.getName().equals(names[n]));
}
}
public void testCycleDection()
{
Graph g = new Graph();
Vertex v0 = new Vertex("V0");
Vertex v1 = new Vertex("V1");
Vertex v2 = new Vertex("V2");
g.addVertex(v0);
g.addVertex(v1);
g.addVertex(v2);
g.addEdge(v0, v1, 0);
g.addEdge(v1, v2, 0);
g.addEdge(v2, v0, 0);
Edge[] cycleEdges = g.findCycles();
assertTrue("There is a cycle", cycleEdges.length == 1);
for(int n = 0; n < cycleEdges.length; n ++)
System.out.println(cycleEdges[n]);
Edge e = cycleEdges[0];
Vertex vx = e.getFrom();
Vertex vy = e.getTo();
assertTrue("Cycle edge is V2->V0", vx.getName().equals("V2")
&& vy.getName().equals("V0"));
}
public void testEdges()
{
Graph g = new Graph();
assertTrue(g.addVertex(ear));
assertFalse(g.addVertex(ear));
assertEquals("size == 1", 1, g.size());
try
{
g.addEdge(ear, e1, 0);
fail("Should have seen IllegalArgumentException");
}
catch(IllegalArgumentException e)
{
System.out.println("Saw IAE as expected");
}
assertTrue("Added e1", g.addVertex(e1));
assertTrue("Added E(ear, e1)", g.addEdge(ear, e1, 0));
assertFalse("Did not readded E(ear, e1)", g.addEdge(ear, e1, 0));
assertTrue("Added e2", g.addVertex(e2));
assertTrue("Added w1", g.addVertex(w1));
assertTrue("Added E(ear, e2)", g.addEdge(ear, e2, 0));
assertTrue("Added E(ear, w1)", g.addEdge(ear, w1, 0));
Edge[] cycles = g.findCycles();
assertEquals("cycles.length = 0", 0, cycles.length);
}
public void testFindByName()
{
Graph g = buildEarGraph();
Vertex v = g.findVertexByName("x");
assertEquals("x", ear, v);
v = g.findVertexByName("e1");
assertEquals("e1", e1, v);
v = g.findVertexByName("e2");
assertEquals("e2", e2, v);
v = g.findVertexByName("w1");
assertEquals("w1", w1, v);
v = g.findVertexByName("w1.war");
assertTrue("w1.war not found", v == null);
}
public void testFindByData()
{
Graph g = buildEarGraph();
Comparator SC = new Comparator()
{
public int compare(String s1, String s2)
{
int compare;
if( s1 == s2 )
compare = 0;
else if( s1 == null )
compare = 1;
else if( s2 == null )
compare = -1;
else
compare = s1.compareTo(s2);
return compare;
}
};
Vertex v = g.findVertexByData("x.ear", SC);
assertEquals("x.ear", ear, v);
v = g.findVertexByData("e1.jar", SC);
assertEquals("e1.jar", e1, v);
v = g.findVertexByData("e2.jar", SC);
assertEquals("e2.jar", e2, v);
v = g.findVertexByData("w1.war", SC);
assertEquals("w1.war", w1, v);
v = g.findVertexByData("w1", SC);
assertTrue("w1 not found", v == null);
}
/** Build the following digraph:
A : B, F
B : C, G
C : H
D : E, H
E :
F : E, I
G : A
H : G, I
I : E, G
*/
private Graph buildGraph1()
{
Graph graph = new Graph();
assertTrue("Added A", graph.addVertex(a));
assertTrue("Added B", graph.addVertex(b));
assertTrue("Added C", graph.addVertex(c));
assertTrue("Added D", graph.addVertex(d));
assertTrue("Added E", graph.addVertex(e));
assertTrue("Added F", graph.addVertex(f));
assertTrue("Added G", graph.addVertex(g));
assertTrue("Added H", graph.addVertex(h));
assertTrue("Added I", graph.addVertex(i));
// A : B, F
assertTrue("Added A -> B", graph.addEdge(a, b, 0));
assertTrue("Added A -> F", graph.addEdge(a, f, 0));
// B : C, G
assertTrue("Added B -> C", graph.addEdge(b, c, 0));
assertTrue("Added B -> G", graph.addEdge(b, g, 0));
// C : H
assertTrue("Added C -> H", graph.addEdge(c, h, 0));
// D : E, H
assertTrue("Added D -> E", graph.addEdge(d, e, 0));
assertTrue("Added D -> H", graph.addEdge(d, h, 0));
// F : E, I
assertTrue("Added F -> E", graph.addEdge(f, e, 0));
assertTrue("Added F -> I", graph.addEdge(f, i, 0));
// G : A
assertTrue("Added G -> A", graph.addEdge(g, a, 0));
// H : G, I
assertTrue("Added H -> G", graph.addEdge(h, g, 0));
assertTrue("Added H -> I", graph.addEdge(h, i, 0));
// I : E, G
assertTrue("Added I -> E", graph.addEdge(i, e, 0));
assertTrue("Added I -> G", graph.addEdge(i, g, 0));
assertTrue("Graph has 9 verticies", graph.size() == 9);
return graph;
}
/** Build the following digraph:
x.ear : e1.jar, e2.jar, w1.war
*/
private Graph buildEarGraph()
{
Graph g = new Graph();
assertTrue(g.addVertex(ear));
assertFalse(g.addVertex(ear));
assertTrue("Added e1", g.addVertex(e1));
assertTrue("Added E(ear, e1)", g.addEdge(ear, e1, 0));
assertTrue("Added e2", g.addVertex(e2));
assertTrue("Added w1", g.addVertex(w1));
assertTrue("Added E(ear, e2)", g.addEdge(ear, e2, 0));
assertTrue("Added E(ear, w1)", g.addEdge(ear, w1, 0));
return g;
}
}
libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/protocol/ 0000755 0001750 0001750 00000000000 11105642361 033001 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000201 00000000000 011556 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/protocol/FileURLConnectionTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/protocol/Fi0000644 0001750 0001750 00000015473 11023722741 033274 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.protocol;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import junit.framework.TestCase;
import org.jboss.net.protocol.file.FileURLConnection;
import org.jboss.util.file.Files;
/**
* Tests of the expected jdk file: url connection protocol handler behaviors.
*
* @author Scott.Stark@jboss.org
* @author Dimitris.Andreadis@jboss.org
* @version $Revision:$
*/
public class FileURLConnectionTestCase extends TestCase
{
public void testLastModified() throws Exception
{
File tmp = File.createTempFile("testLastModified", "");
tmp.deleteOnExit();
long lastModified = tmp.lastModified();
System.out.println("Created file: " + tmp.getAbsolutePath() + ", lastModified:" + lastModified);
URL tmpURL = tmp.toURL();
// Test JDK's provided FileURLConnection
checkLastModified(tmpURL.openConnection(), lastModified);
// Test JBoss's FileURLConnection
checkLastModified(new FileURLConnection(tmpURL), lastModified);
}
public void testContentLength() throws Exception
{
File tmp = File.createTempFile("testContentLength", "");
tmp.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tmp);
fos.write("testLength".getBytes());
fos.close();
long expectedLength = tmp.length();
URL tmpURL = tmp.toURL();
checkContentLength(tmpURL.openConnection(), expectedLength);
checkContentLength(new FileURLConnection(tmpURL), expectedLength);
}
public void testContentType() throws Exception
{
File tmp = File.createTempFile("testContentType", ".txt");
tmp.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tmp);
fos.write("A text file".getBytes());
fos.close();
String expectedContentType = "text/plain";
URL tmpURL = tmp.toURL();
checkContentType(tmpURL.openConnection(), expectedContentType);
checkContentType(new FileURLConnection(tmpURL), expectedContentType);
File dir = tmp.getParentFile();
URL dirURL = dir.toURL();
checkContentType(dirURL.openConnection(), expectedContentType);
checkContentType(new FileURLConnection(dirURL), expectedContentType);
}
public void testDirectoryListing() throws Exception
{
// create a test directory structure
// TMPDIR/testDirectoryList39558
// TMPDIR/testDirectoryList39558/test.txt
// TMPDIR/testDirectoryList39558/test.dir
File rootDir = File.createTempFile("testDirectoryList", "");
try
{
rootDir.delete();
rootDir.mkdir();
System.out.println(rootDir);
File tmpFile = new File(rootDir, "test.txt");
tmpFile.createNewFile();
System.out.println(tmpFile);
FileOutputStream fos = new FileOutputStream(tmpFile);
fos.write("this is a test file".getBytes());
fos.close();
File tmpDir = new File(rootDir, "test.dir");
tmpDir.mkdir();
System.out.println(tmpDir);
String[] expectedList = { "test.dir", "test.txt", null };
URL rootURL = rootDir.toURL();
// Check JDK FileURLConnection impl
checkDirectoryListing(rootURL.openConnection(), expectedList);
// Test JBoss FileURLConnection impl
checkDirectoryListing(new FileURLConnection(rootURL), expectedList);
}
finally
{
// cleanup
Files.delete(rootDir);
}
}
private void checkLastModified(URLConnection conn, long expectedLastModified)
{
System.out.println("Got URLConnection of type: " + conn.getClass().getName());
assertEquals(expectedLastModified, conn.getLastModified());
long lastModifiedHdr = conn.getHeaderFieldDate("last-modified", 0);
System.out.println(conn.getURL() + ", last-modified header: "+lastModifiedHdr);
// the last-modified header is expected to strip the milliseconds to
// comply with the (dd MMM yyyy HH:mm:ss) format, so the following assertions
// is invalid on windows that provide millisecond accuracy to File.lastModified()
// see, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4504473
// assertEquals(expectedLastModified, lastModifiedHdr);
}
private void checkContentLength(URLConnection conn, long expectedLength)
{
System.out.println("Got URLConnection of type: " + conn.getClass().getName());
int length = conn.getContentLength();
System.out.println(conn.getURL() + ", content-length:" + length);
assertEquals(expectedLength, length);
int lengthHdr = conn.getHeaderFieldInt("content-length", 0);
assertEquals(expectedLength, lengthHdr);
}
private void checkContentType(URLConnection conn, String expectedType)
{
System.out.println("Got URLConnection of type: " + conn.getClass().getName());
String type = conn.getContentType();
System.out.println(conn.getURL() + ", content-type: " + type);
assertEquals(type, expectedType);
}
private void checkDirectoryListing(URLConnection conn, String[] expectedFiles) throws IOException
{
System.out.println("Got URLConnection of type: " + conn.getClass().getName());
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
try
{
// verify the sorted directory list
for (int i = 0; i < expectedFiles.length; i++)
{
String msg = "directory entry #" + i;
System.out.println(msg + " : " + expectedFiles[i]);
assertEquals(msg, expectedFiles[i], in.readLine());
}
}
finally
{
in.close();
}
}
}
././@LongLink 0000000 0000000 0000000 00000000145 00000000000 011565 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/threadpool/ libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/threadpool/0000755 0001750 0001750 00000000000 11105642361 033301 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000205 00000000000 011562 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/threadpool/BasicThreadPoolTCCLTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/threadpool/0000644 0001750 0001750 00000011272 10774161402 033311 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.threadpool;
import junit.framework.TestCase;
import org.jboss.util.loading.ClassLoaderSource;
import org.jboss.util.threadpool.BasicThreadPool;
/**
* Tests thread context classloader management by BasicThreadPool.
*
* @author Brian Stansberry
*/
public class BasicThreadPoolTCCLTestCase extends TestCase
{
protected ClassLoader origCl;
/**
* @param name
*/
public BasicThreadPoolTCCLTestCase(String name)
{
super(name);
}
@Override
protected void setUp() throws Exception
{
super.setUp();
origCl = Thread.currentThread().getContextClassLoader();
}
@Override
protected void tearDown() throws Exception
{
try
{
super.tearDown();
}
finally
{
Thread.currentThread().setContextClassLoader(origCl);
}
}
public void testNullClassLoaderSource() throws Exception
{
ClassLoader existing = origCl == null ? getExtendedClassLoader() : origCl;
Thread.currentThread().setContextClassLoader(existing);
runClassLoaderSourceTest(null, existing);
Thread.currentThread().setContextClassLoader(null);
runClassLoaderSourceTest(null, null);
}
public void testConfiguredClassLoaderSource() throws Exception
{
ClassLoaderSource source = new TestClassLoaderSource();
runClassLoaderSourceTest(source, source.getClassLoader());
}
private void runClassLoaderSourceTest(ClassLoaderSource source, ClassLoader expected) throws Exception
{
ThreadGroup group = new ThreadGroup("Test");
BasicThreadPool pool = new BasicThreadPool("Test", group);
// Only one thread so we can use it twice to confirm
// it gets cleaned after the first task
pool.setMaximumPoolSize(1);
pool.setClassLoaderSource(source);
Task task = new Task();
pool.run(task);
// Wait for task completion
synchronized (task)
{
if (!task.done)
{
task.wait();
}
}
// ClassLoader expected = source == null ? null : source.getClassLoader();
assertEquals(expected, task.incomingCl);
Task task2 = new Task();
pool.run(task2);
// Wait for task completion
synchronized (task2)
{
if (!task2.done)
{
task2.wait();
}
}
assertSame(expected, task.incomingCl);
assertEquals("Pool size limited", 1, pool.getPoolSize());
}
private ClassLoader getExtendedClassLoader()
{
return new ExtendedClassLoader(origCl);
}
private class ExtendedClassLoader extends ClassLoader
{
ExtendedClassLoader(ClassLoader parent)
{
super(parent);
}
}
private class Task implements Runnable
{
private ClassLoader incomingCl;
private boolean done;
public void run()
{
incomingCl = Thread.currentThread().getContextClassLoader();
// Deliberately pollute the TCCL
ClassLoader leakedCl = BasicThreadPoolTCCLTestCase.this.getExtendedClassLoader();
Thread.currentThread().setContextClassLoader(leakedCl);
// Wake up the test thread
synchronized (this)
{
done = true;
notifyAll();
}
}
}
private class TestClassLoaderSource implements ClassLoaderSource
{
private ClassLoader cl;
TestClassLoaderSource()
{
cl = BasicThreadPoolTCCLTestCase.this.getExtendedClassLoader();
}
public ClassLoader getClassLoader()
{
return cl;
}
}
}
././@LongLink 0000000 0000000 0000000 00000000145 00000000000 011565 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/ libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/0000755 0001750 0001750 00000000000 11105642362 033323 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000210 00000000000 011556 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/ThreadPoolRunnableUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/0000644 0001750 0001750 00000027731 10774222622 033343 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.concurrent;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.ArrayList;
import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.ThreadPoolFullException;
import org.jboss.util.threadpool.BlockingMode;
import org.jboss.logging.Logger;
import junit.framework.TestCase;
/**
* Tests of thread pool with Runnables added to the pool
*
* @see org.jboss.util.threadpool.ThreadPool
* @author Adrian.Brock
* @author Scott.Stark@jboss.org
* @version $Revision: 2787 $
*/
@SuppressWarnings("unchecked")
public class ThreadPoolRunnableUnitTestCase extends TestCase
{
private static Logger log = Logger.getLogger(ThreadPoolRunnableUnitTestCase.class);
/** Basic test */
static final int BASIC = 0;
/** Hold the thread after start */
static final int HOLD_START = 1;
/** The started runnables */
HashSet startedRunnables = new HashSet();
/** The started releases */
HashSet startedReleases = new HashSet();
/** The finished runnables */
HashSet finishedRunnables = new HashSet();
/** The thread names */
HashMap threadNames = new HashMap();
/**
* Create a new ThreadPoolRunnableUnitTestCase
*
* @param name the test to run
*/
public ThreadPoolRunnableUnitTestCase(String name)
{
super(name);
}
public void testBasic() throws Exception
{
log.debug("testBasic");
BasicThreadPool pool = new BasicThreadPool();
try
{
pool.run(new TestRunnable(BASIC, "test"));
waitFinished(1);
HashSet expected = makeExpected(new Object[] {"test"});
assertEquals(expected, finishedRunnables);
}
finally
{
pool.stop(true);
}
}
public void testMultipleBasic() throws Exception
{
log.debug("testMultipleBasic");
BasicThreadPool pool = new BasicThreadPool();
try
{
pool.run(new TestRunnable(BASIC, "test1"));
pool.run(new TestRunnable(BASIC, "test2"));
pool.run(new TestRunnable(BASIC, "test3"));
waitFinished(3);
HashSet expected = makeExpected(new Object[] {"test1", "test2", "test3"});
assertEquals(expected, finishedRunnables);
}
finally
{
pool.stop(true);
}
}
public void testSimplePooling() throws Exception
{
log.debug("testSimplePooling");
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumPoolSize(1);
try
{
pool.run(new TestRunnable(BASIC, "test1"));
waitFinished(1);
pool.run(new TestRunnable(BASIC, "test2"));
waitFinished(2);
assertEquals(threadNames.get("test1"), threadNames.get("test2"));
}
finally
{
pool.stop(true);
}
}
public void testMultiplePooling() throws Exception
{
log.debug("testMultiplePooling");
BasicThreadPool pool = new BasicThreadPool();
try
{
pool.run(new TestRunnable(HOLD_START, "test1"));
waitStarted(1);
pool.run(new TestRunnable(BASIC, "test2"));
waitFinished(1);
releaseStarted("test1");
waitFinished(2);
assertTrue("Shouldn't run on the same thread", threadNames.get("test1").equals(threadNames.get("test2")) == false);
}
finally
{
pool.stop(true);
}
}
public void testMaximumPool() throws Exception
{
log.debug("testMaximumPool");
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumPoolSize(1);
try
{
pool.run(new TestRunnable(HOLD_START, "test1"));
waitStarted(1);
pool.run(new TestRunnable(BASIC, "test2"));
Thread.sleep(1000);
assertEquals(0, finishedRunnables.size());
releaseStarted("test1");
waitFinished(2);
assertEquals(makeExpected(new Object[] {"test1", "test2"}), finishedRunnables);
}
finally
{
pool.stop(true);
}
}
public void testMaximumQueue() throws Exception
{
log.debug("testMaximumQueue");
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumQueueSize(1);
pool.setMaximumPoolSize(1);
try
{
pool.run(new TestRunnable(HOLD_START, "test1"));
waitStarted(1);
pool.run(new TestRunnable(BASIC, "test2"));
boolean caught = false;
try
{
pool.run(new TestRunnable(BASIC, "test3"));
}
catch (ThreadPoolFullException expected)
{
caught = true;
}
assertTrue("Expected ThreadPoolFullException", caught);
releaseStarted("test1");
waitFinished(2);
assertEquals(makeExpected(new Object[] {"test1", "test2"}), finishedRunnables);
}
finally
{
pool.stop(true);
}
}
public void testRunnableTimeout() throws Exception
{
log.debug("testRunnableTimeout");
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumQueueSize(1);
pool.setMaximumPoolSize(1);
try
{
TestRunnable test = new TestRunnable(HOLD_START, "test1", 12*1000);
pool.run(test, 0, 10*1000);
waitStarted(1);
releaseStarted("test1");
waitFinished(1);
assertEquals(makeExpected(new Object[] {"test1"}), finishedRunnables);
}
finally
{
pool.stop(true);
}
}
public void testRunnableTimeoutWithSpinLoop() throws Exception
{
log.debug("testRunnableTimeoutWithSpinLoop");
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumQueueSize(1);
pool.setMaximumPoolSize(1);
try
{
TestRunnable test = new TestRunnable(HOLD_START, "test1", Long.MAX_VALUE);
pool.run(test, 0, 8*1000);
waitStarted(1);
releaseStarted("test1");
Thread.sleep(12*1000);
// Run another task to validate the previous thread has been cleared
pool.run(new TestRunnable(BASIC, "test2"));
waitStarted(1);
releaseStarted("test2");
waitFinished(1);
assertEquals(makeExpected(new Object[] {"test2"}), finishedRunnables);
}
finally
{
pool.stop(true);
}
}
public void testRunnableTimeoutWithSpinLoop2() throws Exception
{
log.debug("testRunnableTimeoutWithSpinLoop2");
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumQueueSize(1);
pool.setMaximumPoolSize(1);
pool.setBlockingMode(BlockingMode.RUN);
try
{
TestRunnable test = new TestRunnable(BASIC, "testx", Long.MAX_VALUE);
pool.run(test, 0, 1*1000);
// Run another task to validate the previous thread has been cleared
ArrayList tmp = new ArrayList();
for(int n = 0; n < 10; n ++)
{
String name = "test"+n;
pool.run(new TestRunnable(BASIC, name));
tmp.add(name);
}
Thread.sleep(3000);
assertEquals(makeExpected(tmp.toArray()), finishedRunnables);
}
finally
{
pool.stop(true);
}
}
/**
* Save the thread name
*
* @param data the test data
* @param name the thread name
*/
public synchronized void saveRunnableThreadName(String data, String name)
{
threadNames.put(data, name);
}
public synchronized void waitStarted(int target)
throws InterruptedException
{
log.info("waitStarted, target="+target);
while (startedRunnables.size() < target)
wait();
}
/**
* Release in waiting for start
*
* @param data the thread to start
*/
public synchronized void releaseStarted(String data)
{
log.info("releaseStarted, data="+data);
startedReleases.add(data);
notifyAll();
}
public synchronized void waitForReleaseStarted(String data)
{
try
{
log.info("waitForReleaseStarted, data="+data);
while (startedReleases.contains(data) == false)
wait();
}
catch (InterruptedException ignored)
{
}
}
public synchronized void notifyStarted(String data)
{
log.info("notifyStarted, data="+data);
startedRunnables.add(data);
notifyAll();
}
/**
* Clear started
*/
public synchronized void clearStarted()
{
log.info("clearStarted");
startedRunnables.clear();
}
public synchronized void waitFinished(int target)
throws InterruptedException
{
log.info("waitFinished, target="+target);
while (finishedRunnables.size() < target)
wait();
}
public synchronized void notifyFinished(String data)
{
log.info("notifyFinished, data="+data);
finishedRunnables.add(data);
notifyAll();
}
/**
* Clear finished
*/
public synchronized void clearFinished()
{
log.info("clearFinished");
finishedRunnables.clear();
}
/**
* Make the expected result
*
* @param expected the results as an object array
* @return the expected result
*/
public HashSet makeExpected(Object[] expected)
{
return new HashSet(Arrays.asList(expected));
}
/**
* Test runnable
*/
public class TestRunnable implements Runnable
{
/** The test to run */
private int test;
/** The data for the test */
private String data;
private long runSleepTime;
/**
* Create a new TestRunnable
*
* @param test the test
* @param data the test data
*/
public TestRunnable(int test, String data)
{
this(test, data, 0);
}
public TestRunnable(int test, String data, long runSleepTime)
{
this.test = test;
this.data = data;
this.runSleepTime = runSleepTime;
}
/**
* Runnable implementation
*/
public void run()
{
log.info("Begin run");
saveThreadName();
started();
if( runSleepTime > 0 )
{
log.info("Begin spin loop");
if( runSleepTime == Long.MAX_VALUE )
{
while( true )
;
}
else
{
log.info("Begin sleep");
try
{
Thread.sleep(runSleepTime);
}
catch(InterruptedException e)
{
}
}
}
finished();
log.info("End run");
}
/**
* Save the thread
*/
public void saveThreadName()
{
saveRunnableThreadName(data, Thread.currentThread().getName());
}
/**
* The test is finished
*/
public void started()
{
notifyStarted(data);
if (test == HOLD_START)
waitForReleaseStarted(data);
}
/**
* The test is finished
*/
public void finished()
{
notifyFinished(data);
}
}
}
././@LongLink 0000000 0000000 0000000 00000000204 00000000000 011561 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/ThreadPoolTaskUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/0000644 0001750 0001750 00000037577 10774222622 033354 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.concurrent;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.Task;
import org.jboss.logging.Logger;
import junit.framework.TestCase;
/**
* Tests of thread pool with Tasks added to the pool
*
* @see org.jboss.util.threadpool.ThreadPool
* @author Adrian.Brock
* @author Scott.Stark@jboss.org
* @version $Revision: 2787 $
*/
@SuppressWarnings("unchecked")
public class ThreadPoolTaskUnitTestCase extends TestCase
{
private static Logger log = Logger.getLogger(ThreadPoolTaskUnitTestCase.class);
/** Basic test */
static final int BASIC = 0;
/** Hold the thread after start */
static final int HOLD_START = 1;
/** The accepted stats */
Stats accepted = new Stats("Accepted");
/** The rejected stats */
Stats rejected = new Stats("Rejected");
/** The started stats */
Stats started = new Stats("Started");
/** The completed stats */
Stats completed = new Stats("Completed");
/** The stopped stats */
Stats stopped = new Stats("Stopped");
/** The thread names */
HashMap threadNames = new HashMap();
/**
* Create a new ThreadPoolTaskUnitTestCase
*
* @param name the test to run
*/
public ThreadPoolTaskUnitTestCase(String name)
{
super(name);
}
protected void setUp() throws Exception
{
log.debug("====> Starting test: " + getName());
}
protected void tearDown() throws Exception
{
log.debug("=====> Stopping test: " + getName());
}
public void testBasic() throws Exception
{
BasicThreadPool pool = new BasicThreadPool();
try
{
pool.runTask(new TestTask(BASIC, "test"));
completed.wait(1);
HashSet expected = makeExpected(new Object[] {"test"});
assertEquals(expected, accepted.tasks);
assertEquals(expected, started.tasks);
assertEquals(expected, completed.tasks);
}
finally
{
pool.stop(true);
}
}
public void testMultipleBasic() throws Exception
{
BasicThreadPool pool = new BasicThreadPool();
try
{
pool.runTask(new TestTask(BASIC, "test1"));
pool.runTask(new TestTask(BASIC, "test2"));
pool.runTask(new TestTask(BASIC, "test3"));
completed.wait(3);
HashSet expected = makeExpected(new Object[] {"test1", "test2", "test3"});
assertEquals(expected, accepted.tasks);
assertEquals(expected, started.tasks);
assertEquals(expected, completed.tasks);
}
finally
{
pool.stop(true);
}
}
public void testSimplePooling() throws Exception
{
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumPoolSize(1);
try
{
pool.runTask(new TestTask(BASIC, "test1"));
completed.wait(1);
pool.runTask(new TestTask(BASIC, "test2"));
completed.wait(2);
assertEquals(threadNames.get("test1"), threadNames.get("test2"));
}
finally
{
pool.stop(true);
}
}
public void testMultiplePooling() throws Exception
{
BasicThreadPool pool = new BasicThreadPool();
try
{
pool.runTask(new TestTask(HOLD_START, "test1"));
started.wait(1);
pool.runTask(new TestTask(BASIC, "test2"));
completed.wait(1);
started.release("test1");
completed.wait(2);
assertTrue("Shouldn't run on the same thread", threadNames.get("test1").equals(threadNames.get("test2")) == false);
}
finally
{
pool.stop(true);
}
}
public void testMaximumPool() throws Exception
{
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumPoolSize(1);
try
{
pool.runTask(new TestTask(HOLD_START, "test1"));
started.wait(1);
pool.runTask(new TestTask(BASIC, "test2"));
Thread.sleep(1000);
assertEquals(0, completed.tasks.size());
started.release("test1");
completed.wait(2);
assertEquals(makeExpected(new Object[] {"test1", "test2"}), completed.tasks);
}
finally
{
pool.stop(true);
}
}
public void testMaximumQueue() throws Exception
{
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumQueueSize(1);
pool.setMaximumPoolSize(1);
try
{
pool.runTask(new TestTask(HOLD_START, "test1"));
started.wait(1);
pool.runTask(new TestTask(BASIC, "test2"));
assertEquals(0, rejected.tasks.size());
pool.runTask(new TestTask(BASIC, "test3"));
assertEquals(makeExpected(new Object[] {"test3"}), rejected.tasks);
started.release("test1");
completed.wait(2);
assertEquals(makeExpected(new Object[] {"test1", "test2"}), completed.tasks);
}
finally
{
pool.stop(true);
}
}
public void testCompleteTimeout() throws Exception
{
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumQueueSize(1);
pool.setMaximumPoolSize(1);
try
{
/* Test that a task with a timeout that completes within its timeout
works as expected
*/
TestTask task = new TestTask(HOLD_START, "test1", 0, 10*1000, Task.WAIT_NONE);
pool.runTask(task);
started.wait(1);
started.release("test1");
completed.wait(1);
/* Test a task with a timeout that does not complete within its timeout
is stopped
*/
task = new TestTask(HOLD_START, "test2", 0, 10*1000, Task.WAIT_NONE);
task.setRunSleepTime(12*1000);
pool.runTask(task);
started.wait(1);
started.release("test2");
stopped.wait(1);
completed.wait(1);
// Test that another valid task completes as expected
task = new TestTask(HOLD_START, "test3", 0, 0, Task.WAIT_NONE);
pool.runTask(task);
started.wait(1);
started.release("test3");
completed.wait(1);
/* Test a task with a timeout that does not complete within its timeout
is stopped
*/
task = new TestTask(HOLD_START, "test4", 0, 10*1000, Task.WAIT_NONE);
task.setRunSleepTime(12*1000);
pool.runTask(task);
started.wait(1);
started.release("test4");
stopped.wait(1);
completed.wait(1);
}
finally
{
pool.stop(true);
}
}
public void testCompleteTimeoutWithSpinLoop() throws Exception
{
BasicThreadPool pool = new BasicThreadPool();
pool.setMaximumQueueSize(1);
pool.setMaximumPoolSize(1);
try
{
/* Test that a task with a timeout that completes within its timeout
works as expected
*/
TestTask task = new TestTask(HOLD_START, "test1", 0, 10*1000, Task.WAIT_NONE);
task.setRunSleepTime(Long.MAX_VALUE);
pool.runTask(task);
started.wait(1);
started.release("test1");
stopped.wait(1);
completed.wait(1);
}
finally
{
pool.stop(true);
}
}
/**
* Save the thread name
*
* @param data the test data
* @param name the thread name
*/
public synchronized void saveRunnableThreadName(String data, String name)
{
threadNames.put(data, name);
}
/**
* Make the expected result
*
* @param expected the results as an object array
* @return the expected result
*/
public HashSet makeExpected(Object[] expected)
{
return new HashSet(Arrays.asList(expected));
}
/**
* Test task
*/
public class TestTask implements Task
{
/** The test to run */
private int test;
/** The data for the test */
private String data;
/** The start timeout */
private long startTimeout;
/** The completion timeout */
private long completionTimeout;
/** The time to sleep in execute */
private long runSleepTime;
/** The wait type */
private int waitType;
/**
* Create a new TestTask
*
* @param test the test
* @param data the test data
*/
public TestTask(int test, String data)
{
this(test, data, 0, Task.WAIT_NONE);
}
/**
* Create a new TestTask
*
* @param test the test
* @param data the test data
* @param startTimeout the start timeout
* @param waitType the wait type
*/
public TestTask(int test, String data, long startTimeout, int waitType)
{
this(test, data, startTimeout, 0, waitType);
}
public TestTask(int test, String data, long startTimeout,
long completionTimeout, int waitType)
{
this.test = test;
this.data = data;
this.startTimeout = startTimeout;
this.completionTimeout = completionTimeout;
this.waitType = waitType;
}
public void execute()
{
saveThreadName();
log.info("Start execute");
if( runSleepTime > 0 )
{
log.info("Begin spin loop");
if( runSleepTime == Long.MAX_VALUE )
{
while( true )
;
}
else
{
log.info("Begin sleep");
try
{
Thread.sleep(runSleepTime);
}
catch(InterruptedException e)
{
}
}
}
log.info("End execute");
}
public void saveThreadName()
{
saveRunnableThreadName(data, Thread.currentThread().getName());
}
public void accepted(long time)
{
accepted.notify(data, time);
}
public void rejected(long time, Throwable throwable)
{
rejected.notify(data, time, throwable);
}
public void started(long time)
{
started.notify(data, time);
if (test == HOLD_START)
started.waitForRelease(data);
}
public void completed(long time, Throwable throwable)
{
completed.notify(data, time, throwable);
}
public long getCompletionTimeout()
{
return completionTimeout;
}
public int getPriority()
{
return Thread.NORM_PRIORITY;
}
public long getStartTimeout()
{
return startTimeout;
}
public int getWaitType()
{
return waitType;
}
public void stop()
{
stopped.notify(data);
}
public void setRunSleepTime(long runSleepTime)
{
this.runSleepTime = runSleepTime;
}
}
public class Stats
{
/**
* The name
*/
String name;
/** The tasks */
HashSet tasks = new HashSet();
/** The times */
HashMap times = new HashMap();
/** The errors */
HashMap errors = new HashMap();
/** The releases */
HashSet releases = new HashSet();
public Stats(String name)
{
this.name = name;
}
public void wait(int target)
throws InterruptedException
{
log.debug(Thread.currentThread().getName() + ": Waiting for " + name + " target=" + target);
synchronized (ThreadPoolTaskUnitTestCase.this)
{
while (tasks.size() < target)
ThreadPoolTaskUnitTestCase.this.wait();
log.debug(Thread.currentThread().getName() + ": Waited for " + name + " target=" + target);
}
}
/**
* Release in waiting
*
* @param data the thread
*/
public void release(String data)
{
log.debug(Thread.currentThread().getName() + ": Releasing " + name + " data=" + data);
synchronized (ThreadPoolTaskUnitTestCase.this)
{
releases.add(data);
ThreadPoolTaskUnitTestCase.this.notifyAll();
log.debug(Thread.currentThread().getName() + ": Released " + name + " data=" + data);
}
}
public void waitForRelease(String data)
{
log.debug(Thread.currentThread().getName() + ": Waiting for release " + name + " data=" + data);
synchronized (ThreadPoolTaskUnitTestCase.this)
{
try
{
while (releases.contains(data) == false)
ThreadPoolTaskUnitTestCase.this.wait();
}
catch (InterruptedException ignored)
{
}
log.debug(Thread.currentThread().getName() + ": Waited for release " + name + " data=" + data);
}
}
public void notify(String data)
{
log.debug(Thread.currentThread().getName() + ": Notifying " + name + " data=" + data);
synchronized (ThreadPoolTaskUnitTestCase.this)
{
tasks.add(data);
ThreadPoolTaskUnitTestCase.this.notifyAll();
log.debug(Thread.currentThread().getName() + ": Notified " + name + " data=" + data);
}
}
public void notify(String data, long time)
{
log.debug(Thread.currentThread().getName() + ": Notifying " + name + " data=" + data + " time=" + time);
synchronized (ThreadPoolTaskUnitTestCase.this)
{
tasks.add(data);
times.put(data, new Long(time));
ThreadPoolTaskUnitTestCase.this.notifyAll();
}
log.debug(Thread.currentThread().getName() + ": Notified " + name + " data=" + data + " time=" + time);
}
public void notify(String data, long time, Throwable throwable)
{
if (throwable != null)
log.debug(Thread.currentThread().getName() + ": Notifying " + name + " data=" + data + " time=" + time, throwable);
else
log.debug(Thread.currentThread().getName() + ": Notifying " + name + " data=" + data + " time=" + time + " throwable=null");
synchronized (ThreadPoolTaskUnitTestCase.this)
{
tasks.add(data);
times.put(data, new Long(time));
errors.put(data, throwable);
ThreadPoolTaskUnitTestCase.this.notifyAll();
}
if (throwable != null)
log.debug(Thread.currentThread().getName() + ": Notified " + name + " data=" + data + " time=" + time + " throwable=" + throwable.getMessage());
else
log.debug(Thread.currentThread().getName() + ": Notified " + name + " data=" + data + " time=" + time + " throwable=null");
}
/**
* Clear
*/
public void clear()
{
log.debug(Thread.currentThread().getName() + ": Clearing " + name);
synchronized (ThreadPoolTaskUnitTestCase.this)
{
tasks.clear();
log.debug(Thread.currentThread().getName() + ": Cleared " + name);
}
}
}
}
././@LongLink 0000000 0000000 0000000 00000000200 00000000000 011555 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/TimeoutFactoryTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/0000644 0001750 0001750 00000013444 10614235027 033333 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.concurrent;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.jboss.util.threadpool.BasicThreadPool;
import org.jboss.util.threadpool.BlockingMode;
import org.jboss.util.timeout.Timeout;
import org.jboss.util.timeout.TimeoutFactory;
import org.jboss.util.timeout.TimeoutTarget;
/**
* Unit tests for TimeoutFactory class.
*
* @author Elias Ross
* @author Dimitris Andreadis
* @version $Revision: 2393 $
*/
public class TimeoutFactoryTestCase extends TestCase
{
public TimeoutFactoryTestCase(String name)
{
super(name);
}
CountDownLatch count;
public void testBlocking() throws Exception
{
final int times = 5000;
count = new CountDownLatch(times);
TT tt = new TT();
for (int i = 0; i < times; i++)
{
TimeoutFactory.createTimeout(0, tt);
}
count.await(60, TimeUnit.SECONDS);
assertEquals(0, count.getCount());
}
public void testDefaultCtr() throws Exception
{
final int times = 5000;
count = new CountDownLatch(times);
TT tt = new TT();
TimeoutFactory tf = new TimeoutFactory();
for (int i = 0; i < times; i++)
{
tf.schedule(0, (Runnable)tt);
}
count.await(60, TimeUnit.SECONDS);
assertEquals(0, count.getCount());
}
public void testConsecutiveTimeouts() throws Exception
{
final int times = 1000;
count = new CountDownLatch(times);
TT tt = new TT();
TimeoutFactory tf = new TimeoutFactory();
long now = System.currentTimeMillis();
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 100; j++)
{
tf.schedule(now + i*50, (TimeoutTarget)tt);
}
}
count.await(10, TimeUnit.SECONDS);
assertEquals(0, count.getCount());
}
public void testCancel() throws Exception
{
final int times = 100;
count = new CountDownLatch(times);
TT tt = new TT();
TimeoutFactory tf = new TimeoutFactory();
long at = System.currentTimeMillis() + 300;
for (int i = 0; i < times; i++)
{
Timeout t = tf.schedule(at, (TimeoutTarget)tt);
t.cancel();
}
count.await(5, TimeUnit.SECONDS);
assertEquals(times, count.getCount());
}
public void testCancelFactory() throws Exception
{
final int times = 100;
count = new CountDownLatch(times);
TT tt = new TT();
TimeoutFactory tf = new TimeoutFactory();
long at = System.currentTimeMillis() + 300;
for (int i = 0; i < times; i++)
{
tf.schedule(at, (TimeoutTarget)tt);
}
tf.cancel();
count.await(5, TimeUnit.SECONDS);
assertEquals(times, count.getCount());
}
public void testBlockingSmallThreadPool() throws Exception
{
final int times = 100;
count = new CountDownLatch(times);
BasicThreadPool tp = new BasicThreadPool();
tp.setMaximumQueueSize(1);
tp.setMaximumPoolSize(1);
tp.setBlockingMode(BlockingMode.RUN);
TT tt = new TT();
TimeoutFactory tf = new TimeoutFactory(tp);
for (int i = 0; i < times; i++)
{
tf.schedule(0, (TimeoutTarget)tt);
}
count.await(10, TimeUnit.SECONDS);
assertEquals(0, count.getCount());
}
public void testAbortingSmallThreadPool() throws Exception
{
final int times = 50;
count = new CountDownLatch(times);
BasicThreadPool tp = new BasicThreadPool();
tp.setMaximumQueueSize(1);
tp.setMaximumPoolSize(1);
TT tt = new TT();
TimeoutFactory tf = new TimeoutFactory(tp);
for (int i = 0; i < times; i++)
{
tf.schedule(0, (TimeoutTarget)tt);
}
count.await(5, TimeUnit.SECONDS);
assertTrue("Executed " + count.getCount() + " < scheduled " + times, count.getCount() < times);
}
public void testFailedTarget() throws Exception
{
final int times = 50;
count = new CountDownLatch(times);
TimeoutFactory tf = new TimeoutFactory();
TT tt = new TT();
tt.fail = true;
for (int i = 0; i < times; i++)
{
tf.schedule(0, (TimeoutTarget)tt);
}
Thread.sleep(500);
assertEquals(times, count.getCount());
}
class TT implements TimeoutTarget, Runnable
{
boolean fail;
public void timedOut(Timeout timeout)
{
assertTrue(timeout != null);
run();
}
public void run()
{
if (fail)
throw new Error("Fail");
try
{
Thread.sleep(10);
}
catch (InterruptedException e)
{
}
count.countDown();
}
}
}
././@LongLink 0000000 0000000 0000000 00000000221 00000000000 011560 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/ThreadPoolInterruptedThreadUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/concurrent/0000644 0001750 0001750 00000004262 10774225552 033342 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2007, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.concurrent;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.jboss.util.threadpool.BasicThreadPool;
/**
* Tests of thread pool with Tasks added to the pool
*
* @see org.jboss.util.threadpool.ThreadPool
* @author Adrian.Brock
* @author Scott.Stark@jboss.org
* @version $Revision: 2787 $
*/
public class ThreadPoolInterruptedThreadUnitTestCase extends TestCase
{
public ThreadPoolInterruptedThreadUnitTestCase(String name)
{
super(name);
}
public static class TestRunnable implements Runnable
{
public CountDownLatch latch = new CountDownLatch(1);
public void run()
{
latch.countDown();
}
}
public void testInterruptedExecute() throws Exception
{
BasicThreadPool pool = new BasicThreadPool();
TestRunnable runnable = new TestRunnable();
Thread.currentThread().interrupt();
try
{
pool.run(runnable);
}
finally
{
assertTrue(Thread.interrupted());
}
assertTrue(runnable.latch.await(10, TimeUnit.SECONDS));
}
}
././@LongLink 0000000 0000000 0000000 00000000145 00000000000 011565 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/ libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000755 0001750 0001750 00000000000 11105642362 033274 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000175 00000000000 011570 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/AbstractSetUnitTest.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000001251 11042105117 033265 0 ustar twerner twerner package org.jboss.test.util.test.collection;
import java.util.Iterator;
import java.util.Set;
import junit.framework.TestCase;
/**
* Unit tests for WeakSet
*
* @author Sven Meier
* @author Ales Justin
* @version $Revision: 43534 $
*/
@SuppressWarnings("unchecked")
public abstract class AbstractSetUnitTest extends TestCase
{
protected abstract Set createSet();
public void testMultipleHasNext()
{
Set set = createSet();
set.add(new Object());
Iterator iterator = set.iterator();
assertTrue(iterator.hasNext());
assertTrue(iterator.hasNext());
}
} ././@LongLink 0000000 0000000 0000000 00000000175 00000000000 011570 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/WeakSetUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000000736 11042105117 033274 0 ustar twerner twerner package org.jboss.test.util.test.collection;
import java.util.Set;
import org.jboss.util.collection.WeakSet;
/**
* Unit tests for WeakSet
*
* @author Sven Meier
* @author Ales Justin
* @version $Revision: 43534 $
*/
@SuppressWarnings("unchecked")
public class WeakSetUnitTestCase extends AbstractNullableSetUnitTest
{
protected Set createSet()
{
return new WeakSet();
}
}
././@LongLink 0000000 0000000 0000000 00000000175 00000000000 011570 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/AbstractMapUnitTest.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000004352 11103542066 033300 0 ustar twerner twerner package org.jboss.test.util.test.collection;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import junit.framework.TestCase;
/**
* Unit tests for custom maps.
*
* @author Ales Justin
*/
public abstract class AbstractMapUnitTest extends TestCase
{
protected abstract Map createEmptyMap();
@SuppressWarnings("unchecked")
public void testBasicOperations() throws Exception
{
Map map = createEmptyMap();
assertTrue(map.isEmpty());
assertEquals(0, map.size());
String key1 = "date1";
Date value1 = new Date();
map.put(key1, value1);
assertTrue(map.containsKey(key1));
assertTrue(map.containsValue(value1));
assertEquals(1, map.size());
String key2 = "date2";
Date value2 = new Date();
map.put(key2, value2);
assertTrue(map.containsKey(key2));
assertTrue(map.containsValue(value2));
assertEquals(2, map.size());
String key3 = "date3";
Date value3 = new Date();
map.put(key3, value3);
assertTrue(map.containsKey(key1));
assertTrue(map.containsValue(value1));
assertEquals(3, map.size());
map.clear();
assertTrue(map.isEmpty());
key1 = "date1";
value1 = new Date();
map.put(key1, value1);
map.remove(key1);
assertTrue(map.isEmpty());
map.putAll(Collections.singletonMap(key1, value1));
assertEquals(value1, map.get(key1));
assertEquals(Collections.singletonMap(key1, value1), map);
// iterables
Iterable keys = map.keySet();
assertIterable(keys, String.class);
Iterable values = map.values();
assertIterable(values, Date.class);
Iterable entries = map.entrySet();
Map.Entry entry = assertIterable(entries, Map.Entry.class);
assertEquals(key1, entry.getKey());
assertEquals(value1, entry.getValue());
}
protected T assertIterable(Iterable iter, Class clazz)
{
assertTrue(iter.iterator().hasNext());
T next = iter.iterator().next();
assertTrue("Next " + next + " is not instance of " + clazz.getName(), clazz.isInstance(next));
assertNotNull(next);
return next;
}
} ././@LongLink 0000000 0000000 0000000 00000000175 00000000000 011570 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/LazySetUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000000637 11103542066 033302 0 ustar twerner twerner package org.jboss.test.util.test.collection;
import java.util.Set;
import org.jboss.util.collection.CollectionsFactory;
/**
* Unit tests for ConcurrentSet
*
* @author Ales Justin
*/
@SuppressWarnings("unchecked")
public class LazySetUnitTestCase extends AbstractSetUnitTest
{
protected Set createSet()
{
return CollectionsFactory.createLazySet();
}
} ././@LongLink 0000000 0000000 0000000 00000000206 00000000000 011563 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/SoftValueTreeMapUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000002602 11103262257 033275 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.collection;
import java.util.Map;
import org.jboss.util.collection.SoftValueTreeMap;
/**
* SoftValueTreeMap test.
*
* @author Ales Justin
*/
public class SoftValueTreeMapUnitTestCase extends AbstractMapUnitTest
{
protected Map createEmptyMap()
{
return new SoftValueTreeMap();
}
} ././@LongLink 0000000 0000000 0000000 00000000206 00000000000 011563 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/WeakValueHashMapUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000002602 11103262257 033275 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.collection;
import java.util.Map;
import org.jboss.util.collection.WeakValueHashMap;
/**
* WeakValueHashMap test.
*
* @author Ales Justin
*/
public class WeakValueHashMapUnitTestCase extends AbstractMapUnitTest
{
protected Map createEmptyMap()
{
return new WeakValueHashMap();
}
} ././@LongLink 0000000 0000000 0000000 00000000206 00000000000 011563 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/SoftValueHashMapUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000002605 11103262257 033300 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.collection;
import java.util.Map;
import org.jboss.util.collection.SoftValueHashMap;
/**
* SoftValueHashMap test.
*
* @author Ales Justin
*/
public class SoftValueHashMapUnitTestCase extends AbstractMapUnitTest
{
protected Map createEmptyMap()
{
return new SoftValueHashMap();
}
}
././@LongLink 0000000 0000000 0000000 00000000175 00000000000 011570 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/LazyMapUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000002607 11103542066 033301 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.collection;
import java.util.Map;
import org.jboss.util.collection.CollectionsFactory;
/**
* SoftValueHashMap test.
*
* @author Ales Justin
*/
public class LazyMapUnitTestCase extends AbstractMapUnitTest
{
protected Map createEmptyMap()
{
return CollectionsFactory.createLazyMap();
}
} ././@LongLink 0000000 0000000 0000000 00000000206 00000000000 011563 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/WeakValueTreeMapUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000002602 11103262257 033275 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.collection;
import java.util.Map;
import org.jboss.util.collection.WeakValueTreeMap;
/**
* WeakValueTreeMap test.
*
* @author Ales Justin
*/
public class WeakValueTreeMapUnitTestCase extends AbstractMapUnitTest
{
protected Map createEmptyMap()
{
return new WeakValueTreeMap();
}
} ././@LongLink 0000000 0000000 0000000 00000000203 00000000000 011560 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/ConcurrentSetUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000000621 11042105117 033265 0 ustar twerner twerner package org.jboss.test.util.test.collection;
import java.util.Set;
import org.jboss.util.collection.ConcurrentSet;
/**
* Unit tests for ConcurrentSet
*
* @author Ales Justin
*/
@SuppressWarnings("unchecked")
public class ConcurrentSetUnitTestCase extends AbstractSetUnitTest
{
protected Set createSet()
{
return new ConcurrentSet();
}
} ././@LongLink 0000000 0000000 0000000 00000000205 00000000000 011562 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/AbstractNullableSetUnitTest.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/collection/0000644 0001750 0001750 00000001312 11042105117 033263 0 ustar twerner twerner package org.jboss.test.util.test.collection;
import java.util.Iterator;
import java.util.Set;
/**
* Unit tests for WeakSet
*
* @author Sven Meier
* @author Ales Justin
* @version $Revision: 43534 $
*/
@SuppressWarnings("unchecked")
public abstract class AbstractNullableSetUnitTest extends AbstractSetUnitTest
{
protected abstract Set createSet();
public void testNullElement()
{
Set set = createSet();
set.add(null);
assertEquals(1, set.size());
Iterator iterator = set.iterator();
assertTrue(iterator.hasNext());
iterator.next();
assertFalse(iterator.hasNext());
}
} libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/stream/ 0000755 0001750 0001750 00000000000 11105642362 032434 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000201 00000000000 011556 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/stream/MarshallValueStreamTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/stream/Mars0000644 0001750 0001750 00000003021 11054755361 033264 0 ustar twerner twerner package org.jboss.test.util.test.stream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
import junit.framework.TestCase;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
/**
* Test MarshalledValueInput/OutputStream
*
* @see org.jboss.util.propertyeditor.PropertyEditors
*
* @author Jason.Greene@jboss.org
* @version $Revision: 2904 $
*/
public class MarshallValueStreamTestCase extends TestCase
{
public void testArrayMarshall() throws Exception
{
Byte[] bytes = new Byte[] {1, 2, 3};
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MarshalledValueOutputStream os = new MarshalledValueOutputStream(baos);
os.writeObject(bytes);
os.flush();
MarshalledValueInputStream is = new MarshalledValueInputStream(new ByteArrayInputStream(baos.toByteArray()));
assertTrue(Arrays.equals(bytes, (Byte[]) is.readObject()));
}
public void testPrimitive() throws Exception
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(int.class);
oos.close();
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
MarshalledValueInputStream mvis = new MarshalledValueInputStream(bais);
Object o = mvis.readObject();
assertNotNull(o);
assertEquals(o, int.class);
}
}
././@LongLink 0000000 0000000 0000000 00000000162 00000000000 011564 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/ObjectsUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/ObjectsUnit0000644 0001750 0001750 00000005310 11103542066 033312 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test;
import java.util.Date;
import junit.framework.TestCase;
import org.jboss.util.Objects;
/**
* @author Ales Justin
*/
public class ObjectsUnitTestCase extends TestCase
{
public void testEquals() throws Exception
{
assertTrue(Objects.equals("123", "123"));
Object first = new String[]{"123", "321"};
Object second = new String[]{"123", "321"};
assertTrue(Objects.equals(first, second));
first = new String[][]{{"1", "2"}, {"1", "2"}};
second = new String[][]{{"1", "2"}, {"1", "2"}};
assertTrue(Objects.equals(first, second));
assertFalse(Objects.equals("129", "123"));
first = new String[]{"123", "324"};
second = new String[]{"123", "321"};
assertFalse(Objects.equals(first, second));
first = new String[][]{{"1", "6"}, {"1", "2"}};
second = new String[][]{{"1", "2"}, {"1", "2"}};
assertFalse(Objects.equals(first, second));
first = new int[]{1, 2, 3};
second = new int[]{1, 2, 3};
assertTrue(Objects.equals(first, second));
first = new int[][]{{1, 2}, {1, 2}};
second = new int[][]{{1, 2}, {1, 2}};
assertTrue(Objects.equals(first, second));
first = new int[]{1, 2, 4};
second = new int[]{1, 2, 3};
assertFalse(Objects.equals(first, second));
first = new int[][]{{1, 6}, {1, 2}};
second = new int[][]{{1, 2}, {1, 2}};
assertFalse(Objects.equals(first, second));
assertFalse(Objects.equals("123", new int[]{1, 2, 3}));
assertFalse(Objects.equals(new int[]{1, 2, 3}, "123"));
assertFalse(Objects.equals(new Date(), 123));
}
}
././@LongLink 0000000 0000000 0000000 00000000162 00000000000 011564 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/ClassesUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/ClassesUnit0000644 0001750 0001750 00000002110 10774222622 033317 0 ustar twerner twerner package org.jboss.test.util.test;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.jboss.util.Classes;
/**
* Unit tests for org.jboss.util.Classes utility
*
* @author Dimitris.Andreadis@jboss.org
* @version $Revision: 43534 $
*/
public class ClassesUnitTestCase extends TestCase
{
public void testGetAllInterfaces()
{
List> list = new ArrayList>();
Classes.getAllInterfaces(list, ExtendedClass.class);
assertEquals(3, list.size());
assertEquals(Interface1.class, list.get(0));
assertEquals(Interface1.class, list.get(1));
assertEquals(Interface2.class, list.get(2));
}
public void testGetAllUniqueInterfaces()
{
Class>[] interfaces = Classes.getAllUniqueInterfaces(ExtendedClass.class);
assertEquals(2, interfaces.length);
}
public interface Interface1 {}
public interface Interface2 {}
public static class BaseClass implements Interface1, Interface2 {}
public static class ExtendedClass extends BaseClass implements Interface1 {}
} libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/loading/ 0000755 0001750 0001750 00000000000 11105642362 032556 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000223 00000000000 011562 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/loading/ConstructorTCCLClassLoaderSourceUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/loading/Con0000644 0001750 0001750 00000004313 10774222622 033225 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.loading;
import org.jboss.util.loading.ClassLoaderSource;
import org.jboss.util.loading.ConstructorTCCLClassLoaderSource;
/**
* Unit tests of {@link ConstructorTCCLClassLoaderSource}.
*
* @author Brian Stansberry
*/
public class ConstructorTCCLClassLoaderSourceUnitTestCase extends ClassLoaderSourceTestBase
{
public ConstructorTCCLClassLoaderSourceUnitTestCase(String name)
{
super(name);
}
@Override
protected ClassLoaderSource createClassLoaderSource()
{
return new ConstructorTCCLClassLoaderSource();
}
@Override
protected ClassLoader getExpectedClassLoader(ClassLoader tccl)
{
return tccl;
}
/**
* Tests that the ClassLoaderSource does not prevent garbage collection of
* the classloader.
*/
public void testGarbageCollectedClassLoader()
{
ClassLoader cl = getExtendedClassLoader();
Thread.currentThread().setContextClassLoader(cl);
ClassLoaderSource cls = createClassLoaderSource();
Thread.currentThread().setContextClassLoader(origCl);
cl = null;
System.gc();
assertNull("ClassLoader garbage collected", cls.getClassLoader());
}
}
././@LongLink 0000000 0000000 0000000 00000000200 00000000000 011555 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/loading/ClassLoaderSourceTestBase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/loading/Cla0000644 0001750 0001750 00000006757 10774161402 033221 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.loading;
import junit.framework.TestCase;
import org.jboss.util.loading.ClassLoaderSource;
/**
* Base class for testing {@link ClassLoaderSource} implementations.
*
* @author Brian Stansberry
*/
public abstract class ClassLoaderSourceTestBase extends TestCase
{
protected ClassLoader origCl;
/**
* @param name
*/
public ClassLoaderSourceTestBase(String name)
{
super(name);
}
@Override
protected void setUp() throws Exception
{
super.setUp();
origCl = Thread.currentThread().getContextClassLoader();
}
@Override
protected void tearDown() throws Exception
{
try
{
super.tearDown();
}
finally
{
Thread.currentThread().setContextClassLoader(origCl);
}
}
protected abstract ClassLoaderSource createClassLoaderSource();
protected abstract ClassLoader getExpectedClassLoader(ClassLoader tccl);
/**
* Tests that the ClassLoaderSource returns the expected classloader
* when the TCCL is null.
*/
public void testNullTCCL()
{
checkCorrectClassLoaderSource(null);
}
/**
* Tests that the ClassLoaderSource returns the expected classloader
* when the TCCL is the basic one in place when this test is executed.
*/
public void testOriginalTCCL()
{
checkCorrectClassLoaderSource(origCl);
}
/**
* Tests that the ClassLoaderSource returns the expected classloader
* when the TCCL is the CLS impl's own classloader.
*/
public void testImplClassLoader()
{
checkCorrectClassLoaderSource(createClassLoaderSource().getClass().getClassLoader());
}
/**
* Tests that the ClassLoaderSource returns the expected classloader
* when the TCCL is a child classloader.
*/
public void testDifferentTCCL()
{
checkCorrectClassLoaderSource(getExtendedClassLoader());
}
protected void checkCorrectClassLoaderSource(ClassLoader tccl)
{
Thread.currentThread().setContextClassLoader(tccl);
ClassLoaderSource cls = createClassLoaderSource();
assertSame("ClassLoaderSource returned expected cl", getExpectedClassLoader(tccl), cls.getClassLoader());
}
protected ClassLoader getExtendedClassLoader()
{
return new ExtendedClassLoader(origCl);
}
private class ExtendedClassLoader extends ClassLoader
{
ExtendedClassLoader(ClassLoader parent)
{
super(parent);
}
}
}
././@LongLink 0000000 0000000 0000000 00000000221 00000000000 011560 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/loading/MyClassLoaderClassLoaderSourceUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/loading/MyC0000644 0001750 0001750 00000003347 10772776222 033214 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.loading;
import org.jboss.util.loading.ClassLoaderSource;
import org.jboss.util.loading.MyClassLoaderClassLoaderSource;
/**
* Unit tests of {@link MyClassLoaderClassLoaderSource}.
*
* @author Brian Stansberry
*/
public class MyClassLoaderClassLoaderSourceUnitTestCase extends ClassLoaderSourceTestBase
{
public MyClassLoaderClassLoaderSourceUnitTestCase(String name)
{
super(name);
}
@Override
protected ClassLoaderSource createClassLoaderSource()
{
return new MyClassLoaderClassLoaderSource();
}
@Override
protected ClassLoader getExpectedClassLoader(ClassLoader tccl)
{
return MyClassLoaderClassLoaderSource.class.getClassLoader();
}
}
././@LongLink 0000000 0000000 0000000 00000000201 00000000000 011556 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/StringPropertyReplacerUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/StringPrope0000644 0001750 0001750 00000022517 11103042136 033336 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test;
import java.util.Properties;
import junit.framework.TestCase;
import static org.jboss.util.StringPropertyReplacer.replaceProperties;
/**
* A StringPropertyReplacerUnitTestCase.
*
* @author Brian Stansberry
* @version $Revision$
*/
public class StringPropertyReplacerUnitTestCase extends TestCase
{
private static final String PROP_A = "string.prop.replace.test.a";
private static final String PROP_B = "string.prop.replace.test.b";
private static final String PROP_C = "string.prop.replace.test.c";
private static final String PROP_D = "string.prop.replace.test.d";
private static final String DEFAULT = "DEFAULT";
private static final String VALUE = "VALUE";
private static final String WRAPPER = "wrapper";
@Override
protected void tearDown() throws Exception
{
super.tearDown();
System.clearProperty(PROP_A);
System.clearProperty(PROP_B);
System.clearProperty(PROP_C);
System.clearProperty(PROP_D);
}
private static Properties setupProperties()
{
Properties props = new Properties();
props.put(PROP_A, VALUE);
props.put(PROP_C, VALUE);
return props;
}
private static void setupSystemProperties()
{
System.setProperty(PROP_A, VALUE);
System.setProperty(PROP_C, VALUE);
}
public void testNullInput()
{
try
{
assertNull(replaceProperties(null));
fail("NPE expected with null input");
}
catch (NullPointerException good) {}
try
{
assertNull(replaceProperties(null, setupProperties()));
fail("NPE expected with null input");
}
catch (NullPointerException good) {}
}
public void testBasicReplacement()
{
basicReplacementTest(false);
}
public void testBasicReplacementFromSystemProps()
{
basicReplacementTest(true);
}
private void basicReplacementTest(boolean useSysProps)
{
String input = "${"+PROP_A+"}";
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(VALUE, output);
}
public void testWrappedReplacement()
{
wrappedReplacementTest(false);
}
public void testWrappedReplacementFromSystemProps()
{
wrappedReplacementTest(true);
}
private void wrappedReplacementTest(boolean useSysProps)
{
String input = WRAPPER+"${"+PROP_A+"}";
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(WRAPPER+VALUE, output);
input = "${"+PROP_A+"}"+WRAPPER;
output = null;
if (useSysProps)
{
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(VALUE+WRAPPER, output);
input = WRAPPER+"${"+PROP_A+"}"+WRAPPER;
output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(WRAPPER+VALUE+WRAPPER, output);
}
public void testMissingProperty()
{
missingPropertyTest(false);
}
public void testMissingPropertyFromSystemProps()
{
missingPropertyTest(true);
}
private void missingPropertyTest(boolean useSysProps)
{
String input = WRAPPER+"${"+PROP_B+"}"+WRAPPER;
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(input, output);
}
public void testWrappedMissingProperty()
{
wrappedMissingPropertyTest(false);
}
public void testWrappedMissingPropertyFromSystemProps()
{
wrappedMissingPropertyTest(true);
}
private void wrappedMissingPropertyTest(boolean useSysProps)
{
String input = WRAPPER+"${"+PROP_B+"}"+WRAPPER;
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(input, output);
}
public void testDefaultValue()
{
defaultValueTest(false);
}
public void testDefaultValueFromSystemProps()
{
defaultValueTest(true);
}
private void defaultValueTest(boolean useSysProps)
{
String input = "${"+PROP_B+":"+DEFAULT+"}";
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(DEFAULT, output);
}
public void testSecondaryProperty()
{
secondaryPropertyTest(false);
}
public void testSecondaryPropertyFromSystemProps()
{
secondaryPropertyTest(true);
}
private void secondaryPropertyTest(boolean useSysProps)
{
String input = "${"+PROP_B+","+PROP_C+"}";
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(VALUE, output);
}
public void testSecondaryPropertyAndDefault()
{
secondaryPropertyAndDefaultTest(false);
}
public void testSecondaryPropertyAndDefaultFromSystemProps()
{
secondaryPropertyAndDefaultTest(true);
}
private void secondaryPropertyAndDefaultTest(boolean useSysProps)
{
String input = "${"+PROP_B+","+PROP_D+":"+DEFAULT+"}";
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(DEFAULT, output);
}
public void testSecondaryPropertyAndMissing()
{
secondaryPropertyAndMissingTest(false);
}
public void testSecondaryPropertyAndMissingFromSystemProps()
{
secondaryPropertyAndMissingTest(true);
}
private void secondaryPropertyAndMissingTest(boolean useSysProps)
{
String input = "${"+PROP_B+","+PROP_D+"}";
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(input, output);
}
public void testMultipleReplacements()
{
multipleReplacementTest(false);
}
public void testMultipleReplacementsFromSystemProps()
{
multipleReplacementTest(true);
}
private void multipleReplacementTest(boolean useSysProps)
{
String input = "${"+PROP_A+"}${"+PROP_C+"}";
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(VALUE+VALUE, output);
}
public void testPartialMissing()
{
partialMissingTest(false);
}
public void testPartialMissingFromSystemProps()
{
partialMissingTest(true);
}
private void partialMissingTest(boolean useSysProps)
{
String badinput = "${"+PROP_B+"}";
String input = WRAPPER+"${"+PROP_A+"}"+badinput+"${"+PROP_C+"}"+WRAPPER;
String output = null;
if (useSysProps)
{
setupSystemProperties();
output = replaceProperties(input);
}
else
{
output = replaceProperties(input, setupProperties());
}
assertEquals(WRAPPER+VALUE+badinput+VALUE+WRAPPER, output);
}
}
././@LongLink 0000000 0000000 0000000 00000000151 00000000000 011562 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/propertyeditor/ libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/propertyedi0000755 0001750 0001750 00000000000 11105642362 033430 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000211 00000000000 011557 L ustar root root libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/propertyeditor/PropertyEditorsUnitTestCase.java libjboss-common-java-0.0+svn2938.orig/common-core/src/test/java/org/jboss/test/util/test/propertyedi0000644 0001750 0001750 00000045753 11103542066 033446 0 ustar twerner twerner /*
* JBoss, Home of Professional Open Source.
* Copyright 2006, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.util.test.propertyeditor;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.io.File;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import junit.framework.TestCase;
import org.jboss.logging.Logger;
import org.jboss.util.propertyeditor.DateEditor;
import org.jboss.util.propertyeditor.DocumentEditor;
import org.jboss.util.propertyeditor.ElementEditor;
import org.jboss.util.propertyeditor.PropertyEditors;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Unit tests for the custom JBoss property editors
*
* @see org.jboss.util.propertyeditor.PropertyEditors
*
* @author Scott.Stark@jboss.org
* @author Dimitris.Andreadis@jboss.org
* @author Ales.Justin@jboss.org
* @version $Revision: 43534 $
*/
@SuppressWarnings("unchecked")
public class PropertyEditorsUnitTestCase extends TestCase
{
private static Logger log = Logger.getLogger(PropertyEditorsUnitTestCase.class);
Calendar calendar = Calendar.getInstance();
private Locale locale;
/** Augment the PropertyEditorManager search path to incorporate the JBoss
specific editors. This simply references the PropertyEditors.class to
invoke its static initialization block.
*/
static
{
PropertyEditors.init();
String[] paths = PropertyEditorManager.getEditorSearchPath();
log.info(Arrays.asList(paths));
}
static class StringArrayComparator implements Comparator
{
public int compare(Object o1, Object o2)
{
String[] a1 = (String[]) o1;
String[] a2 = (String[]) o2;
int compare = a1.length - a2.length;
for(int n = 0; n < a1.length; n ++)
compare += a1[n].compareTo(a2[n]);
return compare;
}
}
static class ClassArrayComparator implements Comparator
{
public int compare(Object o1, Object o2)
{
Class>[] a1 = (Class[]) o1;
Class>[] a2 = (Class[]) o2;
int compare = a1.length - a2.length;
for(int n = 0; n < a1.length; n ++)
{
int hash1 = a1[n].hashCode();
int hash2 = a2[n].hashCode();
compare += hash1 - hash2;
}
return compare;
}
}
static class IntArrayComparator implements Comparator
{
public int compare(Object o1, Object o2)
{
int[] a1 = (int[]) o1;
int[] a2 = (int[]) o2;
int compare = a1.length - a2.length;
for(int n = 0; n < a1.length; n ++)
compare += a1[n] - a2[n];
return compare;
}
}
static class NumberComparator implements Comparator
{
public int compare(Number o1, Number o2)
{
return o1.intValue() - o2.intValue();
}
}
static class ToStringComparator implements Comparator
{
public int compare(Object o1, Object o2)
{
String s1 = o1.toString();
String s2 = o2.toString();
return s1.compareTo(s2);
}
}
public PropertyEditorsUnitTestCase(String name)
{
super(name);
}
protected void setUp() throws Exception
{
locale = Locale.getDefault();
Locale.setDefault(Locale.US);
super.setUp();
}
protected void tearDown() throws Exception
{
super.tearDown();
Locale.setDefault(locale);
}
public void testEditorSearchPath()
throws Exception
{
log.debug("+++ testEditorSearchPath");
String[] searchPath = PropertyEditorManager.getEditorSearchPath();
boolean foundJBossPath = false;
for(int p = 0; p < searchPath.length; p ++)
{
String path = searchPath[p];
log.debug("path["+p+"]="+path);
foundJBossPath |= path.equals("org.jboss.util.propertyeditor");
}
assertTrue("Found org.jboss.util.propertyeditor in search path", foundJBossPath);
}
/** The mechanism for mapping java.lang.* variants of the primative types
misses editors for java.lang.Boolean and java.lang.Integer. Here we test
the java.lang.* variants we expect editors for.
* @throws Exception
**/
public void testJavaLangEditors()
throws Exception
{
log.debug("+++ testJavaLangEditors");
// The supported java.lang.* types
Class[] types = {
Boolean.class,
Byte.class,
Short.class,
Integer.class,
Long.class,
Float.class,
Double.class,
Byte.class,
Character.class,
};
// The input string data for each type
String[][] inputData = {
{"true", "false", "TRUE", "FALSE", "tRuE", "FaLsE", null},
{"1", "-1", "0", "0x1A"},
{"1", "-1", "0", "0xA0"},
{"1", "-1", "0", "0xA0"},
{"1", "-1", "0", "1000"},
{"1", "-1", "0", "1000.1"},
{"1", "-1", "0", "1000.1"},
{"0x1", "-#1", "0"},
{"A", "a", "Z", "z"},
};
// The expected java.lang.* instance for each inputData value
Object[][] expectedData = {
{Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, null},
{Byte.valueOf("1"), Byte.valueOf("-1"), Byte.valueOf("0"), Byte.decode("0x1A")},
{Short.valueOf("1"), Short.valueOf("-1"), Short.valueOf("0"), Short.decode("0xA0")},
{Integer.valueOf("1"), Integer.valueOf("-1"), Integer.valueOf("0"), Integer.decode("0xA0")},
{Long.valueOf("1"), Long.valueOf("-1"), Long.valueOf("0"), Long.valueOf("1000")},
{Float.valueOf("1"), Float.valueOf("-1"), Float.valueOf("0"), Float.valueOf("1000.1")},
{Double.valueOf("1"), Double.valueOf("-1"), Double.valueOf("0"), Double.valueOf("1000.1")},
{Byte.valueOf("1"), Byte.valueOf("-1"), Byte.valueOf("0")},
{new Character('A'), new Character('a'), new Character('Z'), new Character('z')},
};
// The expected string output from getAsText()
String[][] expectedStringData = {
{"true", "false", "true", "false", "true", "false", "null"},
{"1", "-1", "0", "26"},
{"1", "-1", "0", "160"},
{"1", "-1", "0", "160"},
{"1", "-1", "0", "1000"},
{"1.0", "-1.0", "0.0", "1000.1"},
{"1.0", "-1.0", "0.0", "1000.1"},
{"1", "-1", "0"},
{"A", "a", "Z", "z"},
};
Comparator[] comparators = new Comparator[types.length];
doTests(types, inputData, expectedData, expectedStringData, comparators);
}
/** Test custom JBoss property editors.
* @throws Exception
*/
public void testJBossEditors()
throws Exception
{
log.debug("+++ testJBossEditors");
Class[] types = {
java.io.File.class,
java.net.URL.class,
java.net.URI.class,
java.lang.String.class,
java.lang.Class.class,
InetAddress.class,
String[].class,
Class[].class,
int[].class,
Date.class,
java.util.Properties.class,
Locale.class,
AtomicInteger.class,
AtomicLong.class,
AtomicBoolean.class,
};
// The input string data for each type
String[][] inputData = {
// java.io.File.class
{"/tmp/test1", "/tmp/subdir/../test2"},
// java.net.URL.class
{"http://www.jboss.org", "file:/path with space/tst.xml"},
// java.net.URI.class
{"http://www.jboss.org", "file:/path with space/tst.xml"},
// java.lang.String.class
{"JBoss, Home of Professional Open Source"},
// java.lang.Class.class
{"java.util.Arrays"},
// InetAddress.class, localhost must be defined for this to work
{"127.0.0.1", "localhost"},
// String[].class
{"1,2,3", "a,b,c", "", "#,%,\\,,.,_$,\\,v"},
// Class[].class
{"java.lang.Integer,java.lang.Float"},
// int[].class
{"0,#123,-123"},
// Date.class
{"Jan 4, 2005", "Tue Jan 4 23:38:21 PST 2005", "Tue, 04 Jan 2005 23:38:48 -0800"},
// java.util.Properties.class
{"prop1=value1\nprop2=value2\nprop3=value3\nprop32=${prop3}\nprop4=${user.home}\nprop5=${some.win32.path}"},
{Locale.getDefault().toString(), "ja_JP"},
{"-1", "0", "1"},
{"-1", "0", "1"},
{"true", "false"},
};
// The expected instance for each inputData value
calendar.set(2005, 0, 4, 0, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
Date date1 = calendar.getTime();
calendar.setTimeZone(TimeZone.getTimeZone("PST"));
calendar.set(2005, 0, 4, 23, 38, 21);
Date date2 = calendar.getTime();
calendar.set(2005, 0, 4, 23, 38, 48);
Date date3 = calendar.getTime();
Properties props = new Properties();
props.setProperty("prop1", "value1");
props.setProperty("prop2", "value2");
props.setProperty("prop3", "value3");
props.setProperty("prop32", "value3");
props.setProperty("prop4", System.getProperty("user.home"));
System.setProperty("some.win32.path", "C:\\disk1\\root\\");
props.setProperty("prop5", "C:\\disk1\\root\\");
Object[][] expectedData = {
{new File("/tmp/test1").getCanonicalFile(), new File("/tmp/test2").getCanonicalFile()},
{new URL("http://www.jboss.org"), new File("/path with space/tst.xml").getCanonicalFile().toURI().toURL()},
{new URI("http://www.jboss.org"), new File("/path with space/tst.xml").getCanonicalFile().toURI()},
{new String("JBoss, Home of Professional Open Source")},
{java.util.Arrays.class},
{InetAddress.getByName("127.0.0.1"), InetAddress.getByName("localhost")},
{new String[]{"1", "2", "3"}, new String[] {"a", "b", "c"},
new String[]{}, new String[]{"#","%",",",".","_$", ",v"}},
{new Class[]{Integer.class, Float.class}},
{new int[]{0, 0x123, -123}},
{date1, date2, date3},
{props},
{Locale.getDefault(), Locale.JAPAN},
{new AtomicInteger(-1), new AtomicInteger(0), new AtomicInteger(1)},
{new AtomicLong(-1), new AtomicLong(0), new AtomicLong(1)},
{new AtomicBoolean(true), new AtomicBoolean(false)},
};
// The expected string output from getAsText()
String[][] expectedStringData = {
// java.io.File.class
{"/tmp/test1", "/tmp/subdir/../test2"},
// java.net.URL.class
{"http://www.jboss.org", "file:/path with space/tst.xml"},
// java.net.URI.class
{"http://www.jboss.org", "file:/path with space/tst.xml"},
// java.lang.String.class
{"JBoss, Home of Professional Open Source"},
// java.lang.Class.class
{"java.util.Arrays"},
// InetAddress.class, localhost must be defined for this to work
{"127.0.0.1", "localhost"},
// String[].class
{"1,2,3", "a,b,c", "", "#,%,\\,,.,_$,,v"},
// Class[].class
{"java.lang.Integer,java.lang.Float"},
// int[].class
{"0,291,-123"},
// Date.class
{"Jan 4, 2005", "Tue Jan 4 23:38:21 PST 2005", "Tue, 04 Jan 2005 23:38:48 -0800"},
// java.util.Properties.class
{props.toString()},
{Locale.getDefault().toString(), Locale.JAPAN.toString()},
{"-1", "0", "1"},
{"-1", "0", "1"},
{"true", "false"},
};
// The Comparator for non-trival types
Comparator[] comparators = {
null, // File
null, // URL
null, // URI
null, // String
null, // Class
null, // InetAddress
new StringArrayComparator(), // String[]
new ClassArrayComparator(), // Class[]
new IntArrayComparator(), // int[]
null, // Date
null, // Properties
null, // Locale
new NumberComparator(),
new NumberComparator(),
new ToStringComparator(),
};
doTests(types, inputData, expectedData, expectedStringData, comparators);
}
public void testDateEditor() throws Exception
{
log.debug("+++ testDateEditor");
Locale locale = Locale.getDefault();
try
{
// Use the default locale
log.debug("Current Locale: " + Locale.getDefault());
// An important date
String text = "Fri, 25 Jun 1971 00:30:00 +0200";
DateFormat format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
Date date = format.parse(text);
PropertyEditor editor = new DateEditor();
editor.setAsText(text);
log.debug("setAsText('" + text + "') --> getValue() = '" + editor.getValue() + "'");
assertTrue("Compare date1: " + date + ", date2: " + editor.getValue(),
date.compareTo((Date)editor.getValue()) == 0);
editor.setValue(date);
log.debug("setValue('" + date + "') --> getAsText() - '" + editor.getAsText() + "'");
Date date2 = format.parse(editor.getAsText());
assertTrue("Compare date1: " + date + ", date2: " + date2, date.compareTo(date2) == 0);
// Try in French
Locale.setDefault(Locale.FRENCH);
log.debug("Current Locale: " + Locale.getDefault());
DateEditor.initialize();
// An important date
text = "ven., 25 juin 1971 00:30:00 +0200";
format = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
date = format.parse(text);
editor = new DateEditor();
editor.setAsText(text);
log.debug("setAsText('" + text + "') --> getValue() = '" + editor.getValue() + "'");
assertTrue("Compare date1: " + date + ", date2: " + editor.getValue(), date.compareTo((Date)editor.getValue()) == 0);
editor.setValue(date);
log.debug("setValue('" + date + "') --> getAsText() = '" + editor.getAsText() + "'");
date2 = format.parse(editor.getAsText());
assertTrue("Compare date1: " + date + ", date2: " + date2, date.compareTo(date2) == 0);
}
finally
{
// reset locale
Locale.setDefault(locale);
DateEditor.initialize();
}
}
/**
* Tests the DOM Document and Element editors.
*/
public void testDocumentElementEditors()
{
log.debug("+++ testDocumentElementEditors");
DocumentEditor de = new DocumentEditor();
// Comments can appear outside of a document
String s = "";
log.debug("setAsText '" + s + "'");
de.setAsText(s);
log.debug("Parsed XML document:");
log((Node)de.getValue(), " ");
log.debug("getAsText '" + de.getAsText() + "'");
assertTrue("Document :\n" + de.getAsText(), de.getAsText().trim().endsWith(s));
assertTrue(de.getValue() instanceof org.w3c.dom.Document);
// Test whitespace preservation
s = "\n\n testing\n\n";
de.setAsText(s);
assertTrue("Document :\n" + de.getAsText() + "\nvs\n" + s, de.getAsText().trim().endsWith(s));
ElementEditor ee = new ElementEditor();
s = "text";
ee.setAsText(s);
assertEquals(s, ee.getAsText());
assertTrue(ee.getValue() instanceof org.w3c.dom.Element);
}
private void doTests(Class[] types, String[][] inputData, Object[][] expectedData,
String[][] expectedStringData, Comparator[] comparators)
{
for(int t = 0; t < types.length; t ++)
{
Class type = types[t];
log.debug("Checking property editor for: "+type);
PropertyEditor editor = PropertyEditorManager.findEditor(type);
assertTrue("Found property editor for: "+type, editor != null);
log.debug("Found property editor for: "+type+", editor="+editor.getClass().getName());
assertEquals(editor+" input length", inputData[t].length, expectedData[t].length);
for(int i = 0; i < inputData[t].length; i ++)
{
String input = inputData[t][i];
editor.setAsText(input);
Object expected = expectedData[t][i];
Object output = editor.getValue();
Comparator c = comparators[t];
boolean equals = false;
if (c == null)
{
equals = output != null ? output.equals(expected) : expected == null;
}
else
{
equals = c.compare(output, expected) == 0;
}
if( equals == false )
System.err.println(output+" != "+input);
assertTrue("Transform("+editor+") of "+input+" equals "+expected+", output="+output, equals);
String expectedStringOutput = expectedStringData[t][i];
String stringOutput = editor.getAsText();
log.debug("setAsText '" + logString(input) + "'");
log.debug("getAsText '" + logString(stringOutput) + "'");
if( type != Properties.class )
{
// We can't meaningfully compare the PropertiesEditor string output
String msg = "PropertyEditor: " + editor.getClass().getName() + ", getAsText() == expectedStringOutput '";
assertEquals(msg, expectedStringOutput, stringOutput);
}
}
}
}
/**
* Log a Node hierarchy
*/
private void log(Node node, String indent)
{
String name = node.getNodeName();
String value = node.getNodeValue();
log.debug(indent + "Name=" + name + ", Value=" + value);
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++)
log(list.item(i), indent + indent);
}
private static String logString(String s)
{
return s != null ? s : "";
}
}
libjboss-common-java-0.0+svn2938.orig/common-core/src/test/resources/ 0000755 0001750 0001750 00000000000 11105642362 025410 5 ustar twerner twerner libjboss-common-java-0.0+svn2938.orig/common-core/src/test/resources/tst-config_5.xsd 0000644 0001750 0001750 00000000430 10776055124 030435 0 ustar twerner twerner