diff options
author | Adam Domurad <[email protected]> | 2012-12-04 10:43:59 -0500 |
---|---|---|
committer | Adam Domurad <[email protected]> | 2012-12-04 10:43:59 -0500 |
commit | 1f595aba1e38b1a0113f45492288e22d3fa90799 (patch) | |
tree | 422a8d29652e3084915801fdc960c1c3099ae2a4 /tests/netx/unit/net/sourceforge/jnlp | |
parent | 7aff0a246448bef22d89859b07fef92c128e14e5 (diff) |
Remove redundant HTML-tag scanner from ITW. Do not reconstruct tags.
Diffstat (limited to 'tests/netx/unit/net/sourceforge/jnlp')
-rw-r--r-- | tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java | 53 | ||||
-rw-r--r-- | tests/netx/unit/net/sourceforge/jnlp/PluginParametersTest.java | 114 |
2 files changed, 144 insertions, 23 deletions
diff --git a/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java b/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java index e9069f2..9015acf 100644 --- a/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java +++ b/tests/netx/unit/net/sourceforge/jnlp/PluginBridgeTest.java @@ -29,6 +29,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; +import java.util.Map; import java.util.Hashtable; import java.util.List; import junit.framework.Assert; @@ -64,14 +65,20 @@ public class PluginBridgeTest { } } + static private PluginParameters createValidParamObject() { + Map<String, String> params = new HashMap<String, String>(); + params.put("code", ""); // Avoids an exception being thrown + return new PluginParameters(params); + } + @Test public void testAbsoluteJNLPHref() throws MalformedURLException, Exception { URL codeBase = new URL("http://undesired.absolute.codebase.com"); String absoluteLocation = "http://absolute.href.com/test.jnlp"; - Hashtable<String, String> atts = new Hashtable<String, String>(); - atts.put("jnlp_href", absoluteLocation); + PluginParameters params = createValidParamObject(); + params.put("jnlp_href", absoluteLocation); MockJNLPCreator mockCreator = new MockJNLPCreator(); - PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator); + PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); assertEquals(absoluteLocation, mockCreator.getJNLPHref().toExternalForm()); } @@ -79,12 +86,12 @@ public class PluginBridgeTest { public void testRelativeJNLPHref() throws MalformedURLException, Exception { URL codeBase = new URL("http://desired.absolute.codebase.com/"); String relativeLocation = "sub/dir/test.jnlp"; - Hashtable<String, String> atts = new Hashtable<String, String>(); - atts.put("jnlp_href", relativeLocation); + PluginParameters params = createValidParamObject(); + params.put("jnlp_href", relativeLocation); MockJNLPCreator mockCreator = new MockJNLPCreator(); - PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator); + PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); assertEquals(codeBase.toExternalForm() + relativeLocation, - mockCreator.getJNLPHref().toExternalForm()); + mockCreator.getJNLPHref().toExternalForm()); } @Test @@ -92,12 +99,12 @@ public class PluginBridgeTest { String desiredDomain = "http://desired.absolute.codebase.com"; URL codeBase = new URL(desiredDomain + "/undesired/sub/dir"); String relativeLocation = "/app/test/test.jnlp"; - Hashtable<String, String> atts = new Hashtable<String, String>(); - atts.put("jnlp_href", relativeLocation); + PluginParameters params = createValidParamObject(); + params.put("jnlp_href", relativeLocation); MockJNLPCreator mockCreator = new MockJNLPCreator(); - PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator); + PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); assertEquals(desiredDomain + relativeLocation, - mockCreator.getJNLPHref().toExternalForm()); + mockCreator.getJNLPHref().toExternalForm()); } @Test @@ -166,12 +173,12 @@ public class PluginBridgeTest { "ICAgICAgLz4NCiAgICAgICAgICAgIDwvam5scD4="; MockJNLPCreator mockCreator = new MockJNLPCreator(); - Hashtable<String, String> atts = new Hashtable<String, String>(); - atts.put("jnlp_href", relativeLocation); - atts.put("jnlp_embedded", jnlpFileEncoded); + PluginParameters params = createValidParamObject(); + params.put("jnlp_href", relativeLocation); + params.put("jnlp_embedded", jnlpFileEncoded); String jnlpCodebase = "http://www.redhat.com"; - PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, atts, "", mockCreator); + PluginBridge pb = new PluginBridge(codeBase, null, "", "", 0, 0, params, mockCreator); JARDesc[] jars = pb.getResources().getJARs(); //Check if there are two jars cached @@ -239,11 +246,11 @@ public class PluginBridgeTest { "ICAgICAgICAgICAgPC9qbmxwPg=="; MockJNLPCreator mockCreator = new MockJNLPCreator(); - Hashtable<String, String> atts = new Hashtable<String, String>(); - atts.put("jnlp_href", relativeLocation); - atts.put("jnlp_embedded", jnlpFileEncoded); + PluginParameters params = createValidParamObject(); + params.put("jnlp_href", relativeLocation); + params.put("jnlp_embedded", jnlpFileEncoded); - PluginBridge pb = new PluginBridge(overwrittenCodebase, null, "", "", 0, 0, atts, "", mockCreator); + PluginBridge pb = new PluginBridge(overwrittenCodebase, null, "", "", 0, 0, params, mockCreator); JARDesc[] jars = pb.getResources().getJARs(); //Check if there are two jars cached @@ -268,12 +275,12 @@ public class PluginBridgeTest { 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); + PluginParameters params = createValidParamObject(); + params.put("jnlp_href", relativeLocation); + params.put("jnlp_embedded", jnlpFileEncoded); try { - new PluginBridge(overwrittenCodebase, null, "", "", 0, 0, atts, "", mockCreator); + new PluginBridge(overwrittenCodebase, null, "", "", 0, 0, params, mockCreator); } catch (Exception e) { return; } diff --git a/tests/netx/unit/net/sourceforge/jnlp/PluginParametersTest.java b/tests/netx/unit/net/sourceforge/jnlp/PluginParametersTest.java new file mode 100644 index 0000000..0e05b53 --- /dev/null +++ b/tests/netx/unit/net/sourceforge/jnlp/PluginParametersTest.java @@ -0,0 +1,114 @@ +package net.sourceforge.jnlp; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; + +import org.junit.Test; + +public class PluginParametersTest { + + @Test + public void testAttributeParseJavaPrefix() { + // java_* aliases override older names: + // http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/using_tags.html#in-nav + + Map<String, String> rawParams; + Hashtable<String, String> params; + + rawParams = new HashMap<String, String>(); + rawParams.put("code", "codeValue"); + rawParams.put("java_code", "java_codeValue"); + params = PluginParameters.createParameterTable(rawParams); + + assertEquals("java_codeValue", params.get("code")); + + rawParams = new HashMap<String, String>(); + rawParams.put("codebase", "codebaseValue"); + rawParams.put("java_codebase", "java_codebaseValue"); + params = PluginParameters.createParameterTable(rawParams); + + assertEquals("java_codebaseValue", params.get("codebase")); + + rawParams = new HashMap<String, String>(); + rawParams.put("archive", "archiveValue"); + rawParams.put("java_archive", "java_archiveValue"); + params = PluginParameters.createParameterTable(rawParams); + + assertEquals("java_archiveValue", params.get("archive")); + + rawParams = new HashMap<String, String>(); + rawParams.put("object", "objectValue"); + rawParams.put("java_object", "java_objectValue"); + params = PluginParameters.createParameterTable(rawParams); + + assertEquals("java_objectValue", params.get("object")); + + rawParams = new HashMap<String, String>(); + rawParams.put("type", "typeValue"); + rawParams.put("java_type", "java_typeValue"); + params = PluginParameters.createParameterTable(rawParams); + + assertEquals("java_typeValue", params.get("type")); + } + + @Test + public void testEnsureJavaPrefixTakesPrecedence() { + Map<String, String> params; + params = new HashMap<String, String>(); + params.put("test", "testValue"); + params.put("java_test", "java_testValue"); + PluginParameters.ensureJavaPrefixTakesPrecedence(params, "test"); + assertEquals("java_testValue", params.get("test")); + + params = new HashMap<String, String>(); + params.put("test", "testValue"); + PluginParameters.ensureJavaPrefixTakesPrecedence(params, "test"); + assertEquals("testValue", params.get("test")); + + params = new HashMap<String, String>(); + params.put("java_test", "java_testValue"); + PluginParameters.ensureJavaPrefixTakesPrecedence(params, "test"); + assertEquals("java_testValue", params.get("test")); + } + + @Test + public void testAttributeParseCodeAttribute() { + Map<String, String> rawParams; + Hashtable<String, String> params; + + // Simple test of object tag being set + rawParams = new HashMap<String, String>(); + rawParams.put("object", "objectValue"); + params = PluginParameters.createParameterTable(rawParams); + assertEquals("objectValue", params.get("object")); + + // Classid tag gets used as code tag + rawParams = new HashMap<String, String>(); + rawParams.put("classid", "classidValue"); + params = PluginParameters.createParameterTable(rawParams); + assertEquals("classidValue", params.get("code")); + + // Java: gets stripped from code tag + rawParams = new HashMap<String, String>(); + rawParams.put("code", "java:codeValue"); + params = PluginParameters.createParameterTable(rawParams); + assertEquals("codeValue", params.get("code")); + + // Classid tag gets used as code tag, and java: is stripped + rawParams = new HashMap<String, String>(); + rawParams.put("classid", "java:classidValue"); + params = PluginParameters.createParameterTable(rawParams); + assertEquals("classidValue", params.get("code")); + + // Classid tag gets used as code tag, and clsid: is stripped + rawParams = new HashMap<String, String>(); + rawParams.put("classid", "clsid:classidValue"); + params = PluginParameters.createParameterTable(rawParams); + assertEquals(null, params.get("code")); + + } + +} |