/*
* Name: BasicProcessManagerTest
* Author: Richard Rodger
*
* Copyright (c) 2004 Richard Rodger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
// package
package org.jostraca.process.test;
// import
import org.jostraca.Property;
import org.jostraca.Service;
import org.jostraca.Template;
import org.jostraca.format.BasicFormatManager;
import org.jostraca.format.FormatManager;
import org.jostraca.process.BasicProcessManager;
import org.jostraca.process.ProcessException;
import org.jostraca.process.TemplateHandlerManager;
import org.jostraca.util.ListUtil;
import org.jostraca.util.PropertySet;
import org.jostraca.util.UserMessageHandler;
import org.jostraca.util.CommandLineUserMessageHandler;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
/** Test cases for TemplateHandlerManager.
*/
public class BasicProcessManagerTest extends TestCase {
// test framework
public BasicProcessManagerTest( String pName ) {
super( pName );
}
public static TestSuite suite() {
return new TestSuite( BasicProcessManagerTest.class );
}
public static void main( String[] pArgs ) {
TestRunner.run( suite() );
}
// test methods
public void testProcessManager() throws Exception {
CommandLineUserMessageHandler cm = new CommandLineUserMessageHandler();
FormatManager fm = new BasicFormatManager();
Template tm01 = PackageTest.makeTemplate("tm01");
Template tm02 = PackageTest.makeTemplate("tm02");
ArrayList tmlist = ListUtil.make( tm01, tm02 );
preprocess( cm, fm, tmlist );
PropertySet sysps = PackageTest.getSystemPropertySet();
sysps.set( Property.main_ProcessStages, "Preparer,Parser,Merger,Saver,Compiler,Controller" );
BasicProcessManager bpsm = new BasicProcessManager( sysps );
bpsm.setUserMessageHandler( cm );
bpsm.setFormatManager(fm);
try {
bpsm.process( tmlist );
}
catch( ProcessException pe ) {
pe.getContained().printStackTrace();
throw pe;
}
}
public void preprocess( UserMessageHandler pCM, FormatManager pFM, List pTmList ) {
for( Iterator tmT = pTmList.iterator(); tmT.hasNext(); ) {
Template tm = (Template) tmT.next();
tm.getPropertySet( Service.CONF_template )
.set( TemplateHandlerManager.PROPERTY_PREFIX+"Preparer", "org.jostraca.process.GenericPreparer" );
tm.getPropertySet(Service.CONF_template)
.set( TemplateHandlerManager.PROPERTY_PREFIX+"Parser", "org.jostraca.process.GenericParser" );
tm.getPropertySet(Service.CONF_template)
.set( TemplateHandlerManager.PROPERTY_PREFIX+"Merger", "org.jostraca.process.GenericMerger" );
tm.getPropertySet(Service.CONF_template)
.set( TemplateHandlerManager.PROPERTY_PREFIX+"Saver", "org.jostraca.process.GenericSaver" );
tm.getPropertySet(Service.CONF_template)
.set( TemplateHandlerManager.PROPERTY_PREFIX+"Compiler", "org.jostraca.process.InternalJavaCompiler" );
tm.getPropertySet(Service.CONF_template)
.set( TemplateHandlerManager.PROPERTY_PREFIX+"Controller", "org.jostraca.process.InternalJavaController" );
}
}
}