blob: 444e34bda4492159056d088122b07632a4726908 [file] [log] [blame]
Akrona84260b2020-11-20 14:29:38 +01001package de.ids_mannheim.korap.plkexport;
2
3import org.junit.Test;
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6import static org.junit.Assert.assertFalse;
7import static org.junit.Assert.fail;
8
9import org.glassfish.jersey.server.ResourceConfig;
10import org.glassfish.jersey.test.JerseyTest;
11
12import java.util.Properties;
13
14import javax.ws.rs.client.Entity;
15import javax.ws.rs.core.Application;
16import javax.ws.rs.core.HttpHeaders;
17import javax.ws.rs.core.MediaType;
18import javax.ws.rs.core.MultivaluedHashMap;
19import javax.ws.rs.core.Response;
20import javax.ws.rs.core.Response.Status;
21
22public class AssetTest extends JerseyTest {
23
24 @Override
25 protected Application configure () {
Akron34360792020-11-20 15:06:00 +010026 return new ResourceConfig(Service.class);
Akrona84260b2020-11-20 14:29:38 +010027 }
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
43 public void testFormHtmlAssets () {
44 Properties properties = ExWSConf.properties(null);
45 String hostTemp = properties.getProperty("asset.host");
46 String pathTemp = properties.getProperty("asset.path");
47 properties.setProperty("asset.host", "ids-mannheim.example");
48 properties.setProperty("asset.path", "/instance/test");
49
50 Response responsehtml = target("/export").request()
51 .get();
52 assertEquals("HTTP Code",
53 Status.OK.getStatusCode(), responsehtml.getStatus());
54 String str = responsehtml.readEntity(String.class);
55 assertTrue("HTTP Body", str.contains("<title>Export</title>"));
56 assertTrue("Assets", str.contains("<script src=\"https://ids-mannheim.example/instance/test/js"));
57 assertTrue("Assets", str.contains("<link href=\"https://ids-mannheim.example/instance/test/css"));
58 assertFalse("Errors", str.contains("dynCall("));
59
60 properties.setProperty("asset.host", hostTemp);
61 properties.setProperty("asset.path", pathTemp != null ? pathTemp : "");
62 }
63
64 @Test
65 public void testFormHtmlExporters () {
66 Response responsehtml = target("/export").request()
67 .get();
68 assertEquals("HTTP Code",
69 Status.OK.getStatusCode(), responsehtml.getStatus());
70 String str = responsehtml.readEntity(String.class);
71 assertTrue("HTTP Body", str.contains("<title>Export</title>"));
72 assertTrue("RTF", str.contains("id=\"formatrtf\""));
73 assertTrue("RTF-Label", str.contains("for=\"formatrtf\""));
74 assertTrue("JSON", str.contains("id=\"formatjson\""));
75 assertTrue("JSON-Label", str.contains("for=\"formatjson\""));
76 assertTrue("CSV", str.contains("id=\"formatcsv\""));
77 assertTrue("CSV-Label", str.contains("for=\"formatcsv\""));
78 assertFalse("DOC", str.contains("id=\"formatdoc\""));
79 }
80
81
82 @Test
83 public void testJS () {
84 Response responsejs = target("/export.js").request()
85 .get();
86 assertEquals("HTTP Code",
87 Status.OK.getStatusCode(), responsejs.getStatus());
88 String str = responsejs.readEntity(String.class);
89
90 assertTrue("HTTP Body", str.contains("pluginit"));
91 }
92};