aboutsummaryrefslogtreecommitdiffstats
path: root/tests/netx/unit/net/sourceforge/jnlp/PluginParametersTest.java
blob: fd855e219ffa02356fc8274a1ba6e2085a052b4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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"));

    }

    /**
     * Initialize PluginParameters without code/object parameters
     */
    @Test(expected = PluginParameterException.class)
    public void testConstructorWithNoCodeAndObjectParam() {
        Map<String, String> rawParams = new HashMap<String, String>();
        rawParams.put("classid", "clsid:classidValue");
        new PluginParameters(rawParams);
    }

    /**
     * Initialize PluginParameters with jnlp_href but no code/object parameters
     */
    @Test
    public void testConstructorWithOnlyJnlpHrefParam() {
        Map<String, String> rawParams = new HashMap<String, String>();
        rawParams.put("jnlp_href", "applet.jnlp");
        PluginParameters pluginParam = new PluginParameters(rawParams);
        assertEquals("applet.jnlp", pluginParam.getJNLPHref());
    }
}