Here is a test class for use with Junit.  All you need to do is include
Junit.jar in your class path and let it rip.  You can get the latest version
of Junit from http://www.junit.org.  A lot of the Jakarta projects are using
the lastest version with there build scripts.  I have found that the some of
the distributions come with version 3.2 and there is problem running some of
the test.  Particularly with the assert() method.  This class is somewhat
overkill b/c I include refs to a bunch of services, however it should have
everything we need to test database classes and action methods.  For action
Classes you will have to manually code adding objects to Context or calling
setting methods on Rundata, ie getting a User object from TurbineSecurity
and setting in RunData.
r,
Hugh


package junit.framework;

import junit.extensions.*;

import org.apache.turbine.util.TurbineConfig;
import org.apache.turbine.util.RunData;
import org.apache.turbine.services.TurbineServices;

import org.apache.turbine.services.db.*;
import org.apache.turbine.services.rundata.*;
import org.apache.turbine.services.cache.*;
import org.apache.turbine.services.security.*;
import org.apache.turbine.services.servlet.*;
import org.apache.turbine.services.pool.*;
import org.apache.turbine.services.factory.*;
import org.apache.turbine.services.pool.*;
import org.apache.turbine.services.resources.*;
import org.apache.turbine.services.assemblerbroker.*;
import org.apache.turbine.services.intake.*;
import org.apache.turbine.services.jsp.*;
import org.apache.turbine.services.localization.*;
import org.apache.turbine.services.mimetype.*;
import org.apache.turbine.services.schedule.*;
import org.apache.turbine.services.template.*;
import org.apache.turbine.services.uniqueid.*;
import org.apache.turbine.services.velocity.*;
import org.apache.turbine.services.xmlrpc.*;
import org.apache.turbine.services.xslt.*;

import org.apache.turbine.om.security.TurbineUser;
import org.apache.turbine.om.security.User;

import org.apache.velocity.context.Context;
import org.apache.velocity.VelocityContext;

import org.apache.turbine.util.db.*;
import com.novuscg.om.portal.*;
import java.util.*;

public class ActionUnitTest extends TestCase
{
    private TurbineConfig config;
    private SecurityService securityService;
    private GlobalCacheService cacheService;
    private RunDataService runDataService;
    private ServletService servletService;
    private PoolService poolService;
    private FactoryService factoryService;
    private ResourceService resourceService;
    private RunData runData;
    private Context context;
    public  static String  WEB_DIR =
"G:/jakarta-tomcat-3.2.3/webapps/jetspeed";
    public  static String  CONFIG_FILE =
"WEB-INF/conf/TurbineResources.properties";


    public ActionUnitTest(String name) {
  super(name);
 }

    protected void setUp()
    {
        config = new TurbineConfig(WEB_DIR, CONFIG_FILE);
        config.init();
         file://We could use the Static Classes such as TurbineSecurity to
invoke these classes
        file://however I am instatiating them explicit for demonstration
purposes. I don't believe
        file://all services have and associated static class for calling
service methods
        file://securityService.getAllGroups();  is the same as
TurbineSecurity.getAllGroups();
        securityService =
(SecurityService)TurbineServices.getInstance().getService(SecurityService.SE
RVICE_NAME);
        cacheService =
(GlobalCacheService)TurbineServices.getInstance().getService(GlobalCacheServ
ice.SERVICE_NAME);
        poolService =
(PoolService)TurbineServices.getInstance().getService(PoolService.SERVICE_NA
ME);
        factoryService  =
(FactoryService)TurbineServices.getInstance().getService(FactoryService.SERV
ICE_NAME);
        resourceService =
(ResourceService)TurbineServices.getInstance().getService(ResourceService.SE
RVICE_NAME);

        file://Create a RunData object to pass to doPerform
        this.runData = new DefaultTurbineRunData();

        file://Get a Context object to pass to doPerform
        this.context = new VelocityContext();

    }


    protected void tearDown()
    {
        TurbineServices.getInstance().shutdownServices();
    }

    public static Test suite() {
  return new TestSuite(ActionUnitTest.class);
 }

    public void testProducts1()
    {
        Vector vector = null;
        try
        {
            vector = ProductPeer.doSelect(new Criteria());
        }
        catch (Exception ex)
        {

        }
        boolean result = (vector.size() > 0);
        assertTrue(result);
        assertNotNull(vector);
    }

    public void testProducts2()
    {
        Vector vector = null;
        try
        {
            vector = ProductPeer.doSelect(new Criteria());
        }
        catch (Exception ex)
        {

        }
        boolean result = (vector.size() > 0);
        assertTrue(result);
        assertNotNull(vector);
    }

    public void testProducts3()
    {
        Vector vector = null;
        try
        {
            vector = ProductPeer.doSelect(new Criteria());
        }
        catch (Exception ex)
        {

        }
        boolean result = (vector.size() > 0);
        assertTrue(result);
        assertNotNull(vector);
    }

    public static void main (String[] args) {
  junit.textui.TestRunner.run (suite());
        System.exit(0);
        file://junit.swingui.TestRunner.run(ActionUnitTest.class);
 }

}


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to