| Akron | 69cd35d | 2020-11-20 13:17:31 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.plkexport; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import static org.junit.Assert.assertEquals; |
| 6 | import static org.junit.Assert.assertNull; |
| 7 | import static org.junit.Assert.assertTrue; |
| 8 | import static org.junit.Assert.assertFalse; |
| 9 | import static org.junit.Assert.fail; |
| 10 | import org.junit.Test; |
| 11 | |
| 12 | import javax.ws.rs.core.Response; |
| 13 | |
| Akron | a84260b | 2020-11-20 14:29:38 +0100 | [diff] [blame^] | 14 | public class CsvExporterTest { |
| Akron | 69cd35d | 2020-11-20 13:17:31 +0100 | [diff] [blame] | 15 | |
| 16 | @Test |
| 17 | public void testInit () throws IOException { |
| 18 | CsvExporter csv = new CsvExporter(); |
| 19 | csv.init("{\"query\":\"cool\"}"); |
| 20 | |
| 21 | Response resp = csv.serve().build(); |
| 22 | String x = (String) resp.getEntity(); |
| 23 | resp.close(); |
| 24 | assertEquals(x, "HasMoreLeft,leftContext,Match,rightContext,HasMoreRight,"+ |
| 25 | "isCutted,textSigle,author,pubDate,title\n"); |
| 26 | }; |
| 27 | |
| 28 | @Test |
| 29 | public void testInitFull () throws IOException { |
| 30 | CsvExporter csv = new CsvExporter(); |
| 31 | csv.init("{\"meta\":\"ja\",\"collection\":\"hm\",\"query\":\"cool\"," + |
| 32 | "\"matches\":["+ |
| 33 | "{\"author\":\"Goethe\","+ |
| 34 | "\"title\":\"Title1\","+ |
| 35 | "\"pubDate\":\"20051103\","+ |
| 36 | "\"textSigle\":\"RTF/G59/34284\","+ |
| 37 | "\"snippet\":\"Simple <mark>match1</mark> Snippet\"}"+ |
| 38 | ","+ |
| 39 | "{\"author\":\"Schiller\","+ |
| 40 | "\"title\":\"Title2, the\","+ |
| 41 | "\"pubDate\":\"20051104\","+ |
| 42 | "\"textSigle\":\"RTF/G59/34285\","+ |
| 43 | "\"snippet\":\"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>"+ |
| 44 | "Simpler, \\\"faster\\\" </span><span class=\\\"match\\\"><mark>"match2"</mark></span>"+ |
| 45 | "<span class=\\\"context-right\\\"> Snippet"+ |
| 46 | "<span class=\\\"more\\\"></span></span>\"}"+ |
| 47 | "]}"); |
| 48 | |
| 49 | Response resp = csv.serve().build(); |
| 50 | String x = (String) resp.getEntity(); |
| 51 | resp.close(); |
| 52 | String[] lines = x.split("\n"); |
| 53 | assertEquals(lines[0],"HasMoreLeft,leftContext,Match,rightContext,HasMoreRight,isCutted,textSigle,author,pubDate,title"); |
| 54 | assertEquals(lines[1],",Simple,match1,Snippet,,,RTF/G59/34284,Goethe,20051103,Title1"); |
| 55 | assertEquals(lines[2],"...,\"Simpler, \"\"faster\"\"\",\"\"\"match2\"\"\",Snippet,...,,RTF/G59/34285,Schiller,20051104,\"Title2, the\""); |
| 56 | assertEquals(lines.length,3); |
| 57 | }; |
| 58 | |
| 59 | @Test |
| 60 | public void testAttributes () throws IOException { |
| 61 | CsvExporter csv = new CsvExporter(); |
| 62 | csv.setFileName("Beispiel"); |
| 63 | assertEquals(csv.getFileName(),"Beispiel"); |
| 64 | assertEquals(csv.getMimeType(),"text/csv"); |
| 65 | assertEquals(csv.getSuffix(),"csv"); |
| 66 | }; |
| 67 | }; |