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: 515306 $, $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 parameters.setProperty("listesc", "value1//,value2");
68
69 if (supportsApplet)
70 {
71 Applet applet = new Applet()
72 {
73 public String getParameter(String key)
74 {
75 return parameters.getProperty(key);
76 }
77
78 public String[][] getParameterInfo()
79 {
80 return new String[][]
81 {
82 { "key1", "String", "" },
83 { "key2", "String", "" },
84 { "list", "String[]", "" },
85 { "listesc", "String", "" } };
86 }
87 };
88
89 return new AppletConfiguration(applet);
90 }
91 else
92 {
93 return new MapConfiguration(parameters);
94 }
95 }
96
97 protected AbstractConfiguration getEmptyConfiguration()
98 {
99 if (supportsApplet)
100 {
101 return new AppletConfiguration(new Applet());
102 }
103 else
104 {
105 return new BaseConfiguration();
106 }
107 }
108
109 public void testAddPropertyDirect()
110 {
111 if (supportsApplet)
112 {
113 try
114 {
115 super.testAddPropertyDirect();
116 fail("addPropertyDirect should throw an UnsupportedException");
117 }
118 catch (UnsupportedOperationException e)
119 {
120
121 }
122 }
123 }
124
125 public void testClearProperty()
126 {
127 if (supportsApplet)
128 {
129 try
130 {
131 super.testClearProperty();
132 fail("testClearProperty should throw an UnsupportedException");
133 }
134 catch (UnsupportedOperationException e)
135 {
136
137 }
138 }
139 }
140 }