001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.midp.content;
028:
029: import com.sun.midp.midlet.MIDletSuite;
030: import com.sun.midp.i3test.TestCase;
031:
032: import javax.microedition.content.Registry;
033: import javax.microedition.content.ContentHandler;
034:
035: /**
036: * Test the internal functions of RegistryImpl.
037: */
038: public class TestRegistryImpl extends ExtendedTestCase {
039: /** Constant application ID for testing. */
040: private static final String SUITE_ID = "GraphicalInstaller";
041: /** Constant classname for testing. */
042: private static final String CLASSNAME = "classname";
043:
044: /** The name and ID of the GraphicalInstaller. */
045: private static final String GS_NAME = "GraphicalInstaller";
046: /** The suiteId of the GraphicalInstaller. */
047: private static final int GS_SUITEID = MIDletSuite.INTERNAL_SUITE_ID;
048: /** The class of the GraphicalInstaller. */
049: private static final String GS_CLASSNAME = "com.sun.midp.installer.GraphicalInstaller";
050: /** The types registered for the GraphicalInstaller. */
051: private String[] types = { "text/vnd.sun.j2me.app-descriptor",
052: "application/java-archive" };
053: /** The suffixes registered for the GraphicalInstaller. */
054: private String[] suffixes = { ".jad", ".jar" };
055:
056: /** The registry to use. */
057: RegistryImpl registry;
058:
059: /**
060: * Run the tests.
061: */
062: public void runTests() {
063: setup();
064: test001();
065: test002();
066: }
067:
068: /**
069: * Setup the registry.
070: */
071: void setup() {
072: registry = getRegistry();
073: }
074:
075: /**
076: * Test that the built-in suite is registered.
077: * The Graphical Installer must be present.
078: */
079: void test001() {
080: declare("Verify built-in registration for GraphicalInstaller");
081: try {
082: AppProxy app = AppProxy.getCurrent().forClass(GS_CLASSNAME);
083: ContentHandlerImpl ch = registry.getServer(app);
084:
085: assertNotNull("Verify GraphicalInstaller is present", ch);
086: if (ch != null) {
087: assertEquals("Verify getID", GS_NAME, ch.getID());
088:
089: assertEquals("Verify classname", GS_CLASSNAME,
090: ch.classname);
091: assertEquals("Verify getTypeCount", 2, ch
092: .getTypeCount());
093: assertEquals("Verify Type1", types[0], ch.getType(0));
094: assertEquals("Verify Type2", types[1], ch.getType(1));
095: assertEquals("Verify getSuffixCount", 2, ch
096: .getSuffixCount());
097: assertEquals("Verify Suffix1", suffixes[0], ch
098: .getSuffix(0));
099: assertEquals("Verify Suffix2", suffixes[1], ch
100: .getSuffix(1));
101: assertEquals("Verify Action", 2, ch.getActionCount());
102: assertEquals("Verify Action Name Maps", 3, ch
103: .getActionNameMapCount());
104: }
105: } catch (ClassNotFoundException cnfe) {
106: fail("Unexpected exception");
107: cnfe.printStackTrace();
108: }
109: }
110:
111: /**
112: * Test that the value of the System property "CHAPI-Version"
113: * is "1.0".
114: */
115: void test002() {
116: declare("Check system properties");
117: String ver = System.getProperty("microedition.chapi.version");
118: assertEquals("Verify microedition.chapi.version", "1.0", ver);
119: }
120:
121: }
|