1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.configuration2.web;
19
20 import static org.junit.jupiter.api.Assertions.assertFalse;
21 import static org.junit.jupiter.api.Assertions.assertThrows;
22
23 import java.applet.Applet;
24 import java.util.Properties;
25
26 import org.apache.commons.configuration2.AbstractConfiguration;
27 import org.apache.commons.configuration2.BaseConfiguration;
28 import org.apache.commons.configuration2.MapConfiguration;
29 import org.apache.commons.configuration2.TestAbstractConfiguration;
30 import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33
34
35
36
37 public class TestAppletConfiguration extends TestAbstractConfiguration {
38
39
40 private boolean supportsApplet;
41
42 @Override
43 protected AbstractConfiguration getConfiguration() {
44 final AbstractConfiguration config;
45 final Properties parameters = new Properties();
46 parameters.setProperty("key1", "value1");
47 parameters.setProperty("key2", "value2");
48 parameters.setProperty("list", "value1, value2");
49 parameters.setProperty("listesc", "value1\\,value2");
50
51 if (supportsApplet) {
52 final Applet applet = new Applet() {
53
54
55
56 private static final long serialVersionUID = 1L;
57
58 @Override
59 public String getParameter(final String key) {
60 return parameters.getProperty(key);
61 }
62
63 @Override
64 public String[][] getParameterInfo() {
65 return new String[][] {{"key1", "String", ""}, {"key2", "String", ""}, {"list", "String[]", ""}, {"listesc", "String", ""}};
66 }
67 };
68
69 config = new AppletConfiguration(applet);
70 } else {
71 config = new MapConfiguration(parameters);
72 }
73
74 config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
75 return config;
76 }
77
78 @Override
79 protected AbstractConfiguration getEmptyConfiguration() {
80 if (supportsApplet) {
81 return new AppletConfiguration(new Applet());
82 }
83 return new BaseConfiguration();
84 }
85
86
87
88
89
90
91 @BeforeEach
92 public void setUp() throws Exception {
93 try {
94 new Applet();
95 supportsApplet = true;
96 } catch (final Exception ex) {
97
98 supportsApplet = false;
99 }
100 }
101
102 @Override
103 @Test
104 public void testAddPropertyDirect() {
105 if (supportsApplet) {
106 assertThrows(UnsupportedOperationException.class, super::testAddPropertyDirect);
107 }
108 }
109
110 @Override
111 @Test
112 public void testClearProperty() {
113 if (supportsApplet) {
114 assertThrows(UnsupportedOperationException.class, super::testClearProperty);
115 }
116 }
117
118 @Override
119 @Test
120 public void testContainsValue() {
121 assertFalse(getConfiguration().containsValue(null));
122 assertFalse(getConfiguration().containsValue(""));
123 }
124 }