| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.plkexport; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import static org.junit.Assert.assertEquals; |
| 6 | import static org.junit.Assert.assertNull; |
| 7 | import static org.junit.Assert.assertTrue; |
| 8 | import static org.junit.Assert.assertFalse; |
| 9 | import static org.junit.Assert.fail; |
| 10 | import org.junit.Test; |
| 11 | |
| 12 | import javax.ws.rs.core.Response; |
| 13 | |
| 14 | import de.ids_mannheim.korap.plkexport.JsonExporter; |
| 15 | |
| 16 | public class RtfExportTest { |
| Akron | 820dc64 | 2020-11-19 13:11:50 +0100 | [diff] [blame^] | 17 | |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 18 | @Test |
| 19 | public void testInit () throws IOException { |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 20 | RtfExporter rtf = new RtfExporter(); |
| 21 | rtf.init("{\"query\":\"cool\"}"); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 22 | |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 23 | Response resp = rtf.serve().build(); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 24 | String x = (String) resp.getEntity(); |
| 25 | resp.close(); |
| Akron | ea77cb4 | 2020-11-18 14:04:21 +0100 | [diff] [blame] | 26 | assertTrue(x.contains("\\footer\\pard\\qr\\fs18\\f0 @ Institut")); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 27 | assertTrue(x.contains("Institut f\\u252\\'fcr Deutsche")); |
| 28 | }; |
| 29 | |
| 30 | @Test |
| 31 | public void testInitFull () throws IOException { |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 32 | RtfExporter rtf = new RtfExporter(); |
| 33 | rtf.init("{\"meta\":\"ja\",\"collection\":\"hm\",\"query\":\"cool\"," + |
| Akron | ea77cb4 | 2020-11-18 14:04:21 +0100 | [diff] [blame] | 34 | "\"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>"match2"</mark></span>"+ |
| 47 | "<span class=\\\"context-right\\\"> Snippet"+ |
| 48 | "<span class=\\\"more\\\"></span></span>\"}"+ |
| 49 | "]}"); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 50 | |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 51 | Response resp = rtf.serve().build(); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 52 | String x = (String) resp.getEntity(); |
| 53 | resp.close(); |
| 54 | assertTrue(x.contains("{\\b match1}")); |
| Akron | c408ccb | 2020-11-16 18:22:12 +0100 | [diff] [blame] | 55 | assertTrue(x.contains("{\\b \"match2\"}")); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 56 | assertTrue(x.contains("{\\b Title1")); |
| 57 | assertTrue(x.contains("{\\b Title2")); |
| Akron | 1c8a768 | 2020-11-16 19:06:02 +0100 | [diff] [blame] | 58 | |
| 59 | assertTrue(x.contains("\\qj Simple ")); |
| 60 | assertTrue(x.contains("\\qj [...] Simpler ")); |
| 61 | assertTrue(x.contains("Snippet\\par}")); |
| 62 | assertTrue(x.contains("Snippet [...]\\par}")); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 63 | }; |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 64 | |
| 65 | @Test |
| Akron | 9e3229f | 2020-11-18 14:41:50 +0100 | [diff] [blame] | 66 | 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 |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 85 | public void testAttributes () throws IOException { |
| 86 | RtfExporter rtf = new RtfExporter(); |
| Akron | 7412271 | 2020-11-17 09:41:21 +0100 | [diff] [blame] | 87 | rtf.setFileName("Beispiel"); |
| 88 | assertEquals(rtf.getFileName(),"Beispiel"); |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 89 | assertEquals(rtf.getMimeType(),"application/rtf"); |
| 90 | assertEquals(rtf.getSuffix(),"rtf"); |
| 91 | }; |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 92 | }; |