FileDocCategorySizeDatePackage
TestSwitchMidlets.javaAPI DocphoneME MR2 API (J2ME)4635Wed May 02 18:00:08 BST 2007com.sun.midp.automation

TestSwitchMidlets

public class TestSwitchMidlets extends TestCase
i3test for switching running midlets functionality

Fields Summary
private static final String
SUITE1_URL
URL of the first suite to install
private static final String
SUITE2_URL
URL of the second suite to install
private AutoSuiteStorage
storage
Midlet suite storage
private AutoSuiteDescriptor
suite1
Descriptor of the 1st midlet suite
private AutoSuiteDescriptor
suite2
Descriptor of the 2nd midlet suite
private AutoMIDletDescriptor
midletDescr1
Descriptor of the 1st midlet
private AutoMIDletDescriptor
midletDescr2
Descriptor of the 2nd midlet
Constructors Summary
Methods Summary
voidinstallTestSuites()
Installs the test suites.


             
      
        declare("Install suites");
        storage = AutoSuiteStorage.getStorage();

        try {
            suite1 = storage.installSuite(SUITE1_URL);
            suite2 = storage.installSuite(SUITE2_URL);
        } catch (Exception e) {
        }

        assertNotNull("Failed to install suite 1", suite1);
        assertNotNull("Failed to install suite 2", suite2);

        System.out.println("Suite 1 name: " + suite1.getSuiteName());
        System.out.println("Suite 2 name: " + suite1.getSuiteName());

        Vector midlets1 = suite1.getSuiteMIDlets();
        Vector midlets2 = suite2.getSuiteMIDlets();

        midletDescr1 = (AutoMIDletDescriptor)midlets1.elementAt(0);
        midletDescr2 = (AutoMIDletDescriptor)midlets2.elementAt(0);
    
public voidrunTests()
Run tests

        testSwitchMidlets();
    
voidtestSwitchMidlets()
Tests operations with storage

        installTestSuites();

        declare("Run suites");
        AutoMIDlet midlet1 = midletDescr1.start(null);
        AutoMIDlet midlet2 = midletDescr2.start(null);

        // Initial state is 'PAUSED'.
        midlet1.switchTo(AutoMIDletLifeCycleState.ACTIVE, true);
        midlet2.switchTo(AutoMIDletLifeCycleState.ACTIVE, true);

        assertTrue("Invalid state of the midlet #1.", midlet1.
            getLifeCycleState().equals(AutoMIDletLifeCycleState.ACTIVE));
        assertTrue("Invalid state of the midlet #2.", midlet2.
            getLifeCycleState().equals(AutoMIDletLifeCycleState.ACTIVE));

        midlet1.switchTo(AutoMIDletForegroundState.FOREGROUND, true);
        midlet2.switchTo(AutoMIDletForegroundState.BACKGROUND, true);

        try {
            Thread.sleep(2000);
        } catch (InterruptedException ie) {
        }

        midlet2.switchTo(AutoMIDletForegroundState.FOREGROUND, true);

        try {
            Thread.sleep(2000);
        } catch (InterruptedException ie) {
        }

        midlet1.switchTo(AutoMIDletLifeCycleState.DESTROYED, true);
        midlet2.switchTo(AutoMIDletLifeCycleState.DESTROYED, true);

        uninstallTestSuites();
    
voiduninstallTestSuites()
Uninstalls the test suites.

        declare("Uninstall suites");
        boolean exceptionThrown = false;
        try {
            storage.uninstallSuite(suite1);
            storage.uninstallSuite(suite2);
        } catch (Exception e) {
            exceptionThrown = true;
        }
        assertFalse("Failed to uninstall suites", exceptionThrown);