001: /*
002: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024:
025: package com.sun.jumpimpl.module.preferences;
026:
027: import junit.framework.*;
028:
029: import com.sun.jump.module.contentstore.*;
030: import com.sun.jump.executive.JUMPExecutive;
031: import com.sun.jumpimpl.process.JUMPModulesConfig;
032: import com.sun.jump.module.preferences.*;
033: import com.sun.jumpimpl.module.preferences.*;
034:
035: public class PreferencesModuleTest extends TestCase {
036:
037: JUMPPreferencesModuleFactory prefModule = null;
038: JUMPPreferencesModule sysModule = null;
039: boolean debugmode = false;
040:
041: public PreferencesModuleTest() {
042: initTest();
043: String dprop = System.getProperty("debug");
044: if ((dprop != null) && (dprop.equals("true"))) {
045: debugmode = true;
046: System.err.println("Debug Mode Turned ON!");
047: }
048: }
049:
050: private void initTest() {
051: // Executive setup for testing
052: if (JUMPExecutive.getInstance() == null) {
053: JUMPStoreFactory factory = new com.sun.jumpimpl.module.contentstore.StoreFactoryImpl();
054: factory.load(JUMPModulesConfig.getProperties());
055: new com.sun.jumpimpl.module.preferences.PreferencesModuleFactoryImpl();
056: }
057:
058: prefModule = JUMPPreferencesModuleFactory.getInstance();
059:
060: if (prefModule != null) {
061: sysModule = prefModule
062: .getModule(JUMPPreferencesModuleFactory.TYPE_SYSTEM_PREFERENCES);
063: }
064: }
065:
066: public void testValidPreferenceType() {
067: if (prefModule != null) {
068: try {
069: JUMPPreferencesModule module = prefModule
070: .getModule("Invalid-Type");
071: } catch (IllegalArgumentException success) {
072: assertNotNull(success.getMessage());
073: }
074: }
075: }
076:
077: public void testSetGetPreferences() {
078:
079: if (sysModule != null) {
080:
081: printDebug("Starting Set&Get Preferences Test:");
082:
083: setPreferences();
084:
085: // Get the preferences
086: String colorVal = sysModule.getPreference("Color");
087: String fontVal = sysModule.getPreference("Font");
088: String modeVal = sysModule.getPreference("Mode");
089:
090: // check if they were set fine
091: assertEquals("Gray", colorVal);
092: assertEquals("Sansaref", fontVal);
093: assertEquals("fullscreen", modeVal);
094:
095: // Debug: print the preferences
096: printDebug("Color Value = "
097: + sysModule.getPreference("Color"));
098: printDebug("Font Value = "
099: + sysModule.getPreference("Font"));
100: printDebug("Mode Value = "
101: + sysModule.getPreference("Mode"));
102: }
103: }
104:
105: public void testDeletePreferences() {
106:
107: if (sysModule != null) {
108:
109: printDebug("Starting Delete Preferences Test:");
110:
111: setPreferences();
112: // delete "Color" preference
113: sysModule.deletePreference("Color");
114: // check if it got deleted
115: String colorVal = sysModule.getPreference("Color");
116: assertEquals(null, colorVal);
117:
118: printDebug("Deleted Color Preference => "
119: + sysModule.getPreference("Color"));
120: } else {
121: printDebug("JUMPPreferencesModuleFactory instance NULL");
122: }
123: }
124:
125: private void setPreferences() {
126: // Set some system preferences
127: sysModule.setPreference("Color", "Gray");
128: sysModule.setPreference("Font", "Sansaref");
129: sysModule.setPreference("Mode", "fullscreen");
130: // save the data
131: sysModule.save();
132: }
133:
134: private void printDebug(String msg) {
135: if (debugmode) {
136: System.err.println(msg);
137: }
138: }
139:
140: }
|