| 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; |
| Akron | 32e5aba | 2021-03-24 15:08:54 +0100 | [diff] [blame] | 10 | |
| 11 | import java.util.Properties; |
| 12 | |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 13 | import org.junit.Test; |
| 14 | |
| 15 | import javax.ws.rs.core.Response; |
| 16 | |
| Akron | a84260b | 2020-11-20 14:29:38 +0100 | [diff] [blame] | 17 | public class RtfExporterTest { |
| Akron | 820dc64 | 2020-11-19 13:11:50 +0100 | [diff] [blame] | 18 | |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 19 | @Test |
| 20 | public void testInit () throws IOException { |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 21 | RtfExporter rtf = new RtfExporter(); |
| 22 | rtf.init("{\"query\":\"cool\"}"); |
| Akron | 3588101 | 2020-11-24 20:05:06 +0100 | [diff] [blame] | 23 | rtf.finish(); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 24 | |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 25 | Response resp = rtf.serve().build(); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 26 | String x = (String) resp.getEntity(); |
| 27 | resp.close(); |
| Akron | 143acad | 2020-11-25 17:48:33 +0100 | [diff] [blame] | 28 | |
| 29 | assertTrue(x.contains("\\footer\\pard\\qr\\fs18\\f0 @ Leibniz-Institut")); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 30 | assertTrue(x.contains("Institut f\\u252\\'fcr Deutsche")); |
| 31 | }; |
| 32 | |
| 33 | @Test |
| 34 | public void testInitFull () throws IOException { |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 35 | RtfExporter rtf = new RtfExporter(); |
| 36 | rtf.init("{\"meta\":\"ja\",\"collection\":\"hm\",\"query\":\"cool\"," + |
| Akron | ea77cb4 | 2020-11-18 14:04:21 +0100 | [diff] [blame] | 37 | "\"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>"match2"</mark></span>"+ |
| 50 | "<span class=\\\"context-right\\\"> Snippet"+ |
| 51 | "<span class=\\\"more\\\"></span></span>\"}"+ |
| 52 | "]}"); |
| Akron | 3588101 | 2020-11-24 20:05:06 +0100 | [diff] [blame] | 53 | rtf.finish(); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 54 | |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 55 | Response resp = rtf.serve().build(); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 56 | String x = (String) resp.getEntity(); |
| 57 | resp.close(); |
| 58 | assertTrue(x.contains("{\\b match1}")); |
| Akron | c408ccb | 2020-11-16 18:22:12 +0100 | [diff] [blame] | 59 | assertTrue(x.contains("{\\b \"match2\"}")); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 60 | assertTrue(x.contains("{\\b Title1")); |
| 61 | assertTrue(x.contains("{\\b Title2")); |
| Akron | 1c8a768 | 2020-11-16 19:06:02 +0100 | [diff] [blame] | 62 | |
| 63 | assertTrue(x.contains("\\qj Simple ")); |
| 64 | assertTrue(x.contains("\\qj [...] Simpler ")); |
| 65 | assertTrue(x.contains("Snippet\\par}")); |
| 66 | assertTrue(x.contains("Snippet [...]\\par}")); |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 67 | }; |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 68 | |
| 69 | @Test |
| Akron | 9e3229f | 2020-11-18 14:41:50 +0100 | [diff] [blame] | 70 | 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 | "]}"); |
| Akron | 3588101 | 2020-11-24 20:05:06 +0100 | [diff] [blame] | 79 | rtf.finish(); |
| Akron | 9e3229f | 2020-11-18 14:41:50 +0100 | [diff] [blame] | 80 | |
| 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 |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 90 | public void testAttributes () throws IOException { |
| 91 | RtfExporter rtf = new RtfExporter(); |
| Akron | 7412271 | 2020-11-17 09:41:21 +0100 | [diff] [blame] | 92 | rtf.setFileName("Beispiel"); |
| 93 | assertEquals(rtf.getFileName(),"Beispiel"); |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 94 | assertEquals(rtf.getMimeType(),"application/rtf"); |
| 95 | assertEquals(rtf.getSuffix(),"rtf"); |
| 96 | }; |
| Akron | 32e5aba | 2021-03-24 15:08:54 +0100 | [diff] [blame] | 97 | |
| 98 | @Test |
| Akron | eb9b507 | 2021-04-27 23:52:29 +0200 | [diff] [blame] | 99 | 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 |
| Akron | 32e5aba | 2021-03-24 15:08:54 +0100 | [diff] [blame] | 132 | 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 | }; |
| Akron | 6418467 | 2020-11-16 10:22:31 +0100 | [diff] [blame] | 151 | }; |