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
57 private static final long serialVersionUID = 1L;
58
59 @Override
60 public String getParameter(final String key) {
61 return parameters.getProperty(key);
62 }
63
64 @Override
65 public String[][] getParameterInfo() {
66 return new String[][] {{"key1", "String", ""}, {"key2", "String", ""}, {"list", "String[]", ""}, {"listesc", "String", ""}};
67 }
68 };
69
70 config = new AppletConfiguration(applet);
71 } else {
72 config = new MapConfiguration(parameters);
73 }
74
75 config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
76 return config;
77 }
78
79 @Override
80 protected AbstractConfiguration getEmptyConfiguration() {
81 if (supportsApplet) {
82 return new AppletConfiguration(new Applet());
83 }
84 return new BaseConfiguration();
85 }
86
87
88
89
90
91
92 @BeforeEach
93 public void setUp() throws Exception {
94 try {
95 new Applet();
96 supportsApplet = true;
97 } catch (final Exception ex) {
98
99 supportsApplet = false;
100 }
101 }
102
103 @Override
104 @Test
105 public void testAddPropertyDirect() {
106 if (supportsApplet) {
107 assertThrows(UnsupportedOperationException.class, super::testAddPropertyDirect);
108 }
109 }
110
111 @Override
112 @Test
113 public void testClearProperty() {
114 if (supportsApplet) {
115 assertThrows(UnsupportedOperationException.class, super::testClearProperty);
116 }
117 }
118
119 @Override
120 @Test
121 public void testContainsValue() {
122 assertFalse(getConfiguration().containsValue(null));
123 assertFalse(getConfiguration().containsValue(""));
124 }
125 }