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.
86 lines
2.8 KiB
86 lines
2.8 KiB
package de.superx.servlet; |
|
|
|
import java.io.File; |
|
import java.io.IOException; |
|
import java.util.Iterator; |
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; |
|
import org.apache.poi.ss.usermodel.Sheet; |
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
import org.junit.Assert; |
|
import org.junit.BeforeClass; |
|
import org.junit.Test; |
|
import org.springframework.test.context.ContextConfiguration; |
|
|
|
import de.superx.BaseDbTest; |
|
import de.superx.TestApplicationConfigPg; |
|
import de.superx.bin.ExecuteMask; |
|
import de.superx.sec.InputCheckRegistry; |
|
|
|
//@ContextConfiguration(classes = { TestApplicationConfigPg.class }) |
|
public class JasperCreatorTest extends BaseDbTest { |
|
|
|
private static String outputFilename; |
|
private static File outputFile; |
|
|
|
private static final String STUDENTS_FACTSHEET_NAME = "Studierende Datenblatt"; |
|
|
|
@BeforeClass |
|
public static void setup() throws IOException |
|
{ |
|
outputFilename=String.join(File.separator, "test", "output_160440.xlsx"); |
|
InputCheckRegistry.registerDefaultChecks(); |
|
if (outputFilename != null) { |
|
outputFile = new File(outputFilename); |
|
if (outputFile.exists()) { |
|
outputFile.delete(); |
|
} |
|
} |
|
} |
|
|
|
@Test |
|
public void testXslxDatenblatt() |
|
throws Exception { |
|
String[] params = buildParams(); |
|
ExecuteMask.setMyWEBINFFilePath(SuperXManager.getWEB_INFPfad()); |
|
ExecuteMask.execute(params); |
|
validateXSLXFile(); |
|
} |
|
|
|
private static String[] buildParams() { |
|
String contenttype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; |
|
String stylesheet = "tabelle_160440_semester_geschlecht.jrxml"; |
|
String[] params = { |
|
"-tid:160440", |
|
"-out:" + outputFilename, |
|
"-user:admin", |
|
"-params:Köpfe oder Fälle ?=KoF_2&Stichtag=1" |
|
+ "&stylesheet=" + stylesheet |
|
+ "&tablestylesheet=" + stylesheet |
|
+ "&contenttype=" + contenttype, |
|
"-logger:" + logConfigPath, |
|
"-mandantenID:" + MANDANTEN_ID }; |
|
return params; |
|
} |
|
|
|
private static void validateXSLXFile() throws IOException, InvalidFormatException { |
|
Assert.assertTrue("'" + outputFilename + " ("+outputFile.getCanonicalPath()+") does not exist", outputFile.exists()); |
|
boolean studendsFactSheetFound = containsStudentsFactSheet(outputFile); |
|
Assert.assertTrue("'" + outputFilename + "' misses sheet '" + STUDENTS_FACTSHEET_NAME + "'", |
|
studendsFactSheetFound); |
|
} |
|
|
|
private static boolean containsStudentsFactSheet(File xslxFile) |
|
throws IOException, InvalidFormatException { |
|
boolean studendsFactSheetFound = false; |
|
try (XSSFWorkbook workbook = new XSSFWorkbook(xslxFile);) { |
|
Iterator<Sheet> shit = workbook.sheetIterator(); |
|
while (shit.hasNext()) { |
|
Sheet sheet = shit.next(); |
|
String sheetName = sheet.getSheetName(); |
|
studendsFactSheetFound |= sheetName.equals(STUDENTS_FACTSHEET_NAME); |
|
} |
|
} |
|
return studendsFactSheetFound; |
|
} |
|
}
|
|
|