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.
183 lines
8.5 KiB
183 lines
8.5 KiB
package de.superx.kettle.statistics; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
import static org.junit.Assert.assertNotNull; |
|
import static org.junit.Assert.assertTrue; |
|
|
|
import java.time.Year; |
|
import java.util.HashMap; |
|
import java.util.Map; |
|
|
|
import org.junit.Before; |
|
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 de.superx.BaseDbTest; |
|
import de.superx.KettleTestRunner; |
|
import de.superx.stat.StatisticsBase; |
|
|
|
public class StudentOfficialStatisticTest extends BaseDbTest { |
|
|
|
private static final String KETTLE_JOB_FILE = "superx/WEB-INF/conf/edustore/db/module/astat/etl/statistik2016/estatistik.kjb"; |
|
private final int year = Year.now().getValue() - 1; |
|
private String STICHTAG_STUD_AKTUELLE; |
|
private String STICHTAG_STUD_AMTLSTAT; |
|
private String STICHTAG_PRUEF_AKTUELLE; |
|
private String STICHTAG_PRUEF_AMTLSTAT; |
|
|
|
|
|
@Before |
|
public void _init() throws Exception { |
|
JdbcTemplate jt = new JdbcTemplate(dataSource); |
|
STICHTAG_STUD_AKTUELLE = jt.queryForObject("SELECT tid FROM sos_stichtag where TRIM(stichtagsart)='Studierende'" |
|
+ " AND TRIM(name)='Aktuelle Zahlen'", String.class); |
|
STICHTAG_STUD_AMTLSTAT = jt.queryForObject("SELECT tid FROM sos_stichtag where TRIM(stichtagsart)='Studierende'" |
|
+ " AND TRIM(name)='Amtl. Statistik Land'", String.class); |
|
STICHTAG_PRUEF_AKTUELLE = jt.queryForObject("SELECT tid FROM sos_stichtag where TRIM(stichtagsart)='Prüfungen'" |
|
+ " AND TRIM(name)='Aktuelle Zahlen'", String.class); |
|
STICHTAG_PRUEF_AMTLSTAT = jt.queryForObject("SELECT tid FROM sos_stichtag where TRIM(stichtagsart)='Prüfungen'" |
|
+ " AND TRIM(name)='Amtl. Statistik Land (Prüf.)'", String.class); |
|
} |
|
|
|
/** |
|
* Test to check if statistics contains a column for berichtseinheitid |
|
* <a href="https://hiszilla.his.de/hiszilla/show_bug.cgi?id=186046">#186046</a> |
|
* |
|
* @author hiber |
|
* |
|
*/ |
|
@Test |
|
public void testBerichtseinheitId() throws Exception { |
|
Map<String,String> parameter = new HashMap<>() { |
|
private static final long serialVersionUID = 1L; |
|
{ |
|
put("lieferung", "1"); |
|
put("berichtssemester", year + "1"); |
|
put("stichtagsart_stud_berichtssem", STICHTAG_STUD_AMTLSTAT); |
|
put("stichtagsart_stud_vorsem", STICHTAG_STUD_AKTUELLE); |
|
put("stichtagsart_pruef_berichtssem", STICHTAG_PRUEF_AMTLSTAT); |
|
put("stichtagsart_pruef_vorsem", STICHTAG_PRUEF_AKTUELLE); |
|
put("finalizePruefStatSql", ""); |
|
put("berichtseinheitid", "4567"); |
|
} |
|
}; |
|
KettleTestRunner.runKettleJob(KETTLE_JOB_FILE, parameter, LogLevel.BASIC); |
|
final String EXPECTED = "4567"; |
|
SqlRowSet rs = executeQuery("SELECT distinct berichtseinheitid FROM " + StatisticsBase.MODULE_PREFIX + "astat;"); |
|
rs.next(); |
|
String berichtseinheitid = rs.getString(1); |
|
assertNotNull("berichtseinheitid not null", berichtseinheitid); |
|
assertTrue("berichtseinheitid has been right padded", berichtseinheitid.endsWith(EXPECTED)); |
|
assertTrue("length berichtseinheitid", berichtseinheitid.length() == 8); |
|
} |
|
|
|
/** |
|
* Test to check if gender '2' is set correctly |
|
* <br> |
|
* <b> Attention: </b> this test uses modified unload data at the moment |
|
* |
|
* @author hiber |
|
* |
|
* @throws Exception |
|
*/ |
|
@Test |
|
public void testGender() throws Exception { |
|
Map<String,String> parameter = new HashMap<>() { |
|
private static final long serialVersionUID = 1L; |
|
{ |
|
put("lieferung", "1"); |
|
put("berichtssemester", year + "1"); |
|
put("stichtagsart_stud_berichtssem", STICHTAG_STUD_AMTLSTAT); |
|
put("stichtagsart_stud_vorsem", STICHTAG_STUD_AKTUELLE); |
|
put("stichtagsart_pruef_berichtssem", STICHTAG_PRUEF_AMTLSTAT); |
|
put("stichtagsart_pruef_vorsem", STICHTAG_PRUEF_AKTUELLE); |
|
put("finalizePruefStatSql", ""); |
|
put("berichtseinheitid", "4567"); |
|
} |
|
}; |
|
KettleTestRunner.runKettleJob(KETTLE_JOB_FILE, parameter, LogLevel.BASIC); |
|
SqlRowSet resultSet = executeQuery("SELECT ef007 FROM " + StatisticsBase.MODULE_PREFIX + "astat WHERE ef006 = '000011200545';"); |
|
resultSet.next(); |
|
int gender = resultSet.getInt("ef007"); |
|
assertEquals("Field ef007 contains correct gender", 2, gender); |
|
} |
|
|
|
/** |
|
* Test to check if the specified finalizeStudStatSql variable will be executed |
|
* @author hiber |
|
* |
|
*/ |
|
@Test |
|
public void testFinalizeStudStatSql() throws Exception { |
|
final String EXPECTED = "4567"; |
|
Map<String,String> parameter = new HashMap<>() { |
|
private static final long serialVersionUID = 1L; |
|
{ |
|
put("lieferung", "1"); |
|
put("berichtssemester", year + "1"); |
|
put("matrikelnr", "11200545"); |
|
put("stichtagsart_stud_berichtssem", STICHTAG_STUD_AMTLSTAT); |
|
put("stichtagsart_stud_vorsem", STICHTAG_STUD_AKTUELLE); |
|
put("stichtagsart_pruef_berichtssem", STICHTAG_PRUEF_AMTLSTAT); |
|
put("stichtagsart_pruef_vorsem", STICHTAG_PRUEF_AKTUELLE); |
|
put("finalizeStudStatSql", "UPDATE " + StatisticsBase.MODULE_PREFIX + "astat SET berichtseinheitid='4567' WHERE ef006='000011200545'"); |
|
put("berichtseinheitid", "4567"); |
|
} |
|
}; |
|
KettleTestRunner.runKettleJob(KETTLE_JOB_FILE, parameter, LogLevel.BASIC); |
|
SqlRowSet rs = executeQuery("SELECT berichtseinheitid FROM " + StatisticsBase.MODULE_PREFIX + "astat WHERE ef006='000011200545';"); |
|
rs.next(); |
|
String berichtseinheitid = rs.getString(1); |
|
assertNotNull("berichtseinheitid not null", berichtseinheitid); |
|
assertEquals("finalizePruefStatSql has been executed", EXPECTED, berichtseinheitid); |
|
} |
|
|
|
/** |
|
* BIA TC15976: Studierenden- und Prüfungsstatistik ab SS 2017: Export Prüfungsstatistik |
|
* Test to checks the content of the generated small examination Statistic |
|
* |
|
* @author hase |
|
* |
|
*/ |
|
@Test |
|
public void testStudentStatistic() throws Exception { |
|
Map<String, String> parameter = new HashMap<>() { |
|
private static final long serialVersionUID = 1L; |
|
{ |
|
put("lieferung", "1"); //ExaminationStatistic |
|
put("berichtssemester", year + "1"); |
|
put("stichtagsart_stud_berichtssem", STICHTAG_STUD_AMTLSTAT); |
|
put("matrikelnr", "11200545"); |
|
put("stichtagsart_stud_vorsem", STICHTAG_STUD_AKTUELLE); |
|
put("stichtagsart_pruef_berichtssem", STICHTAG_PRUEF_AMTLSTAT); |
|
put("stichtagsart_pruef_vorsem", STICHTAG_PRUEF_AKTUELLE); |
|
put("finalizePruefStatSql", ""); |
|
put("berichtseinheitid", "4567"); |
|
} |
|
}; |
|
KettleTestRunner.runKettleJob(KETTLE_JOB_FILE, parameter, LogLevel.ERROR); |
|
Integer YEAR = Integer.valueOf(year); |
|
final String[] EXPECTED = (String.format("99914567;03;1;%s;9991;000001;000011200545;2;16;03;2005;Mart;000" |
|
+ ";;03;241;03;241;1;;;9991;;1;%s;01;00;0;0;00;;;1;;1;1;01;182;03;241;06;021;;;;;;;;;;;;00;;;;00;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" |
|
+ ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%s;03;03;256;;;;;;;;00;00;0;0;0;000;000;000;;;;" |
|
+ ";;;;;;;;;;;00;;;;;;;;;;;;;;;00;00;0;0;0;000;000;000;;;;;;;;;;;;" |
|
+ ";;;00;;;;;;;;;;;;;;" |
|
,YEAR, Integer.valueOf(year), Integer.valueOf(year - 1), YEAR, YEAR)).split(";", -1); |
|
SqlRowSet rs = executeQuery("SELECT * FROM " + StatisticsBase.MODULE_PREFIX + "astat"); |
|
final int colomnCount = rs.getMetaData().getColumnCount(); |
|
assertTrue("Result not empty", rs.next()); |
|
for (int i = 0; i < colomnCount - 1; i++) { |
|
String s = rs.getString(i + 1); |
|
if (s == null) s = ""; |
|
|
|
assertEquals("Field " + (i+1) + " contains correct value ", EXPECTED[i], s); |
|
} |
|
} |
|
|
|
protected SqlRowSet executeQuery(String query) throws Exception { |
|
JdbcTemplate jt = new JdbcTemplate(dataSource); |
|
return jt.queryForRowSet(query); |
|
} |
|
} |