You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.9 KiB
53 lines
1.9 KiB
package de.superx; |
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
import java.util.Map; |
|
|
|
import org.apache.log4j.Logger; |
|
import org.junit.Ignore; |
|
import org.pentaho.di.core.Result; |
|
import org.pentaho.di.core.database.DatabaseMeta; |
|
import org.pentaho.di.core.logging.LogLevel; |
|
import org.pentaho.di.job.Job; |
|
import org.pentaho.di.job.JobMeta; |
|
import org.pentaho.di.metastore.DatabaseMetaStoreUtil; |
|
import org.pentaho.metastore.api.exceptions.MetaStoreException; |
|
import org.pentaho.metastore.stores.memory.MemoryMetaStore; |
|
|
|
@Ignore |
|
public class KettleTestRunner { |
|
|
|
private static Logger logger = Logger.getLogger(KettleTestRunner.class); |
|
|
|
public static void runKettleJob(String jobFile, Map<String,String> parameters, LogLevel logLevel) { |
|
try { |
|
MemoryMetaStore metastore = new MemoryMetaStore(); |
|
initKettleEnvironment(metastore); |
|
JobMeta jobMeta = new JobMeta(null, jobFile, null, metastore, null); |
|
for (String key : parameters.keySet()) { |
|
jobMeta.setParameterValue(key, parameters.get(key)); |
|
} |
|
Job job = new Job(null, jobMeta); |
|
job.setLogLevel(logLevel); |
|
job.start(); |
|
job.waitUntilFinished(); |
|
notifyLoggedErrors(job); |
|
} catch (Exception e) { |
|
logger.error("Couldn't run kettle job!", e); |
|
} |
|
} |
|
|
|
private static void initKettleEnvironment(MemoryMetaStore metastore) throws MetaStoreException { |
|
DatabaseMeta dbmeta = new DatabaseMeta("eduetl", "POSTGRESQL", "JNDI", null, "eduetl", "1521", null, null); |
|
DatabaseMetaStoreUtil.createDatabaseElement(metastore, dbmeta); |
|
} |
|
|
|
private static void notifyLoggedErrors(Job job) { |
|
Result result = job.getResult(); |
|
String log = result.getLogText(); |
|
boolean errorsOccured = log.contains("ERROR"); |
|
assertFalse("Errors where found in kettle log:\n" + log, errorsOccured); |
|
} |
|
|
|
}
|
|
|