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.
117 lines
5.7 KiB
117 lines
5.7 KiB
package de.superx.kettle.statistics; |
|
|
|
import java.io.File; |
|
import java.io.IOException; |
|
import java.util.ArrayList; |
|
import java.util.HashMap; |
|
import java.util.List; |
|
import java.util.Map; |
|
|
|
import org.junit.Test; |
|
import org.pentaho.di.core.logging.LogLevel; |
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
import org.springframework.jdbc.support.rowset.SqlRowSet; |
|
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData; |
|
|
|
import de.superx.BaseDbTest; |
|
import de.superx.KettleTestRunner; |
|
import de.superx.stat.StatisticsBase; |
|
|
|
public class ExaminationEctsAndRszTest extends BaseDbTest { |
|
|
|
private static final String jobFile = String.join(File.separator, "superx","WEB-INF","conf","edustore","db","module","astat","etl","statistik2016","estatistik.kjb"); |
|
private static final String statSelect = "select * from " + StatisticsBase.MODULE_PREFIX + "astat"; |
|
|
|
private static Map<String, String> parameters = createParameterMap(); |
|
private SqlRowSet originalContentStgLab; |
|
private Integer rsz, tid1, tid2, bioTid, matheTid; |
|
|
|
@Test |
|
public void testEctsRsz() throws IOException { |
|
loadFixture(); |
|
KettleTestRunner.runKettleJob(jobFile, parameters, LogLevel.ERROR); |
|
Map<String,Object> expectedResult = new HashMap<>(); |
|
expectedResult.put("ef132", "250"); |
|
expectedResult.put("ef149", "07"); |
|
expectedResult.put("ef150", "026"); |
|
expectedResult.put("ef151", "105"); |
|
expectedResult.put("ef153", null); |
|
expectedResult.put("ef155", "07"); |
|
expectedResult.put("ef156", "2020"); |
|
expectedResult.put("ef187", null); |
|
expectedResult.put("ef188", null); |
|
expectedResult.put("ef189", null); |
|
expectedResult.put("ef190", null); |
|
validateSingleRow(statSelect, expectedResult); |
|
unloadFixture(); |
|
} |
|
|
|
private void loadFixture() throws IOException { |
|
JdbcTemplate jt = new JdbcTemplate(dataSource); |
|
originalContentStgLab = jt.queryForRowSet("select * from sos_lab_stg where matrikel_nr=11202664 and abschnitt=2 and stichtag=4"); |
|
jt.execute("delete from sos_lab_stg where matrikel_nr=11202664 and abschnitt=2 and stichtag=4"); |
|
loadCsvFileIntoTable(String.join(File.separator, "test","resources","db","fixtures","ects_and_rsz_aggregation","11202664_sos_lab_stg.txt"), "sos_lab_stg"); |
|
updateStgTid(); |
|
} |
|
|
|
private void unloadFixture() { |
|
JdbcTemplate jt = new JdbcTemplate(dataSource); |
|
SqlRowSetMetaData meta = originalContentStgLab.getMetaData(); |
|
String[] columns = meta.getColumnNames(); |
|
String columnList = String.join(",", columns); |
|
while (originalContentStgLab.next()) { |
|
List<Object> row = new ArrayList<>(); |
|
for (String column : columns) { |
|
row.add(originalContentStgLab.getObject(column)); |
|
} |
|
StringBuffer places = new StringBuffer("("); |
|
for (int i = 0; i < columns.length; i++) { |
|
if (i < columns.length - 1) { |
|
places.append("?,"); |
|
} else { |
|
places.append("?"); |
|
} |
|
} |
|
places.append(")"); |
|
String insert = "insert into sos_lab_stg ( " + columnList + " ) values " + places; |
|
jt.update(insert, row.toArray()); |
|
} |
|
undoUpdateStgTid(); |
|
} |
|
|
|
private void updateStgTid() { |
|
JdbcTemplate jt = new JdbcTemplate(dataSource); |
|
bioTid = jt.queryForObject("select tid from dim_studiengang where stg='026' and pversion=6 and abschluss='35' and kz_fach='H'" |
|
, Integer.class); |
|
matheTid = jt.queryForObject("select tid from dim_studiengang where stg='105' and pversion=6 and abschluss='35' and kz_fach='H'" |
|
, Integer.class); |
|
tid1 = jt.queryForObject("select tid_stg from sos_lab_stg where matrikel_nr=11202664 and stichtag=4 and abschnitt=2 and ch30_fach='026' and kz_fach='H'", Integer.class); |
|
tid1 = jt.queryForObject("select tid_stg from sos_lab_stg where matrikel_nr=11202664 and stichtag=4 and abschnitt=2 and ch30_fach='105' and kz_fach='H'", Integer.class); |
|
jt.update("update sos_lab_stg set tid_stg=? where matrikel_nr=11202664 and stichtag=4 and abschnitt=2 and ch30_fach=? and kz_fach=?", |
|
bioTid, "026", "H"); |
|
jt.update("update sos_lab_stg set tid_stg=? where matrikel_nr=11202664 and stichtag=4 and abschnitt=2 and ch30_fach=? and kz_fach=?", |
|
matheTid, "105", "H"); |
|
rsz = jt.queryForObject("select regel from dim_studiengang where tid=?", Integer.class, matheTid); |
|
jt.update("update dim_studiengang set regel=7 where tid=?", matheTid); |
|
} |
|
|
|
private void undoUpdateStgTid() { |
|
JdbcTemplate jt = new JdbcTemplate(dataSource); |
|
jt.update("update sos_lab_stg set tid_stg=? where matrikel_nr=11202664 and stichtag=4 and abschnitt=2 and ch30_fach='026' and kz_fach='H'", tid1); |
|
jt.update("update sos_lab_stg set tid_stg=? where matrikel_nr=11202664 and stichtag=4 and abschnitt=2 and ch30_fach='105' and kz_fach='H'", tid2); |
|
jt.update("update dim_studiengang set regel=? where tid=?", rsz, matheTid); |
|
} |
|
|
|
private static Map<String,String> createParameterMap() { |
|
Map<String,String> parameterMap = new HashMap<String,String>(); |
|
parameterMap.put("lieferung", "2"); |
|
parameterMap.put("berichtssemester", "20211"); |
|
parameterMap.put("stichtagsart_pruef_vorsem", "4"); |
|
parameterMap.put("stichtagsart_pruef_berichtssem", "4"); |
|
parameterMap.put("stichtagsart_stud_vorsem", "1"); |
|
parameterMap.put("stichtagsart_stud_berichtssem", "1"); |
|
parameterMap.put("matrikelnr", "11202664"); |
|
return parameterMap; |
|
} |
|
|
|
}
|
|
|