001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.configuration.web;
019:
020: import org.apache.commons.configuration.AbstractConfiguration;
021: import org.apache.commons.configuration.BaseConfiguration;
022: import org.apache.commons.configuration.MapConfiguration;
023: import org.apache.commons.configuration.TestAbstractConfiguration;
024:
025: import java.applet.Applet;
026: import java.util.Properties;
027:
028: /**
029: * Test case for the {@link AppletConfiguration} class.
030: *
031: * @author Emmanuel Bourg
032: * @version $Revision: 515306 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb
033: * 2005) $
034: */
035: public class TestAppletConfiguration extends TestAbstractConfiguration {
036: /** A flag whether tests with an applet can be run. */
037: boolean supportsApplet;
038:
039: /**
040: * Initializes the tests. This implementation checks whether an applet can
041: * be used. Some environments, which do not support a GUI, don't allow
042: * creating an <code>Applet</code> instance. If we are in such an
043: * environment, some tests need to behave differently or be completely
044: * dropped.
045: */
046: protected void setUp() throws Exception {
047: try {
048: new Applet();
049: supportsApplet = true;
050: } catch (Exception ex) {
051: // cannot use applets
052: supportsApplet = false;
053: }
054: }
055:
056: protected AbstractConfiguration getConfiguration() {
057: final Properties parameters = new Properties();
058: parameters.setProperty("key1", "value1");
059: parameters.setProperty("key2", "value2");
060: parameters.setProperty("list", "value1, value2");
061: parameters.setProperty("listesc", "value1\\,value2");
062:
063: if (supportsApplet) {
064: Applet applet = new Applet() {
065: public String getParameter(String key) {
066: return parameters.getProperty(key);
067: }
068:
069: public String[][] getParameterInfo() {
070: return new String[][] { { "key1", "String", "" },
071: { "key2", "String", "" },
072: { "list", "String[]", "" },
073: { "listesc", "String", "" } };
074: }
075: };
076:
077: return new AppletConfiguration(applet);
078: } else {
079: return new MapConfiguration(parameters);
080: }
081: }
082:
083: protected AbstractConfiguration getEmptyConfiguration() {
084: if (supportsApplet) {
085: return new AppletConfiguration(new Applet());
086: } else {
087: return new BaseConfiguration();
088: }
089: }
090:
091: public void testAddPropertyDirect() {
092: if (supportsApplet) {
093: try {
094: super .testAddPropertyDirect();
095: fail("addPropertyDirect should throw an UnsupportedException");
096: } catch (UnsupportedOperationException e) {
097: // ok
098: }
099: }
100: }
101:
102: public void testClearProperty() {
103: if (supportsApplet) {
104: try {
105: super .testClearProperty();
106: fail("testClearProperty should throw an UnsupportedException");
107: } catch (UnsupportedOperationException e) {
108: // ok
109: }
110: }
111: }
112: }
|