Mercurial > dive4elements > river
diff gwt-client/src/test/java/test/ModuleRunnerOutput.java @ 9570:531a60b7af95
failed tests will be saved to disk
author | gernotbelger |
---|---|
date | Mon, 05 Nov 2018 17:15:30 +0100 |
parents | 86e522bc7f36 |
children |
line wrap: on
line diff
--- a/gwt-client/src/test/java/test/ModuleRunnerOutput.java Mon Nov 05 13:51:47 2018 +0100 +++ b/gwt-client/src/test/java/test/ModuleRunnerOutput.java Mon Nov 05 17:15:30 2018 +0100 @@ -9,15 +9,11 @@ */ package test; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.net.URL; -import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; @@ -42,8 +38,6 @@ private static final String LINE_SEPARATOR = System.getProperty("line.separator"); - private static final String EXPORT_FILE_DIR = "D:" + File.separator; - final FilenameSupplier filename; final String outputModeName; @@ -62,7 +56,7 @@ this.params = getChartExportAttributeMap(currentKm, outputModeName); } - protected final void assertAndWriteToFile(final HttpClient client, final String collectionId) throws IOException { + protected final void assertAndWriteToFile(final HttpClient client, final String collectionId, final File testFolder) throws IOException { final String type = "csv"; @@ -79,39 +73,23 @@ final String expected = deleteErstelldatum(FileUtils.readFileToString(new File(expectedResource.getFile()), enc)); - // if (!actual.equals(expected)) { - // if (this.writeToFile != null && this.writeToFile == true) { - doGetWriteToDisk(actual); // TODO: WENN der Test negativ ausfällt, Datei abspeichern -> Diskussion - // } + final File fileTmp = doGetWriteToDisk(actual, testFolder); + Assert.assertEquals(expected, actual); - try { - Assert.assertEquals(expected, actual); - } - catch (final AssertionError e) { - // TODO write (both?) files + fileTmp.delete(); // if assert fails, file won't be deleted - // doGetWriteToDisk(actual); // TODO: WENN der Test negativ ausfällt, Datei abspeichern -> Diskussion - throw e; - } } - public final void doGetWriteToDisk(final String actual_text) throws FileNotFoundException, IOException { + public final File doGetWriteToDisk(final String actual_text, final File testFolder) throws FileNotFoundException, IOException { + + final File file = new File(testFolder, this.filename.getFilename()); + new File(file.getParent()).mkdir(); // final String name = mode; - final String type = "csv"; - - final String fn = this.outputModeName + System.currentTimeMillis() + "." + type; - final String enc = "windows-1252"; + // final String type = "csv"; - final String filepath = EXPORT_FILE_DIR + fn; - // BOM - final byte[] BOM = new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF }; - final String bomChar = new String(BOM, "UTF-8"); - final String actualWithBom = new StringBuilder().append(BOM).append(actual_text).toString(); - - final InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(Charset.forName(enc).encode(actualWithBom).array()), enc); - - IOUtils.copy(in, new FileOutputStream(filepath), enc); + FileUtils.write(file, actual_text, "UTF-8"); + return file; } private final String deleteErstelldatum(final String input) {