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

TestAutoSuiteStorage

public class TestAutoSuiteStorage extends TestCase
i3test for AutoSuiteStorage

Fields Summary
private static final String
NONEXISTENT_SUITE_URL
URL of unexistent suite
private static final String
SUITE_URL
URL of suite to install
Constructors Summary
Methods Summary
public voidrunTests()
Run tests

        testStorage();
        testFailures();
    
voidtestFailures()
Test failures

    
            
      
        boolean exceptionThrown;
        
        declare("Obtain AutoSuiteStorage instance");
        AutoSuiteStorage storage = AutoSuiteStorage.getStorage();
        assertNotNull("Failed to obtain AutoSuiteStorage instance", storage);

        declare("Install nonexistent suite");
        exceptionThrown = false;
        try {
            AutoSuiteDescriptor suite = null;
            suite = storage.installSuite(NONEXISTENT_SUITE_URL);
        } catch (Exception e) {
            exceptionThrown = true;
        }
        assertTrue("Installed nonexistent suite", exceptionThrown);

        declare("Install suite");
        AutoSuiteDescriptor suite = null;
        try {
            suite = storage.installSuite(SUITE_URL);
        } catch (Exception e) {
        }
        assertNotNull("Failed to install suite", suite);


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

        declare("Uninstall not installed suite");
        exceptionThrown = false;
        try {
            storage.uninstallSuite(suite);
        } catch (Exception e) {
            exceptionThrown = true;
        }
        assertTrue("Uninstalled not installed suite", exceptionThrown);
    
voidtestStorage()
Tests operations with storage

        declare("Obtain AutoSuiteStorage instance");
        AutoSuiteStorage storage = AutoSuiteStorage.getStorage();
        assertNotNull("Failed to obtain AutoSuiteStorage instance", storage);

        Vector suites = storage.getInstalledSuites();
        assertNotNull("Failed to obtain list of installed suites", suites);

        int totalSuitesBefore = suites.size();

        declare("Install suite");
        AutoSuiteDescriptor suite = null;
        try {
            suite = storage.installSuite(SUITE_URL);
        } catch (Exception e) {
        }
        assertNotNull("Failed to install suite", suite);

        suites = storage.getInstalledSuites();
        int totalSuitesAfter = suites.size();
        assertTrue("Invalid number of installed suites", 
                totalSuitesAfter == totalSuitesBefore + 1);

        System.out.println("Suite name: " + suite.getSuiteName());
        Vector midlets = suite.getSuiteMIDlets();
        for (int i = 0; i < midlets.size(); ++i) {
            AutoMIDletDescriptor midlet;
            midlet = (AutoMIDletDescriptor)midlets.elementAt(i);
            System.out.println("MIDlet #" + i);
            System.out.println("  name : " + midlet.getMIDletName());
            System.out.println("  class: " + midlet.getMIDletClassName());
            System.out.println("");
        }
        
        declare("Uninstall suite");
        boolean exceptionThrown = false;
        try {
            storage.uninstallSuite(suite);
        } catch (Exception e) {
            exceptionThrown = true;
        }
        assertFalse("Failed to uninstall suite", exceptionThrown);

        suites = storage.getInstalledSuites();
        totalSuitesAfter = suites.size();
        assertTrue("Invalid number of installed suites", 
                totalSuitesAfter == totalSuitesBefore);