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.automation;
028:
029: import com.sun.midp.i3test.*;
030: import java.util.*;
031:
032: /**
033: * i3test for switching running midlets functionality
034: */
035: public class TestSwitchMidlets extends TestCase {
036: /** URL of the first suite to install */
037: private static final String SUITE1_URL = "http://localhost/midlets/HelloMIDlet.jad";
038:
039: /** URL of the second suite to install */
040: private static final String SUITE2_URL = "http://localhost/midlets/GrinderBench.jad";
041:
042: /** Midlet suite storage */
043: private AutoSuiteStorage storage = null;
044:
045: /** Descriptor of the 1st midlet suite */
046: private AutoSuiteDescriptor suite1 = null;
047:
048: /** Descriptor of the 2nd midlet suite */
049: private AutoSuiteDescriptor suite2 = null;
050:
051: /** Descriptor of the 1st midlet */
052: private AutoMIDletDescriptor midletDescr1 = null;
053:
054: /** Descriptor of the 2nd midlet */
055: private AutoMIDletDescriptor midletDescr2 = null;
056:
057: /**
058: * Installs the test suites.
059: */
060: void installTestSuites() {
061: declare("Install suites");
062: storage = AutoSuiteStorage.getStorage();
063:
064: try {
065: suite1 = storage.installSuite(SUITE1_URL);
066: suite2 = storage.installSuite(SUITE2_URL);
067: } catch (Exception e) {
068: }
069:
070: assertNotNull("Failed to install suite 1", suite1);
071: assertNotNull("Failed to install suite 2", suite2);
072:
073: System.out.println("Suite 1 name: " + suite1.getSuiteName());
074: System.out.println("Suite 2 name: " + suite1.getSuiteName());
075:
076: Vector midlets1 = suite1.getSuiteMIDlets();
077: Vector midlets2 = suite2.getSuiteMIDlets();
078:
079: midletDescr1 = (AutoMIDletDescriptor) midlets1.elementAt(0);
080: midletDescr2 = (AutoMIDletDescriptor) midlets2.elementAt(0);
081: }
082:
083: /**
084: * Uninstalls the test suites.
085: */
086: void uninstallTestSuites() {
087: declare("Uninstall suites");
088: boolean exceptionThrown = false;
089: try {
090: storage.uninstallSuite(suite1);
091: storage.uninstallSuite(suite2);
092: } catch (Exception e) {
093: exceptionThrown = true;
094: }
095: assertFalse("Failed to uninstall suites", exceptionThrown);
096: }
097:
098: /**
099: * Tests operations with storage
100: */
101: void testSwitchMidlets() {
102: installTestSuites();
103:
104: declare("Run suites");
105: AutoMIDlet midlet1 = midletDescr1.start(null);
106: AutoMIDlet midlet2 = midletDescr2.start(null);
107:
108: // Initial state is 'PAUSED'.
109: midlet1.switchTo(AutoMIDletLifeCycleState.ACTIVE, true);
110: midlet2.switchTo(AutoMIDletLifeCycleState.ACTIVE, true);
111:
112: assertTrue("Invalid state of the midlet #1.", midlet1
113: .getLifeCycleState().equals(
114: AutoMIDletLifeCycleState.ACTIVE));
115: assertTrue("Invalid state of the midlet #2.", midlet2
116: .getLifeCycleState().equals(
117: AutoMIDletLifeCycleState.ACTIVE));
118:
119: midlet1.switchTo(AutoMIDletForegroundState.FOREGROUND, true);
120: midlet2.switchTo(AutoMIDletForegroundState.BACKGROUND, true);
121:
122: try {
123: Thread.sleep(2000);
124: } catch (InterruptedException ie) {
125: }
126:
127: midlet2.switchTo(AutoMIDletForegroundState.FOREGROUND, true);
128:
129: try {
130: Thread.sleep(2000);
131: } catch (InterruptedException ie) {
132: }
133:
134: midlet1.switchTo(AutoMIDletLifeCycleState.DESTROYED, true);
135: midlet2.switchTo(AutoMIDletLifeCycleState.DESTROYED, true);
136:
137: uninstallTestSuites();
138: }
139:
140: /**
141: * Run tests
142: */
143: public void runTests() {
144: testSwitchMidlets();
145: }
146: }
|