com.mockrunner.test.consistency.JarReferenceTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Mockrunner is a lightweight framework for unit testing applications
in the J2EE environment. It supports servlets, filters, tag classes
and Struts actions. It includes a JDBC a JMS and a JCA test
framework and can be used to test EJB based applications.
The newest version!
package com.mockrunner.test.consistency;
import junit.framework.TestCase;
import com.mockrunner.gen.jar.TestConfigurationClassLoader;
import com.mockrunner.test.consistency.MockrunnerJarTestConfiguration.Mapping;
import com.mockrunner.util.common.MethodUtil;
public class JarReferenceTest extends TestCase
{
public void testReferenceTests() throws Exception
{
MockrunnerJarTestConfiguration configuration = new MockrunnerJarTestConfiguration();
Mapping[] mappings = configuration.createMappings();
int numberErrors = 0;
for(int ii = 0; ii < mappings.length; ii++)
{
LauncherThread thread = new LauncherThread(mappings[ii]);
thread.start();
thread.join();
if(thread.hasError())
{
numberErrors++;
}
}
assertTrue("There are errors.", numberErrors == 0);
}
private class LauncherThread extends Thread
{
private Mapping mapping;
private boolean hasError;
public LauncherThread(Mapping mapping)
{
this.mapping = mapping;
hasError = false;
}
public synchronized boolean hasError()
{
return hasError;
}
private synchronized void setHasError()
{
hasError = true;
}
public void run()
{
try
{
TestConfigurationClassLoader classLoader = new TestConfigurationClassLoader(mapping.getUrls(), this.getClass().getClassLoader());
Object launcher = classLoader.loadClass("com.mockrunner.test.consistency.Launcher").newInstance();
setContextClassLoader(classLoader);
System.out.println("Executing reference test for " + mapping.getUrls()[0] + ": " + mapping.getTestClass());
MethodUtil.invoke(launcher, "run", mapping.getTestClass());
}
catch(Exception exc)
{
setHasError();
}
}
}
}