comparison 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
comparison
equal deleted inserted replaced
9569:9f83ebf67c92 9570:531a60b7af95
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
9 */ 9 */
10 package test; 10 package test;
11 11
12 import java.io.ByteArrayInputStream;
13 import java.io.File; 12 import java.io.File;
14 import java.io.FileNotFoundException; 13 import java.io.FileNotFoundException;
15 import java.io.FileOutputStream;
16 import java.io.IOException; 14 import java.io.IOException;
17 import java.io.InputStream; 15 import java.io.InputStream;
18 import java.io.InputStreamReader;
19 import java.net.URL; 16 import java.net.URL;
20 import java.nio.charset.Charset;
21 import java.util.HashMap; 17 import java.util.HashMap;
22 import java.util.Map; 18 import java.util.Map;
23 19
24 import org.apache.commons.io.FileUtils; 20 import org.apache.commons.io.FileUtils;
25 import org.apache.commons.io.IOUtils; 21 import org.apache.commons.io.IOUtils;
40 private static final String IGNORE_FLYS_VERSION = "# FLYS-Version:"; 36 private static final String IGNORE_FLYS_VERSION = "# FLYS-Version:";
41 private static final String IGNORE_BEARBEITER = "# Bearbeiter:"; 37 private static final String IGNORE_BEARBEITER = "# Bearbeiter:";
42 38
43 private static final String LINE_SEPARATOR = System.getProperty("line.separator"); 39 private static final String LINE_SEPARATOR = System.getProperty("line.separator");
44 40
45 private static final String EXPORT_FILE_DIR = "D:" + File.separator;
46
47 final FilenameSupplier filename; 41 final FilenameSupplier filename;
48 final String outputModeName; 42 final String outputModeName;
49 43
50 // private final String collectionIdentifier; 44 // private final String collectionIdentifier;
51 45
60 this.outputModeName = outputModeName; 54 this.outputModeName = outputModeName;
61 55
62 this.params = getChartExportAttributeMap(currentKm, outputModeName); 56 this.params = getChartExportAttributeMap(currentKm, outputModeName);
63 } 57 }
64 58
65 protected final void assertAndWriteToFile(final HttpClient client, final String collectionId) throws IOException { 59 protected final void assertAndWriteToFile(final HttpClient client, final String collectionId, final File testFolder) throws IOException {
66 60
67 final String type = "csv"; 61 final String type = "csv";
68 62
69 final String enc = "UTF-8";// req.getParameter("encoding"); 63 final String enc = "UTF-8";// req.getParameter("encoding");
70 64
77 71
78 final String actual = deleteErstelldatum(IOUtils.toString(response, "UTF-8")); 72 final String actual = deleteErstelldatum(IOUtils.toString(response, "UTF-8"));
79 73
80 final String expected = deleteErstelldatum(FileUtils.readFileToString(new File(expectedResource.getFile()), enc)); 74 final String expected = deleteErstelldatum(FileUtils.readFileToString(new File(expectedResource.getFile()), enc));
81 75
82 // if (!actual.equals(expected)) { 76 final File fileTmp = doGetWriteToDisk(actual, testFolder);
83 // if (this.writeToFile != null && this.writeToFile == true) { 77 Assert.assertEquals(expected, actual);
84 doGetWriteToDisk(actual); // TODO: WENN der Test negativ ausfällt, Datei abspeichern -> Diskussion
85 // }
86 78
87 try { 79 fileTmp.delete(); // if assert fails, file won't be deleted
88 Assert.assertEquals(expected, actual);
89 }
90 catch (final AssertionError e) {
91 // TODO write (both?) files
92 80
93 // doGetWriteToDisk(actual); // TODO: WENN der Test negativ ausfällt, Datei abspeichern -> Diskussion
94 throw e;
95 }
96 } 81 }
97 82
98 public final void doGetWriteToDisk(final String actual_text) throws FileNotFoundException, IOException { 83 public final File doGetWriteToDisk(final String actual_text, final File testFolder) throws FileNotFoundException, IOException {
84
85 final File file = new File(testFolder, this.filename.getFilename());
86 new File(file.getParent()).mkdir();
99 87
100 // final String name = mode; 88 // final String name = mode;
101 final String type = "csv"; 89 // final String type = "csv";
102 90
103 final String fn = this.outputModeName + System.currentTimeMillis() + "." + type; 91 FileUtils.write(file, actual_text, "UTF-8");
104 final String enc = "windows-1252"; 92 return file;
105
106 final String filepath = EXPORT_FILE_DIR + fn;
107 // BOM
108 final byte[] BOM = new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
109 final String bomChar = new String(BOM, "UTF-8");
110 final String actualWithBom = new StringBuilder().append(BOM).append(actual_text).toString();
111
112 final InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(Charset.forName(enc).encode(actualWithBom).array()), enc);
113
114 IOUtils.copy(in, new FileOutputStream(filepath), enc);
115 } 93 }
116 94
117 private final String deleteErstelldatum(final String input) { 95 private final String deleteErstelldatum(final String input) {
118 String result = ""; 96 String result = "";
119 final String[] lines = input.split(LINE_SEPARATOR); 97 final String[] lines = input.split(LINE_SEPARATOR);

http://dive4elements.wald.intevation.org