[jboss-cvs] jboss-portal/test/src/main/org/jboss/portal/test/framework/junit ...
Julien Viet
julien at jboss.com
Mon Jul 24 10:19:29 EDT 2006
User: julien
Date: 06/07/24 10:19:29
Added: test/src/main/org/jboss/portal/test/framework/junit
DatabaseTestSuite.java
Log:
added DatabaseTestsuite that helps to create a testsuite for a specific database configuration
Revision Changes Path
1.1 date: 2006/07/24 14:19:29; author: julien; state: Exp;jboss-portal/test/src/main/org/jboss/portal/test/framework/junit/DatabaseTestSuite.java
Index: DatabaseTestSuite.java
===================================================================
/*
* 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.portal.test.framework.junit;
import junit.framework.TestSuite;
import junit.framework.TestCase;
import org.jboss.portal.test.framework.embedded.DataSourceSupport;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* Database test suite.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class DatabaseTestSuite extends TestSuite
{
/** . */
private DataSourceSupport.Config[] configs;
public DatabaseTestSuite(DataSourceSupport.Config[] configs)
{
this.configs = configs;
}
public DataSourceSupport.Config[] getConfigs()
{
return configs;
}
public void addTestCase(Class clazz) throws IllegalArgumentException
{
try
{
Constructor ctor = clazz.getConstructor(new Class[]{DataSourceSupport.Config.class});
//
for (int i = 0; i < configs.length; i++)
{
DataSourceSupport.Config config = configs[i];
//
Method[] methods = clazz.getMethods();
for (int j = 0; j < methods.length; j++)
{
Method method = methods[j];
int modifiers = method.getModifiers();
if (Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers) && method.getName().startsWith("test"))
{
TestCase testCase = (TestCase)ctor.newInstance(new Object[]{config});
testCase.setName(method.getName());
addTest(testCase);
}
}
}
}
catch (InstantiationException e)
{
IllegalArgumentException iae = new IllegalArgumentException();
iae.initCause(e);
throw iae;
}
catch (NoSuchMethodException e)
{
IllegalArgumentException iae = new IllegalArgumentException();
iae.initCause(e);
throw iae;
}
catch (IllegalAccessException e)
{
IllegalArgumentException iae = new IllegalArgumentException();
iae.initCause(e);
throw iae;
}
catch (InvocationTargetException e)
{
IllegalArgumentException iae = new IllegalArgumentException();
iae.initCause(e);
throw iae;
}
}
}
More information about the jboss-cvs-commits
mailing list