blob: 528c63f02f9a08af9470681051e8e4a74157b1c9 [file] [log] [blame]
Akron69cd35d2020-11-20 13:17:31 +01001package de.ids_mannheim.korap.plkexport;
2
3import java.io.IOException;
4
5import static org.junit.Assert.assertEquals;
6import static org.junit.Assert.assertNull;
7import static org.junit.Assert.assertTrue;
8import static org.junit.Assert.assertFalse;
9import static org.junit.Assert.fail;
10import org.junit.Test;
11
12import javax.ws.rs.core.Response;
13
Akrona84260b2020-11-20 14:29:38 +010014public class CsvExporterTest {
Akron69cd35d2020-11-20 13:17:31 +010015
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>&quot;match2&quot;</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};