| 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; |
| 7 | import static org.junit.Assert.fail; |
| 8 | |
| 9 | import org.glassfish.jersey.server.ResourceConfig; |
| 10 | import org.glassfish.jersey.test.JerseyTest; |
| 11 | |
| 12 | import java.util.Properties; |
| 13 | |
| 14 | import javax.ws.rs.client.Entity; |
| 15 | import javax.ws.rs.core.Application; |
| 16 | import javax.ws.rs.core.HttpHeaders; |
| 17 | import javax.ws.rs.core.MediaType; |
| 18 | import javax.ws.rs.core.MultivaluedHashMap; |
| 19 | import javax.ws.rs.core.Response; |
| 20 | import javax.ws.rs.core.Response.Status; |
| 21 | |
| 22 | public class AssetTest extends JerseyTest { |
| 23 | |
| 24 | @Override |
| 25 | protected Application configure () { |
| Akron | 3436079 | 2020-11-20 15:06:00 +0100 | [diff] [blame] | 26 | return new ResourceConfig(Service.class); |
| Akron | a84260b | 2020-11-20 14:29:38 +0100 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | @Test |
| 30 | public void testFormHtml () { |
| 31 | Response responsehtml = target("/export").request() |
| 32 | .get(); |
| 33 | assertEquals("HTTP Code", |
| 34 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 35 | String str = responsehtml.readEntity(String.class); |
| 36 | assertTrue("HTTP Body", str.contains("<title>Export</title>")); |
| 37 | assertTrue("Assets", str.contains("<script src=\"https://korap.ids-mannheim.de/js")); |
| 38 | assertTrue("Assets", str.contains("<link href=\"https://korap.ids-mannheim.de/css")); |
| 39 | assertFalse("Errors", str.contains("dynCall(")); |
| 40 | } |
| 41 | |
| 42 | @Test |
| Akron | a578eb0 | 2020-11-26 12:34:17 +0100 | [diff] [blame^] | 43 | public void testFormHtmlLocalization () { |
| 44 | |
| 45 | // Check german |
| 46 | Response responsehtml = target("/export").request() |
| 47 | .header("Accept-Language","fr-CH, fr;q=0.9, de;q=0.8, en;q=0.7, *;q=0.5").get(); |
| 48 | assertEquals("HTTP Code", |
| 49 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 50 | String str = responsehtml.readEntity(String.class); |
| 51 | assertTrue("HTTP Body (de)", str.contains("Dateiformat")); |
| 52 | |
| 53 | // Check English |
| 54 | responsehtml = target("/export").request() |
| 55 | .header("Accept-Language","fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5").get(); |
| 56 | assertEquals("HTTP Code", |
| 57 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 58 | str = responsehtml.readEntity(String.class); |
| 59 | assertTrue("HTTP Body (en)", str.contains("File format")); |
| 60 | |
| 61 | // Check German (2) |
| 62 | responsehtml = target("/export").request() |
| 63 | .header("Accept-Language","de-DE, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5").get(); |
| 64 | assertEquals("HTTP Code", |
| 65 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 66 | str = responsehtml.readEntity(String.class); |
| 67 | assertTrue("HTTP Body (de)", str.contains("Dateiformat")); |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | @Test |
| Akron | a84260b | 2020-11-20 14:29:38 +0100 | [diff] [blame] | 72 | public void testFormHtmlAssets () { |
| 73 | Properties properties = ExWSConf.properties(null); |
| 74 | String hostTemp = properties.getProperty("asset.host"); |
| 75 | String pathTemp = properties.getProperty("asset.path"); |
| 76 | properties.setProperty("asset.host", "ids-mannheim.example"); |
| 77 | properties.setProperty("asset.path", "/instance/test"); |
| 78 | |
| 79 | Response responsehtml = target("/export").request() |
| 80 | .get(); |
| 81 | assertEquals("HTTP Code", |
| 82 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 83 | String str = responsehtml.readEntity(String.class); |
| 84 | assertTrue("HTTP Body", str.contains("<title>Export</title>")); |
| 85 | assertTrue("Assets", str.contains("<script src=\"https://ids-mannheim.example/instance/test/js")); |
| 86 | assertTrue("Assets", str.contains("<link href=\"https://ids-mannheim.example/instance/test/css")); |
| 87 | assertFalse("Errors", str.contains("dynCall(")); |
| 88 | |
| 89 | properties.setProperty("asset.host", hostTemp); |
| 90 | properties.setProperty("asset.path", pathTemp != null ? pathTemp : ""); |
| 91 | } |
| 92 | |
| 93 | @Test |
| 94 | public void testFormHtmlExporters () { |
| 95 | Response responsehtml = target("/export").request() |
| 96 | .get(); |
| 97 | assertEquals("HTTP Code", |
| 98 | Status.OK.getStatusCode(), responsehtml.getStatus()); |
| 99 | String str = responsehtml.readEntity(String.class); |
| 100 | assertTrue("HTTP Body", str.contains("<title>Export</title>")); |
| 101 | assertTrue("RTF", str.contains("id=\"formatrtf\"")); |
| 102 | assertTrue("RTF-Label", str.contains("for=\"formatrtf\"")); |
| 103 | assertTrue("JSON", str.contains("id=\"formatjson\"")); |
| 104 | assertTrue("JSON-Label", str.contains("for=\"formatjson\"")); |
| 105 | assertTrue("CSV", str.contains("id=\"formatcsv\"")); |
| 106 | assertTrue("CSV-Label", str.contains("for=\"formatcsv\"")); |
| 107 | assertFalse("DOC", str.contains("id=\"formatdoc\"")); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | @Test |
| 112 | public void testJS () { |
| 113 | Response responsejs = target("/export.js").request() |
| 114 | .get(); |
| 115 | assertEquals("HTTP Code", |
| 116 | Status.OK.getStatusCode(), responsejs.getStatus()); |
| 117 | String str = responsejs.readEntity(String.class); |
| 118 | |
| 119 | assertTrue("HTTP Body", str.contains("pluginit")); |
| 120 | } |
| 121 | }; |