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 static org.junit.Assert.fail;
21
22 import java.applet.Applet;
23 import java.util.Properties;
24
25 import org.apache.commons.configuration.AbstractConfiguration;
26 import org.apache.commons.configuration.BaseConfiguration;
27 import org.apache.commons.configuration.MapConfiguration;
28 import org.apache.commons.configuration.TestAbstractConfiguration;
29 import org.junit.Before;
30 import org.junit.Test;
31
32
33
34
35
36
37
38 public class TestAppletConfiguration extends TestAbstractConfiguration
39 {
40
41 boolean supportsApplet;
42
43
44
45
46
47
48
49
50 @Before
51 public void setUp() throws Exception
52 {
53 try
54 {
55 new Applet();
56 supportsApplet = true;
57 }
58 catch (Exception ex)
59 {
60
61 supportsApplet = false;
62 }
63 }
64
65 @Override
66 protected AbstractConfiguration getConfiguration()
67 {
68 final Properties parameters = new Properties();
69 parameters.setProperty("key1", "value1");
70 parameters.setProperty("key2", "value2");
71 parameters.setProperty("list", "value1, value2");
72 parameters.setProperty("listesc", "value1\\,value2");
73
74 if (supportsApplet)
75 {
76 Applet applet = new Applet()
77 {
78
79
80
81 private static final long serialVersionUID = 1L;
82
83 @Override
84 public String getParameter(String key)
85 {
86 return parameters.getProperty(key);
87 }
88
89 @Override
90 public String[][] getParameterInfo()
91 {
92 return new String[][]
93 {
94 { "key1", "String", "" },
95 { "key2", "String", "" },
96 { "list", "String[]", "" },
97 { "listesc", "String", "" } };
98 }
99 };
100
101 return new AppletConfiguration(applet);
102 }
103 else
104 {
105 return new MapConfiguration(parameters);
106 }
107 }
108
109 @Override
110 protected AbstractConfiguration getEmptyConfiguration()
111 {
112 if (supportsApplet)
113 {
114 return new AppletConfiguration(new Applet());
115 }
116 else
117 {
118 return new BaseConfiguration();
119 }
120 }
121
122 @Override
123 @Test
124 public void testAddPropertyDirect()
125 {
126 if (supportsApplet)
127 {
128 try
129 {
130 super.testAddPropertyDirect();
131 fail("addPropertyDirect should throw an UnsupportedException");
132 }
133 catch (UnsupportedOperationException e)
134 {
135
136 }
137 }
138 }
139
140 @Override
141 @Test
142 public void testClearProperty()
143 {
144 if (supportsApplet)
145 {
146 try
147 {
148 super.testClearProperty();
149 fail("testClearProperty should throw an UnsupportedException");
150 }
151 catch (UnsupportedOperationException e)
152 {
153
154 }
155 }
156 }
157 }