aboutsummaryrefslogtreecommitdiffstats
path: root/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java
diff options
context:
space:
mode:
authorSaad Mohammad <[email protected]>2012-11-13 10:55:19 -0500
committerSaad Mohammad <[email protected]>2012-11-13 10:55:19 -0500
commit07debbc4fcc25b31d0231230ff2093926580129e (patch)
treeb593c2d38dc655c9c6f6887df75c4f41c0103d2e /tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java
parenta44e019b4f1d36262bc8177ed5f89620fe948bb6 (diff)
Unit tests for PR1166
Diffstat (limited to 'tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java')
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java185
1 files changed, 184 insertions, 1 deletions
diff --git a/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java b/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java
index c006fef..e9069f2 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java
@@ -27,10 +27,14 @@ import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.List;
+import junit.framework.Assert;
import net.sourceforge.jnlp.cache.UpdatePolicy;
+import net.sourceforge.jnlp.util.replacements.BASE64Encoder;
import org.junit.Test;
@@ -96,4 +100,183 @@ public class PluginBridgeTest {
mockCreator.getJNLPHref().toExternalForm());
}
-} \ No newline at end of file
+ @Test
+ public void testBase64StringDecoding() throws Exception {
+ String actualFile = "This is a sample string that will be encoded to" +
+ "a Base64 string and then decoded using PluginBridge's" +
+ "decoding method and compared.";
+
+ BASE64Encoder encoder = new BASE64Encoder();
+ String encodedFile = encoder.encodeBuffer(actualFile.getBytes());
+
+ byte[] decodedBytes = PluginBridge.decodeBase64String(encodedFile);
+ String decodedString = new String(decodedBytes);
+ Assert.assertEquals(actualFile, decodedString);
+ }
+
+ @Test
+ public void testEmbeddedJnlpWithValidCodebase() throws Exception {
+ URL codeBase = new URL("http://icedtea.classpath.org");
+ String relativeLocation = "/EmbeddedJnlpFile.jnlp";
+
+ //Codebase within jnlp file is VALID
+ /**
+ <?xml version="1.0"?>
+ <jnlp spec="1.5+"
+ href="EmbeddedJnlpFile.jnlp"
+ codebase="http://www.redhat.com"
+ >
+
+ <information>
+ <title>Sample Test</title>
+ <vendor>RedHat</vendor>
+ <offline-allowed/>
+ </information>
+
+ <resources>
+ <j2se version='1.6+' />
+ <jar href='EmbeddedJnlpJarOne.jar' main='true' />
+ <jar href='EmbeddedJnlpJarTwo.jar' main='true' />
+ </resources>
+
+ <applet-desc
+ documentBase="."
+ name="redhat.embeddedjnlp"
+ main-class="redhat.embeddedjnlp"
+ width="0"
+ height="0"
+ />
+ </jnlp>
+ **/
+
+ String jnlpFileEncoded = "ICAgICAgICA8P3htbCB2ZXJzaW9uPSIxLjAiPz4NCiAgICAgICAgICAgIDxqbmxwIHNwZWM9IjEu" +
+ "NSsiIA0KICAgICAgICAgICAgICBocmVmPSJFbWJlZGRlZEpubHBGaWxlLmpubHAiIA0KICAgICAg" +
+ "ICAgICAgICBjb2RlYmFzZT0iaHR0cDovL3d3dy5yZWRoYXQuY29tIiAgICANCiAgICAgICAgICAg" +
+ "ID4NCg0KICAgICAgICAgICAgPGluZm9ybWF0aW9uPg0KICAgICAgICAgICAgICAgIDx0aXRsZT5T" +
+ "YW1wbGUgVGVzdDwvdGl0bGU+DQogICAgICAgICAgICAgICAgPHZlbmRvcj5SZWRIYXQ8L3ZlbmRv" +
+ "cj4NCiAgICAgICAgICAgICAgICA8b2ZmbGluZS1hbGxvd2VkLz4NCiAgICAgICAgICAgIDwvaW5m" +
+ "b3JtYXRpb24+DQoNCiAgICAgICAgICAgIDxyZXNvdXJjZXM+DQogICAgICAgICAgICAgICAgPGoy" +
+ "c2UgdmVyc2lvbj0nMS42KycgLz4NCiAgICAgICAgICAgICAgICA8amFyIGhyZWY9J0VtYmVkZGVk" +
+ "Sm5scEphck9uZS5qYXInIG1haW49J3RydWUnIC8+DQogICAgICAgICAgICAgICAgPGphciBocmVm" +
+ "PSdFbWJlZGRlZEpubHBKYXJUd28uamFyJyBtYWluPSd0cnVlJyAvPg0KICAgICAgICAgICAgPC9y" +
+ "ZXNvdXJjZXM+DQoNCiAgICAgICAgICAgIDxhcHBsZXQtZGVzYw0KICAgICAgICAgICAgICAgIGRv" +
+ "Y3VtZW50QmFzZT0iLiINCiAgICAgICAgICAgICAgICBuYW1lPSJyZWRoYXQuZW1iZWRkZWRqbmxw" +
+ "Ig0KICAgICAgICAgICAgICAgIG1haW4tY2xhc3M9InJlZGhhdC5lbWJlZGRlZGpubHAiDQogICAg" +
+ "ICAgICAgICAgICAgd2lkdGg9IjAiDQogICAgICAgICAgICAgICAgaGVpZ2h0PSIwIg0KICAgICAg" +
+ "ICAgICAgLz4NCiAgICAgICAgICAgIDwvam5scD4=";
+
+ MockJNLPCreator mockCreator = new MockJNLPCreator();
+ Hashtable<String, String> atts = new Hashtable<String, String>();
+ atts.put("jnlp_href", relativeLocation);
+ atts.put("jnlp_embedded", jnlpFileEncoded);
+
+ String jnlpCodebase = "http://www.redhat.com";
+ PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator);
+ JARDesc[] jars = pb.getResources().getJARs();
+
+ //Check if there are two jars cached
+ Assert.assertTrue(jars.length == 2);
+
+ //Resource can be in any order
+ List<String> resourceLocations = new ArrayList<String>();
+ resourceLocations.add(jars[0].getLocation().toExternalForm());
+ resourceLocations.add(jars[1].getLocation().toExternalForm());
+
+ //Check URLs of jars
+ Assert.assertTrue(resourceLocations.contains(jnlpCodebase + "/EmbeddedJnlpJarOne.jar"));
+ Assert.assertTrue((resourceLocations.contains(jnlpCodebase + "/EmbeddedJnlpJarTwo.jar")));
+ }
+
+ @Test
+ public void testEmbeddedJnlpWithInvalidCodebase() throws Exception {
+ URL overwrittenCodebase = new URL("http://icedtea.classpath.org");
+ String relativeLocation = "/EmbeddedJnlpFile.jnlp";
+
+ //Codebase within jnlp file is INVALID
+ /**
+ <?xml version="1.0"?>
+ <jnlp spec="1.5+"
+ href="EmbeddedJnlpFile.jnlp"
+ codebase="invalidPath"
+ >
+
+ <information>
+ <title>Sample Test</title>
+ <vendor>RedHat</vendor>
+ <offline-allowed/>
+ </information>
+
+ <resources>
+ <j2se version='1.6+' />
+ <jar href='EmbeddedJnlpJarOne.jar' main='true' />
+ <jar href='EmbeddedJnlpJarTwo.jar' main='true' />
+ </resources>
+
+ <applet-desc
+ documentBase="."
+ name="redhat.embeddedjnlp"
+ main-class="redhat.embeddedjnlp"
+ width="0"
+ height="0"
+ />
+ </jnlp>
+ **/
+
+ String jnlpFileEncoded = "ICAgICAgICA8P3htbCB2ZXJzaW9uPSIxLjAiPz4NCiAgICAgICAgICAgIDxqbmxwIHNwZWM9IjEu" +
+ "NSsiIA0KICAgICAgICAgICAgICBocmVmPSJFbWJlZGRlZEpubHBGaWxlLmpubHAiIA0KICAgICAg" +
+ "ICAgICAgICBjb2RlYmFzZT0iaW52YWxpZFBhdGgiICAgIA0KICAgICAgICAgICAgPg0KDQogICAg" +
+ "ICAgICAgICA8aW5mb3JtYXRpb24+DQogICAgICAgICAgICAgICAgPHRpdGxlPlNhbXBsZSBUZXN0" +
+ "PC90aXRsZT4NCiAgICAgICAgICAgICAgICA8dmVuZG9yPlJlZEhhdDwvdmVuZG9yPg0KICAgICAg" +
+ "ICAgICAgICAgIDxvZmZsaW5lLWFsbG93ZWQvPg0KICAgICAgICAgICAgPC9pbmZvcm1hdGlvbj4N" +
+ "Cg0KICAgICAgICAgICAgPHJlc291cmNlcz4NCiAgICAgICAgICAgICAgICA8ajJzZSB2ZXJzaW9u" +
+ "PScxLjYrJyAvPg0KICAgICAgICAgICAgICAgIDxqYXIgaHJlZj0nRW1iZWRkZWRKbmxwSmFyT25l" +
+ "LmphcicgbWFpbj0ndHJ1ZScgLz4NCiAgICAgICAgICAgICAgICA8amFyIGhyZWY9J0VtYmVkZGVk" +
+ "Sm5scEphclR3by5qYXInIG1haW49J3RydWUnIC8+DQogICAgICAgICAgICA8L3Jlc291cmNlcz4N" +
+ "Cg0KICAgICAgICAgICAgPGFwcGxldC1kZXNjDQogICAgICAgICAgICAgICAgZG9jdW1lbnRCYXNl" +
+ "PSIuIg0KICAgICAgICAgICAgICAgIG5hbWU9InJlZGhhdC5lbWJlZGRlZGpubHAiDQogICAgICAg" +
+ "ICAgICAgICAgbWFpbi1jbGFzcz0icmVkaGF0LmVtYmVkZGVkam5scCINCiAgICAgICAgICAgICAg" +
+ "ICB3aWR0aD0iMCINCiAgICAgICAgICAgICAgICBoZWlnaHQ9IjAiDQogICAgICAgICAgICAvPg0K" +
+ "ICAgICAgICAgICAgPC9qbmxwPg==";
+
+ MockJNLPCreator mockCreator = new MockJNLPCreator();
+ Hashtable<String, String> atts = new Hashtable<String, String>();
+ atts.put("jnlp_href", relativeLocation);
+ atts.put("jnlp_embedded", jnlpFileEncoded);
+
+ PluginBridge pb = new PluginBridge(overwrittenCodebase, null, "", "", 0, 0, atts, "", mockCreator);
+ JARDesc[] jars = pb.getResources().getJARs();
+
+ //Check if there are two jars cached
+ Assert.assertTrue(jars.length == 2);
+
+ //Resource can be in any order
+ List<String> resourceLocations = new ArrayList<String>();
+ resourceLocations.add(jars[0].getLocation().toExternalForm());
+ resourceLocations.add(jars[1].getLocation().toExternalForm());
+
+ //Check URLs of jars
+ Assert.assertTrue(resourceLocations.contains(overwrittenCodebase + "/EmbeddedJnlpJarOne.jar"));
+ Assert.assertTrue((resourceLocations.contains(overwrittenCodebase + "/EmbeddedJnlpJarTwo.jar")));
+ }
+
+ @Test
+ public void testInvalidEmbeddedJnlp() throws Exception {
+ URL overwrittenCodebase = new URL("http://icedtea.classpath.org");
+ String relativeLocation = "/EmbeddedJnlpFile.jnlp";
+
+ //Embedded jnlp is invalid
+ String jnlpFileEncoded = "thisContextIsInvalid";
+
+ MockJNLPCreator mockCreator = new MockJNLPCreator();
+ Hashtable<String, String> atts = new Hashtable<String, String>();
+ atts.put("jnlp_href", relativeLocation);
+ atts.put("jnlp_embedded", jnlpFileEncoded);
+
+ try {
+ new PluginBridge(overwrittenCodebase, null, "", "", 0, 0, atts, "", mockCreator);
+ } catch (Exception e) {
+ return;
+ }
+ Assert.fail("PluginBridge was successfully created with an invalid embedded jnlp value");
+ }
+}