1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.configuration.web;
19
20 import org.apache.commons.configuration.AbstractConfiguration;
21 import org.apache.commons.configuration.BaseConfiguration;
22 import org.apache.commons.configuration.MapConfiguration;
23 import org.apache.commons.configuration.TestAbstractConfiguration;
24
25 import java.applet.Applet;
26 import java.util.Properties;
27
28 /***
29 * Test case for the {@link AppletConfiguration} class.
30 *
31 * @author Emmanuel Bourg
32 * @version $Revision: 439648 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb
33 * 2005) $
34 */
35 public class TestAppletConfiguration extends TestAbstractConfiguration
36 {
37 /*** A flag whether tests with an applet can be run. */
38 boolean supportsApplet;
39
40 /***
41 * Initializes the tests. This implementation checks whether an applet can
42 * be used. Some environments, which do not support a GUI, don't allow
43 * creating an <code>Applet</code> instance. If we are in such an
44 * environment, some tests need to behave differently or be completely
45 * dropped.
46 */
47 protected void setUp() throws Exception
48 {
49 try
50 {
51 new Applet();
52 supportsApplet = true;
53 }
54 catch (Exception ex)
55 {
56
57 supportsApplet = false;
58 }
59 }
60
61 protected AbstractConfiguration getConfiguration()
62 {
63 final Properties parameters = new Properties();
64 parameters.setProperty("key1", "value1");
65 parameters.setProperty("key2", "value2");
66 parameters.setProperty("list", "value1, value2");
67
68 if (supportsApplet)
69 {
70 Applet applet = new Applet()
71 {
72 public String getParameter(String key)
73 {
74 return parameters.getProperty(key);
75 }
76
77 public String[][] getParameterInfo()
78 {
79 return new String[][]
80 {
81 { "key1", "String", "" },
82 { "key2", "String", "" },
83 { "list", "String[]", "" } };
84 }
85 };
86
87 return new AppletConfiguration(applet);
88 }
89 else
90 {
91 return new MapConfiguration(parameters);
92 }
93 }
94
95 protected AbstractConfiguration getEmptyConfiguration()
96 {
97 if (supportsApplet)
98 {
99 return new AppletConfiguration(new Applet());
100 }
101 else
102 {
103 return new BaseConfiguration();
104 }
105 }
106
107 public void testAddPropertyDirect()
108 {
109 if (supportsApplet)
110 {
111 try
112 {
113 super.testAddPropertyDirect();
114 fail("addPropertyDirect should throw an UnsupportedException");
115 }
116 catch (UnsupportedOperationException e)
117 {
118
119 }
120 }
121 }
122
123 public void testClearProperty()
124 {
125 if (supportsApplet)
126 {
127 try
128 {
129 super.testClearProperty();
130 fail("testClearProperty should throw an UnsupportedException");
131 }
132 catch (UnsupportedOperationException e)
133 {
134
135 }
136 }
137 }
138 }