| Akron | a84260b | 2020-11-20 14:29:38 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.plkexport; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | import static org.junit.Assert.assertEquals; |
| 5 | import static org.junit.Assert.assertTrue; |
| 6 | import static org.junit.Assert.assertFalse; |
| Akron | a84260b | 2020-11-20 14:29:38 +0100 | [diff] [blame] | 7 | import org.glassfish.jersey.server.ResourceConfig; |
| 8 | import org.glassfish.jersey.test.JerseyTest; |
| 9 | |
| 10 | import java.util.Properties; |
| 11 | |
| Marc Kupietz | a2a1797 | 2022-03-27 12:03:48 +0200 | [diff] [blame^] | 12 | import jakarta.ws.rs.client.Entity; |
| 13 | import jakarta.ws.rs.core.Application; |
| 14 | import jakarta.ws.rs.core.HttpHeaders; |
| 15 | import jakarta.ws.rs.core.MediaType; |
| 16 | import jakarta.ws.rs.core.MultivaluedHashMap; |
| 17 | import jakarta.ws.rs.core.Response; |
| 18 | import jakarta.ws.rs.core.Response.Status; |
| Akron | a84260b | 2020-11-20 14:29:38 +0100 | [diff] [blame] | 19 | |
| 20 | public class AssetTest extends JerseyTest { |
| 21 | |
| 22 | @Override |
| 23 | protected Application configure () { |
| Akron | 3436079 | 2020-11-20 15:06:00 +0100 | [diff] [blame] | 24 | return new ResourceConfig(Service.class); |
| Akron | a84260b | 2020-11-20 14:29:38 +0100 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | @Test |
| 28 | public void testFormHtml () { |
| 29 | Response responsehtml = target("/export").request() |
| 30 | .get(); |
| 31 | assertEquals("HTTP Code", |
| 32 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 33 | String str = responsehtml.readEntity(String.class); |
| 34 | assertTrue("HTTP Body", str.contains("<title>Export</title>")); |
| 35 | assertTrue("Assets", str.contains("<script src=\"https://korap.ids-mannheim.de/js")); |
| 36 | assertTrue("Assets", str.contains("<link href=\"https://korap.ids-mannheim.de/css")); |
| 37 | assertFalse("Errors", str.contains("dynCall(")); |
| 38 | } |
| 39 | |
| 40 | @Test |
| Akron | a578eb0 | 2020-11-26 12:34:17 +0100 | [diff] [blame] | 41 | public void testFormHtmlLocalization () { |
| 42 | |
| 43 | // Check german |
| 44 | Response responsehtml = target("/export").request() |
| 45 | .header("Accept-Language","fr-CH, fr;q=0.9, de;q=0.8, en;q=0.7, *;q=0.5").get(); |
| 46 | assertEquals("HTTP Code", |
| 47 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 48 | String str = responsehtml.readEntity(String.class); |
| 49 | assertTrue("HTTP Body (de)", str.contains("Dateiformat")); |
| 50 | |
| 51 | // Check English |
| 52 | responsehtml = target("/export").request() |
| 53 | .header("Accept-Language","fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5").get(); |
| 54 | assertEquals("HTTP Code", |
| 55 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 56 | str = responsehtml.readEntity(String.class); |
| 57 | assertTrue("HTTP Body (en)", str.contains("File format")); |
| 58 | |
| 59 | // Check German (2) |
| 60 | responsehtml = target("/export").request() |
| 61 | .header("Accept-Language","de-DE, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5").get(); |
| 62 | assertEquals("HTTP Code", |
| 63 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 64 | str = responsehtml.readEntity(String.class); |
| 65 | assertTrue("HTTP Body (de)", str.contains("Dateiformat")); |
| 66 | }; |
| 67 | |
| Akron | a77f2f0 | 2020-11-26 16:37:48 +0100 | [diff] [blame] | 68 | @Test |
| Akron | fba8197 | 2020-11-26 19:53:01 +0100 | [diff] [blame] | 69 | public void testFormJsLocalization () { |
| 70 | |
| 71 | // Check german |
| 72 | Response responsehtml = target("/export").request() |
| 73 | .header("Accept-Language","fr-CH, fr;q=0.9, de;q=0.8, en;q=0.7, *;q=0.5").get(); |
| 74 | assertEquals("HTTP Code", |
| 75 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 76 | String str = responsehtml.readEntity(String.class); |
| 77 | |
| 78 | assertTrue("HTTP Body (de1)", str.contains("data-withql=\"mit\"")); |
| 79 | assertTrue("HTTP Body (de2)", str.contains("data-incq=\"in\"")); |
| 80 | |
| 81 | // Check English |
| 82 | responsehtml = target("/export").request() |
| 83 | .header("Accept-Language","fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5").get(); |
| 84 | assertEquals("HTTP Code", |
| 85 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 86 | str = responsehtml.readEntity(String.class); |
| 87 | |
| 88 | assertTrue("HTTP Body (en1)", str.contains("data-withql=\"with\"")); |
| 89 | assertTrue("HTTP Body (en2)", str.contains("data-incq=\"in\"")); |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | @Test |
| Akron | a77f2f0 | 2020-11-26 16:37:48 +0100 | [diff] [blame] | 94 | public void testFormHtmlMaxHitc () { |
| 95 | |
| 96 | // Check german |
| 97 | Response responsehtml = target("/export").request() |
| 98 | .header("Accept-Language","fr-CH, fr;q=0.9, de;q=0.8, en;q=0.7, *;q=0.5").get(); |
| 99 | assertEquals("HTTP Code", |
| 100 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 101 | String str = responsehtml.readEntity(String.class); |
| 102 | assertTrue("HTTP Body (de)", str.contains("value=\"100\"")); |
| 103 | assertTrue("HTTP Body (de)", str.contains("Maximal zu exportierende Treffer: <tt>10.000</tt>")); |
| 104 | |
| 105 | |
| 106 | // Check English |
| 107 | responsehtml = target("/export").request() |
| 108 | .header("Accept-Language","fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5").get(); |
| 109 | assertEquals("HTTP Code", |
| 110 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 111 | str = responsehtml.readEntity(String.class); |
| Marc Kupietz | 8852588 | 2022-03-26 22:28:36 +0100 | [diff] [blame] | 112 | assertTrue("HTTP Body (en)", str.contains("Maximum number of exportable matches: <tt>10,000</tt>")); |
| Akron | a77f2f0 | 2020-11-26 16:37:48 +0100 | [diff] [blame] | 113 | |
| 114 | }; |
| 115 | |
| 116 | |
| Akron | a578eb0 | 2020-11-26 12:34:17 +0100 | [diff] [blame] | 117 | |
| 118 | @Test |
| Akron | a84260b | 2020-11-20 14:29:38 +0100 | [diff] [blame] | 119 | public void testFormHtmlAssets () { |
| 120 | Properties properties = ExWSConf.properties(null); |
| 121 | String hostTemp = properties.getProperty("asset.host"); |
| 122 | String pathTemp = properties.getProperty("asset.path"); |
| 123 | properties.setProperty("asset.host", "ids-mannheim.example"); |
| 124 | properties.setProperty("asset.path", "/instance/test"); |
| 125 | |
| 126 | Response responsehtml = target("/export").request() |
| 127 | .get(); |
| 128 | assertEquals("HTTP Code", |
| 129 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 130 | String str = responsehtml.readEntity(String.class); |
| 131 | assertTrue("HTTP Body", str.contains("<title>Export</title>")); |
| 132 | assertTrue("Assets", str.contains("<script src=\"https://ids-mannheim.example/instance/test/js")); |
| 133 | assertTrue("Assets", str.contains("<link href=\"https://ids-mannheim.example/instance/test/css")); |
| 134 | assertFalse("Errors", str.contains("dynCall(")); |
| 135 | |
| 136 | properties.setProperty("asset.host", hostTemp); |
| 137 | properties.setProperty("asset.path", pathTemp != null ? pathTemp : ""); |
| 138 | } |
| 139 | |
| 140 | @Test |
| 141 | public void testFormHtmlExporters () { |
| 142 | Response responsehtml = target("/export").request() |
| 143 | .get(); |
| 144 | assertEquals("HTTP Code", |
| 145 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 146 | String str = responsehtml.readEntity(String.class); |
| 147 | assertTrue("HTTP Body", str.contains("<title>Export</title>")); |
| 148 | assertTrue("RTF", str.contains("id=\"formatrtf\"")); |
| 149 | assertTrue("RTF-Label", str.contains("for=\"formatrtf\"")); |
| 150 | assertTrue("JSON", str.contains("id=\"formatjson\"")); |
| 151 | assertTrue("JSON-Label", str.contains("for=\"formatjson\"")); |
| 152 | assertTrue("CSV", str.contains("id=\"formatcsv\"")); |
| 153 | assertTrue("CSV-Label", str.contains("for=\"formatcsv\"")); |
| 154 | assertFalse("DOC", str.contains("id=\"formatdoc\"")); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | @Test |
| 159 | public void testJS () { |
| 160 | Response responsejs = target("/export.js").request() |
| 161 | .get(); |
| 162 | assertEquals("HTTP Code", |
| 163 | Status.OK.getStatusCode(), responsejs.getStatus()); |
| 164 | String str = responsejs.readEntity(String.class); |
| 165 | |
| 166 | assertTrue("HTTP Body", str.contains("pluginit")); |
| 167 | } |
| 168 | }; |