SuperX-Kernmodul
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.
 
 
 
 
 
 

118 lines
4.9 KiB

package de.superx.kettle.statistics;
import java.io.File;
import java.util.HashMap;
import javax.sql.DataSource;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.database.DataSourceProviderFactory;
import org.pentaho.di.core.database.DataSourceProviderInterface;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogLevel;
import org.pentaho.di.metastore.DatabaseMetaStoreUtil;
import org.pentaho.metastore.api.exceptions.MetaStoreException;
import org.pentaho.metastore.stores.memory.MemoryMetaStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import de.superx.KettleTestRunner;
import de.superx.db.H2InMemoryCreator;
import de.superx.stat.StatisticsBase;
import de.superx.util.test.KettleH2TestDataSourceProvider;
/**
* Base class to execute kettle jobs with different parameters
* @author hiber
*
*/
@Ignore
public class StudentAndExaminationOfficialStatisticBase {
private static final Logger LOG = LoggerFactory.getLogger(StudentAndExaminationOfficialStatisticBase.class);
protected static final String KETTLE_JOB_FILE = "superx/WEB-INF/conf/edustore/db/module/astat/etl/statistik2016/estatistik.kjb";
private static final String BASE_DIR = "test/resources/schema_files/students_and_examination_statistics";
protected static final String SCHEMA_PATH = BASE_DIR + "/schema";
protected static final String VIEWS_PATH = BASE_DIR + "/views";
protected static final String UNLOADS_PATH = BASE_DIR +"/unloads";
private static final String KETTLE_PLUGIN_DIR = String.join(File.separator, "superx", "WEB-INF", "kettle-plugins");
private static DataSource datasource = null;
@BeforeClass
public static void initEnvironment() throws Exception {
createInMemoryTestDb();
// createFileTestDb();
initKettleEnvironment();
}
protected static void runKettleJob(HashMap<String, String> parameter)
throws Exception {
KettleTestRunner.runKettleJob(KETTLE_JOB_FILE, parameter, LogLevel.BASIC);
SqlRowSet resultSet = executeQuery("SELECT * FROM " + StatisticsBase.MODULE_PREFIX + "astat");
int columnCount = resultSet.getMetaData().getColumnCount();
LOG.info("content of " + StatisticsBase.MODULE_PREFIX + "_astat:");
while(resultSet.next()) {
StringBuilder sb = new StringBuilder();
for(int i = 1; i < columnCount+1; i++) {
sb.append(resultSet.getString(i)+" ");
}
LOG.info(sb.toString());
}
}
private static void createInMemoryTestDb() throws Exception {
H2InMemoryCreator h2InMemoryCreator = new H2InMemoryCreator();
String schemaPath = new File(SCHEMA_PATH).getAbsolutePath();
String unloadsPath = new File(UNLOADS_PATH).getAbsolutePath();
String viewsPath = new File(VIEWS_PATH).getAbsolutePath();
h2InMemoryCreator.setSchemaDir(schemaPath).setViewDir(viewsPath).setUnlDir(unloadsPath).setUserName("sa")
.setTablePattern(
"(astat_.*|sos_.*|trans_cifx|cif.*|dim_studiengang|hochschulinfo|semester|konstanten|accredited_ects|sx_repository)")
.setViewPattern("skipeverything");
h2InMemoryCreator.createH2InMemory();
}
private static void createFileTestDb() throws Exception {
H2InMemoryCreator h2InMemoryCreator = new H2InMemoryCreator(H2InMemoryCreator.JDBC_H2_IN_FILE_URL);
String schemaPath = new File(SCHEMA_PATH).getAbsolutePath();
String unloadsPath = new File(UNLOADS_PATH).getAbsolutePath();
String viewsPath = new File(VIEWS_PATH).getAbsolutePath();
h2InMemoryCreator.setSchemaDir(schemaPath).setViewDir(viewsPath).setUnlDir(unloadsPath).setUserName("sa")
.setTablePattern(
"(astat_.*|sos_.*|trans_cifx|cif.*|dim_studiengang|hochschulinfo|semester|konstanten|accredited_ects|sx_repository)")
.setViewPattern("skipeverything");
h2InMemoryCreator.createH2InMemory();
}
private static void initKettleEnvironment() throws KettleException, MetaStoreException {
System.setProperty("BI_KETTLE_PLUGIN_BASE_FOLDERS", KETTLE_PLUGIN_DIR);
KettleEnvironment.init();
DataSourceProviderInterface providerinterface = new KettleH2TestDataSourceProvider("default", null);
DataSourceProviderFactory.setDataSourceProviderInterface(providerinterface);
// Server.startWebServer(connection);
MemoryMetaStore metastore = new MemoryMetaStore();
DatabaseMeta dbmeta = new DatabaseMeta("eduetl", "POSTGRESQL", "JNDI", null, "eduetl", "1521", null, null);
DatabaseMetaStoreUtil.createDatabaseElement(metastore, dbmeta);
datasource = providerinterface.getNamedDataSource("eduetl");
}
protected static SqlRowSet executeQuery(String query) throws Exception {
JdbcTemplate jt = new JdbcTemplate(datasource);
return jt.queryForRowSet(query);
}
@AfterClass
public static void tearDown() throws Exception {
KettleEnvironment.shutdown();
}
}