blob: 33eb7871765ed6399443e27282b7269cb453c9a2 [file] [log] [blame]
Akron64184672020-11-16 10:22: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
Akron64184672020-11-16 10:22:31 +010014public class RtfExportTest {
Akron820dc642020-11-19 13:11:50 +010015
Akron64184672020-11-16 10:22:31 +010016 @Test
17 public void testInit () throws IOException {
Akron876017d2020-11-17 09:19:24 +010018 RtfExporter rtf = new RtfExporter();
19 rtf.init("{\"query\":\"cool\"}");
Akron64184672020-11-16 10:22:31 +010020
Akron876017d2020-11-17 09:19:24 +010021 Response resp = rtf.serve().build();
Akron64184672020-11-16 10:22:31 +010022 String x = (String) resp.getEntity();
23 resp.close();
Akronea77cb42020-11-18 14:04:21 +010024 assertTrue(x.contains("\\footer\\pard\\qr\\fs18\\f0 @ Institut"));
Akron64184672020-11-16 10:22:31 +010025 assertTrue(x.contains("Institut f\\u252\\'fcr Deutsche"));
26 };
27
28 @Test
29 public void testInitFull () throws IOException {
Akron876017d2020-11-17 09:19:24 +010030 RtfExporter rtf = new RtfExporter();
31 rtf.init("{\"meta\":\"ja\",\"collection\":\"hm\",\"query\":\"cool\"," +
Akronea77cb42020-11-18 14:04:21 +010032 "\"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\","+
41 "\"pubDate\":\"20051104\","+
42 "\"textSigle\":\"RTF/G59/34285\","+
43 "\"snippet\":\"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>"+
44 "Simpler </span><span class=\\\"match\\\"><mark>&quot;match2&quot;</mark></span>"+
45 "<span class=\\\"context-right\\\"> Snippet"+
46 "<span class=\\\"more\\\"></span></span>\"}"+
47 "]}");
Akron64184672020-11-16 10:22:31 +010048
Akron876017d2020-11-17 09:19:24 +010049 Response resp = rtf.serve().build();
Akron64184672020-11-16 10:22:31 +010050 String x = (String) resp.getEntity();
51 resp.close();
52 assertTrue(x.contains("{\\b match1}"));
Akronc408ccb2020-11-16 18:22:12 +010053 assertTrue(x.contains("{\\b \"match2\"}"));
Akron64184672020-11-16 10:22:31 +010054 assertTrue(x.contains("{\\b Title1"));
55 assertTrue(x.contains("{\\b Title2"));
Akron1c8a7682020-11-16 19:06:02 +010056
57 assertTrue(x.contains("\\qj Simple "));
58 assertTrue(x.contains("\\qj [...] Simpler "));
59 assertTrue(x.contains("Snippet\\par}"));
60 assertTrue(x.contains("Snippet [...]\\par}"));
Akron64184672020-11-16 10:22:31 +010061 };
Akron876017d2020-11-17 09:19:24 +010062
63 @Test
Akron9e3229f2020-11-18 14:41:50 +010064 public void testSnippets () throws IOException {
65 RtfExporter rtf = new RtfExporter();
66 rtf.init("{\"matches\":["+
67 "{\"author\":\"Goethe\","+
68 "\"title\":\"Title1\","+
69 "\"pubDate\":\"20051103\","+
70 "\"textSigle\":\"RTF/G59/34284\","+
71 "\"snippet\":\"<span class=\\\"context-left\\\"></span><span class=\\\"match\\\"><mark>Und dafür musstest Du extra ne neue Socke erstellen? Wieso traust Du Dich nicht, mit Deinem Account aufzutreten? - -- ωωσσI - talk with me 09:17, 17. Dez. 2011 (CET) Der ist doch gesperrt. -- 09:21, 17. Dez. 2011 (CET) WWSS1, weil ich normalerweise mit IP schreibe und in dem Fall nicht möchte, dass</mark><span class=\\\"cutted\\\"></span></span><span class=\\\"context-right\\\"> meine IP öffentlich angezeigt wird. Über die IP kann man auf den Wohnort, den Provider und bei Aufenthalt am Arbeitsplatz auf den Arbeitgeber schließen, über Konto nicht. -- 09:24, 17. Dez. 2011 (CET) Bist Du denn nicht mehr selber Arbeitgeber? -- 09:31<span class=\\\"more\\\"></span></span>\"}"+
72 "]}");
73
74 Response resp = rtf.serve().build();
75 String x = (String) resp.getEntity();
76 resp.close();
77 assertTrue(x.contains("\\qj {\\b Und daf\\u252\\'fcr"));
78 assertTrue(x.contains("dass [!]} meine"));
79 assertTrue(x.contains("[...]\\par}"));
80 };
81
82 @Test
Akron876017d2020-11-17 09:19:24 +010083 public void testAttributes () throws IOException {
84 RtfExporter rtf = new RtfExporter();
Akron74122712020-11-17 09:41:21 +010085 rtf.setFileName("Beispiel");
86 assertEquals(rtf.getFileName(),"Beispiel");
Akron876017d2020-11-17 09:19:24 +010087 assertEquals(rtf.getMimeType(),"application/rtf");
88 assertEquals(rtf.getSuffix(),"rtf");
89 };
Akron64184672020-11-16 10:22:31 +010090};