package org.jetel.test;

import junit.framework.TestCase;

import org.jetel.graph.runtime.EngineInitializer;

public abstract class CloverTestCase extends TestCase {

	public CloverTestCase() {
		super();
	}

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

	private static final String PLUGINS_KEY = "cloveretl.plugins";

	private static final String PLUGINS_DEFAULT_DIR = "..";


	protected void initEngine() {
		initEngine(null);
	}
	
	protected void initEngine(String defaultPropertiesFile) {
		final String pluginsDir;

		final String pluginsProperty = System.getenv(PLUGINS_KEY);
		if (pluginsProperty != null) {
			pluginsDir = pluginsProperty;
		} else {
			pluginsDir = PLUGINS_DEFAULT_DIR;
		}

		System.out.println("Cloveretl plugins: " + pluginsDir);
		EngineInitializer.initEngine(pluginsDir, defaultPropertiesFile, null);
		EngineInitializer.forceActivateAllPlugins();
	}

}

@@ -30,82 +30,783 @@
 rt j
-unit.framework.TestCase;%0A%0Aimport org.jetel.graph.runtime.EngineInitializer
+ava.io.BufferedInputStream;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.InputStream;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.Future;%0A%0Aimport junit.framework.TestCase;%0A%0Aimport org.apache.commons.io.IOUtils;%0Aimport org.jetel.exception.ComponentNotReadyException;%0Aimport org.jetel.exception.GraphConfigurationException;%0Aimport org.jetel.exception.XMLConfigurationException;%0Aimport org.jetel.graph.Result;%0Aimport org.jetel.graph.TransformationGraph;%0Aimport org.jetel.graph.TransformationGraphXMLReaderWriter;%0Aimport org.jetel.graph.runtime.EngineInitializer;%0Aimport org.jetel.graph.runtime.GraphRuntimeContext;%0Aimport org.jetel.graph.runtime.SimpleThreadManager;%0Aimport org.jetel.graph.runtime.WatchDog
 ;%0A%0Ap
@@ -1589,10 +1589,1516 @@
 ();%0A%09%7D%0A%0A
+%09@Override%0A%09protected void setUp() throws Exception %7B%0A%09%09if (!EngineInitializer.isInitialized()) %7B%0A%09%09%09initEngine(getCloverPropertiesFile());%0A%09%09%7D%0A%09%7D%0A%09%0A%09protected String getCloverPropertiesFile() %7B%0A%09%09return null;%0A%09%7D%0A%09%0A%09protected TransformationGraph createTransformationGraph(String path, GraphRuntimeContext context)%0A%09%09throws FileNotFoundException, GraphConfigurationException, XMLConfigurationException, ComponentNotReadyException %7B%0A%09%09%0A%09%09InputStream in = new BufferedInputStream(new FileInputStream(path));%0A%09%09try %7B%0A%09%09%09context.setUseJMX(false);%0A%09%09%09TransformationGraph graph = TransformationGraphXMLReaderWriter.loadGraph(in, context);%0A%09%09%09EngineInitializer.initGraph(graph, context);%0A%09%09%09return graph;%0A%09%09%7D finally %7B%0A%09%09%09IOUtils.closeQuietly(in);%0A%09%09%7D%0A%09%7D%0A%09%0A%09protected Result runGraph(TransformationGraph graph)%0A%09%09throws ExecutionException, InterruptedException %7B%0A%09%09%0A%09%09WatchDog watchDog = new WatchDog(graph, graph.getRuntimeContext());%0A%09%09watchDog.init();%0A%09%09SimpleThreadManager manager = new SimpleThreadManager();%0A%09%09Future%3CResult%3E result = manager.executeWatchDog(watchDog);%0A%09%09Result value = result.get();%0A%09%09if (value == Result.ERROR) %7B%0A%09%09%09rethrowRuntime(watchDog.getCauseException());%0A%09%09%7D%0A%09%09return value;%0A%09%7D%0A%09%0A%09protected static void rethrowRuntime(Throwable throwable) %7B%0A%09%09%0A%09%09if (throwable instanceof RuntimeException) %7B%0A%09%09%09throw (RuntimeException)throwable;%0A%09%09%7D else if (throwable instanceof Error) %7B%0A%09%09%09throw (Error)throwable;%0A%09%09%7D else %7B%0A%09%09%09throw new RuntimeException(throwable.getMessage(), throwable);%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

test for XPathBeanReader downgraded to JUnit 3