blob: e979cc134ef325311fe523b383c6b0178190a0e0 [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 {
17
18 @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
66 public void testAttributes () throws IOException {
67 RtfExporter rtf = new RtfExporter();
Akron74122712020-11-17 09:41:21 +010068 rtf.setFileName("Beispiel");
69 assertEquals(rtf.getFileName(),"Beispiel");
Akron876017d2020-11-17 09:19:24 +010070 assertEquals(rtf.getMimeType(),"application/rtf");
71 assertEquals(rtf.getSuffix(),"rtf");
72 };
Akron64184672020-11-16 10:22:31 +010073};