blob: e4c5f46310c176f7b4fa3806988efe77fc6114a4 [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;
Akron32e5aba2021-03-24 15:08:54 +010010
11import java.util.Properties;
12
Akron64184672020-11-16 10:22:31 +010013import org.junit.Test;
14
15import javax.ws.rs.core.Response;
16
Akrona84260b2020-11-20 14:29:38 +010017public class RtfExporterTest {
Akron820dc642020-11-19 13:11:50 +010018
Akron64184672020-11-16 10:22:31 +010019 @Test
20 public void testInit () throws IOException {
Akron876017d2020-11-17 09:19:24 +010021 RtfExporter rtf = new RtfExporter();
22 rtf.init("{\"query\":\"cool\"}");
Akron35881012020-11-24 20:05:06 +010023 rtf.finish();
Akron64184672020-11-16 10:22:31 +010024
Akron876017d2020-11-17 09:19:24 +010025 Response resp = rtf.serve().build();
Akron64184672020-11-16 10:22:31 +010026 String x = (String) resp.getEntity();
27 resp.close();
Akron143acad2020-11-25 17:48:33 +010028
29 assertTrue(x.contains("\\footer\\pard\\qr\\fs18\\f0 @ Leibniz-Institut"));
Akron64184672020-11-16 10:22:31 +010030 assertTrue(x.contains("Institut f\\u252\\'fcr Deutsche"));
31 };
32
33 @Test
34 public void testInitFull () throws IOException {
Akron876017d2020-11-17 09:19:24 +010035 RtfExporter rtf = new RtfExporter();
36 rtf.init("{\"meta\":\"ja\",\"collection\":\"hm\",\"query\":\"cool\"," +
Akronea77cb42020-11-18 14:04:21 +010037 "\"matches\":["+
38 "{\"author\":\"Goethe\","+
39 "\"title\":\"Title1\","+
40 "\"pubDate\":\"20051103\","+
41 "\"textSigle\":\"RTF/G59/34284\","+
42 "\"snippet\":\"Simple <mark>match1</mark> Snippet\"}"+
43 ","+
44 "{\"author\":\"Schiller\","+
45 "\"title\":\"Title2\","+
46 "\"pubDate\":\"20051104\","+
47 "\"textSigle\":\"RTF/G59/34285\","+
48 "\"snippet\":\"<span class=\\\"context-left\\\"><span class=\\\"more\\\"></span>"+
49 "Simpler </span><span class=\\\"match\\\"><mark>&quot;match2&quot;</mark></span>"+
50 "<span class=\\\"context-right\\\"> Snippet"+
51 "<span class=\\\"more\\\"></span></span>\"}"+
52 "]}");
Akron35881012020-11-24 20:05:06 +010053 rtf.finish();
Akron64184672020-11-16 10:22:31 +010054
Akron876017d2020-11-17 09:19:24 +010055 Response resp = rtf.serve().build();
Akron64184672020-11-16 10:22:31 +010056 String x = (String) resp.getEntity();
57 resp.close();
58 assertTrue(x.contains("{\\b match1}"));
Akronc408ccb2020-11-16 18:22:12 +010059 assertTrue(x.contains("{\\b \"match2\"}"));
Akron64184672020-11-16 10:22:31 +010060 assertTrue(x.contains("{\\b Title1"));
61 assertTrue(x.contains("{\\b Title2"));
Akron1c8a7682020-11-16 19:06:02 +010062
63 assertTrue(x.contains("\\qj Simple "));
64 assertTrue(x.contains("\\qj [...] Simpler "));
65 assertTrue(x.contains("Snippet\\par}"));
66 assertTrue(x.contains("Snippet [...]\\par}"));
Akron64184672020-11-16 10:22:31 +010067 };
Akron876017d2020-11-17 09:19:24 +010068
69 @Test
Akron9e3229f2020-11-18 14:41:50 +010070 public void testSnippets () throws IOException {
71 RtfExporter rtf = new RtfExporter();
72 rtf.init("{\"matches\":["+
73 "{\"author\":\"Goethe\","+
74 "\"title\":\"Title1\","+
75 "\"pubDate\":\"20051103\","+
76 "\"textSigle\":\"RTF/G59/34284\","+
77 "\"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>\"}"+
78 "]}");
Akron35881012020-11-24 20:05:06 +010079 rtf.finish();
Akron9e3229f2020-11-18 14:41:50 +010080
81 Response resp = rtf.serve().build();
82 String x = (String) resp.getEntity();
83 resp.close();
84 assertTrue(x.contains("\\qj {\\b Und daf\\u252\\'fcr"));
85 assertTrue(x.contains("dass [!]} meine"));
86 assertTrue(x.contains("[...]\\par}"));
87 };
88
89 @Test
Akron876017d2020-11-17 09:19:24 +010090 public void testAttributes () throws IOException {
91 RtfExporter rtf = new RtfExporter();
Akron74122712020-11-17 09:41:21 +010092 rtf.setFileName("Beispiel");
93 assertEquals(rtf.getFileName(),"Beispiel");
Akron876017d2020-11-17 09:19:24 +010094 assertEquals(rtf.getMimeType(),"application/rtf");
95 assertEquals(rtf.getSuffix(),"rtf");
96 };
Akron32e5aba2021-03-24 15:08:54 +010097
98 @Test
Akroneb9b5072021-04-27 23:52:29 +020099 public void testRtfText () throws IOException {
100 RtfExporter rtf = new RtfExporter();
101 rtf.init("{\"matches\":[{\"author\":\"Goethe\"}]}");
102 rtf.finish();
103
104 Response resp = rtf.serve().build();
105 String x = (String) resp.getEntity();
106 resp.close();
107
108 assertTrue(x.contains("{\\pard\\fs18\\f0"));
109
110 rtf = new RtfExporter();
111 rtf.init("{\"matches\":[{\"author\":\"\"}]}");
112 rtf.finish();
113
114 resp = rtf.serve().build();
115 x = (String) resp.getEntity();
116 resp.close();
117
118 assertTrue(x.contains("{\\pard\\fs18\\f0"));
119
120 rtf = new RtfExporter();
121 rtf.init("{\"versuch\":\"try\"}");
122 rtf.finish();
123
124 resp = rtf.serve().build();
125 x = (String) resp.getEntity();
126 resp.close();
127
128 assertTrue(x.contains("{\\pard\\fs18\\f0"));
129};
130
131 @Test
Akron32e5aba2021-03-24 15:08:54 +0100132 public void testTrail () throws IOException {
133
134 Properties properties = ExWSConf.properties(null);
135 properties.setProperty(
136 "rtf.trail",
137 "Please cite us under http://korap.ids-mannheim.de!"
138 );
139
140 RtfExporter rtf = new RtfExporter();
141 rtf.init("{\"query\":\"cool\"}");
142 rtf.finish();
143
144 Response resp = rtf.serve().build();
145 String x = (String) resp.getEntity();
146 resp.close();
147
148 assertTrue(x.contains("{\\pard\\fs18\\f0 Please cite us"));
149 assertTrue(x.contains("under http://korap.ids-mannheim.de!\\par}"));
150 };
Akron64184672020-11-16 10:22:31 +0100151};