blob: 359b8ca6dee657665d88a4978d1d2f2213cf4a77 [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
14import de.ids_mannheim.korap.plkexport.JsonExporter;
15
16public class RtfExportTest {
Akron820dc642020-11-19 13:11:50 +010017
Akron64184672020-11-16 10:22:31 +010018 @Test
19 public void testInit () throws IOException {
Akron876017d2020-11-17 09:19:24 +010020 RtfExporter rtf = new RtfExporter();
21 rtf.init("{\"query\":\"cool\"}");
Akron64184672020-11-16 10:22:31 +010022
Akron876017d2020-11-17 09:19:24 +010023 Response resp = rtf.serve().build();
Akron64184672020-11-16 10:22:31 +010024 String x = (String) resp.getEntity();
25 resp.close();
Akronea77cb42020-11-18 14:04:21 +010026 assertTrue(x.contains("\\footer\\pard\\qr\\fs18\\f0 @ Institut"));
Akron64184672020-11-16 10:22:31 +010027 assertTrue(x.contains("Institut f\\u252\\'fcr Deutsche"));
28 };
29
30 @Test
31 public void testInitFull () throws IOException {
Akron876017d2020-11-17 09:19:24 +010032 RtfExporter rtf = new RtfExporter();
33 rtf.init("{\"meta\":\"ja\",\"collection\":\"hm\",\"query\":\"cool\"," +
Akronea77cb42020-11-18 14:04:21 +010034 "\"matches\":["+
35 "{\"author\":\"Goethe\","+
36 "\"title\":\"Title1\","+
37 "\"pubDate\":\"20051103\","+
38 "\"textSigle\":\"RTF/G59/34284\","+
39 "\"snippet\":\"Simple <mark>match1</mark> Snippet\"}"+
40 ","+
41 "{\"author\":\"Schiller\","+
42 "\"title\":\"Title2\","+
43 "\"pubDate\":\"20051104\","+
44 "\"textSigle\":\"RTF/G59/34285\","+
45 "\"snippet\":\"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>"+
46 "Simpler </span><span class=\\\"match\\\"><mark>&quot;match2&quot;</mark></span>"+
47 "<span class=\\\"context-right\\\"> Snippet"+
48 "<span class=\\\"more\\\"></span></span>\"}"+
49 "]}");
Akron64184672020-11-16 10:22:31 +010050
Akron876017d2020-11-17 09:19:24 +010051 Response resp = rtf.serve().build();
Akron64184672020-11-16 10:22:31 +010052 String x = (String) resp.getEntity();
53 resp.close();
54 assertTrue(x.contains("{\\b match1}"));
Akronc408ccb2020-11-16 18:22:12 +010055 assertTrue(x.contains("{\\b \"match2\"}"));
Akron64184672020-11-16 10:22:31 +010056 assertTrue(x.contains("{\\b Title1"));
57 assertTrue(x.contains("{\\b Title2"));
Akron1c8a7682020-11-16 19:06:02 +010058
59 assertTrue(x.contains("\\qj Simple "));
60 assertTrue(x.contains("\\qj [...] Simpler "));
61 assertTrue(x.contains("Snippet\\par}"));
62 assertTrue(x.contains("Snippet [...]\\par}"));
Akron64184672020-11-16 10:22:31 +010063 };
Akron876017d2020-11-17 09:19:24 +010064
65 @Test
Akron9e3229f2020-11-18 14:41:50 +010066 public void testSnippets () throws IOException {
67 RtfExporter rtf = new RtfExporter();
68 rtf.init("{\"matches\":["+
69 "{\"author\":\"Goethe\","+
70 "\"title\":\"Title1\","+
71 "\"pubDate\":\"20051103\","+
72 "\"textSigle\":\"RTF/G59/34284\","+
73 "\"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>\"}"+
74 "]}");
75
76 Response resp = rtf.serve().build();
77 String x = (String) resp.getEntity();
78 resp.close();
79 assertTrue(x.contains("\\qj {\\b Und daf\\u252\\'fcr"));
80 assertTrue(x.contains("dass [!]} meine"));
81 assertTrue(x.contains("[...]\\par}"));
82 };
83
84 @Test
Akron876017d2020-11-17 09:19:24 +010085 public void testAttributes () throws IOException {
86 RtfExporter rtf = new RtfExporter();
Akron74122712020-11-17 09:41:21 +010087 rtf.setFileName("Beispiel");
88 assertEquals(rtf.getFileName(),"Beispiel");
Akron876017d2020-11-17 09:19:24 +010089 assertEquals(rtf.getMimeType(),"application/rtf");
90 assertEquals(rtf.getSuffix(),"rtf");
91 };
Akron64184672020-11-16 10:22:31 +010092};