FileDocCategorySizeDatePackage
TestMIDletControllerEventProducer.javaAPI DocphoneME MR2 API (J2ME)17951Wed May 02 18:00:06 BST 2007com.sun.midp.main

TestMIDletControllerEventProducer

public class TestMIDletControllerEventProducer extends com.sun.midp.i3test.TestCase implements MIDletControllerEventConsumer
Unit tests for the MIDletControllerEventProducer class. This class, and event producer classes in general, don't have much logic. However, they do implement the mapping between specific data and generic event fields (e.g., intParam1 or stringParam2) which is important to test.

Fields Summary
private com.sun.midp.security.SecurityToken
token
Random
rand
static final int
SUITE_ID
static final String
CLASS_NAME
static final String
DISPLAY_NAME
static final int
TARGET_SUITE_ID
static final String
TARGET_CLASS_NAME
static final String
ERROR_DETAILES
int
currentIsolateId
int
amsIsolateId
int
displayId
int
displayId2
int
externalId
int
errorCode
com.sun.midp.events.EventQueue
queue
MIDletControllerEventProducer
producer
MIDletControllerEventListener
listener
Constructors Summary
Methods Summary
public voidhandleActivateAllEvent()
Process an ACTIVATE_ALL_EVENT. MIDletControllerEventConsumer I/F method.

        assertTrue(true);
    
public voidhandleDestroyAllEvent()
Process a SHUTDOWN_ALL_EVENT. MIDletControllerEventConsumer I/F method. It simply calls "shutdown()". In future it shall be merged with "shutdown()" and substitute it.

        assertTrue(true);
    
public voidhandleDisplayBackgroundRequestEvent(int midletIsolateId, int midletDisplayId)
Process a background request event. MIDletControllerEventConsumer I/F method.

param
midletIsolateId isolate ID of the sending Display
param
midletDisplayId ID of the sending Display


        assertEquals(currentIsolateId, midletIsolateId);
        assertEquals(displayId, midletDisplayId);
    
public voidhandleDisplayCreateNotifyEvent(int midletIsolateId, int midletDisplayId, java.lang.String midletClassName)
Process a Display created notification. MIDletControllerEventConsumer I/F method.

param
midletIsolateId isolate ID of the sending Display
param
midletDisplayId ID of the sending Display
param
midletClassName Class name of the MIDlet that owns the display


        assertEquals(currentIsolateId, midletIsolateId);
        assertEquals(displayId, midletDisplayId);
        assertEquals(CLASS_NAME, midletClassName);
    
public voidhandleDisplayForegroundRequestEvent(int midletIsolateId, int midletDisplayId, boolean isAlert)
Process a foreground request event. MIDletControllerEventConsumer I/F method.

param
midletIsolateId isolate ID of the sending Display
param
midletDisplayId ID of the sending Display
param
isAlert true if the current displayable is an Alert


        assertEquals(currentIsolateId, midletIsolateId);
        assertEquals(displayId, midletDisplayId);
        assertTrue(isAlert);
    
public voidhandleDisplayPreemptStartEvent(int midletIsolateId, int midletDisplayId)
Process a "display preempt start" event.

Set the foreground to a given display if a certain display has the foreground. Used to start preempting. MIDletControllerEventConsumer I/F method.

param
midletIsolateId isolate ID of the sending Display
param
midletDisplayId ID of the sending Display


        assertEquals(currentIsolateId, midletIsolateId);
        assertEquals(displayId, midletDisplayId);
    
public voidhandleDisplayPreemptStopEvent(int midletIsolateId, int midletDisplayId)
Process a "display preempt stop" event.

Set the foreground to a given display if a certain display has the foreground. Used to end preempting. MIDletControllerEventConsumer I/F method.

param
midletIsolateId isolate ID of the sending Display
param
midletDisplayId ID of the sending Display


        assertEquals(currentIsolateId, midletIsolateId);
        assertEquals(displayId2, midletDisplayId);
    
public voidhandleFatalErrorNotifyEvent(int midletIsolateId, int midletDisplayId)
Processes FATAL_ERROR_NOTIFICATION. MIDletControllerEventConsumer I/F method.

param
midletIsolateId isolate ID of the sending isolate
param
midletDisplayId ID of the sending Display


        assertEquals(currentIsolateId, midletIsolateId);
        assertEquals(displayId, midletDisplayId);
    
public voidhandleMIDletActiveNotifyEvent(int midletSuiteId, java.lang.String midletClassName)
Process a MIDlet active notification MIDletControllerEventConsumer I/F method. TBD: param midletProxy proxy with information about MIDlet

param
midletSuiteId ID of the MIDlet suite
param
midletClassName Class name of the MIDlet


        assertEquals(SUITE_ID, midletSuiteId);
        assertEquals(CLASS_NAME, midletClassName);
    
public voidhandleMIDletCreateNotifyEvent(int midletSuiteId, java.lang.String midletClassName, int midletIsolateId, int midletExternalAppId, java.lang.String midletDisplayName)
Process a MIDlet created notification. MIDletControllerEventConsumer I/F method.

param
midletSuiteId ID of the MIDlet suite
param
midletClassName Class name of the MIDlet
param
midletIsolateId isolate ID of the sending MIDlet
param
midletExternalAppId ID of given by an external application manager
param
midletDisplayName name to show the user


        assertEquals(SUITE_ID, midletSuiteId);
        assertEquals(CLASS_NAME, midletClassName);
        assertEquals(currentIsolateId, midletIsolateId);
        assertEquals(externalId, midletExternalAppId);
        assertEquals(DISPLAY_NAME, midletDisplayName);
    
public voidhandleMIDletDestroyNotifyEvent(int midletSuiteId, java.lang.String midletClassName)
Process a MIDlet destroyed event. MIDletControllerEventConsumer I/F method.

param
midletSuiteId ID of the MIDlet suite
param
midletClassName Class name of the MIDlet


        assertEquals(SUITE_ID, midletSuiteId);
        assertEquals(CLASS_NAME, midletClassName);
    
public voidhandleMIDletDestroyRequestEvent(int midletIsolateId, int midletDisplayId)
Process a MIDlet destroy request event. MIDletControllerEventConsumer I/F method.

param
midletIsolateId isolate ID of the sending Display
param
midletDisplayId ID of the sending Display


        assertEquals(currentIsolateId, midletIsolateId);
        assertEquals(displayId, midletDisplayId);
    
public voidhandleMIDletForegroundSelectEvent(int onlyFromLaunched)
Process a select foreground event by putting the foreground selector MIDlet in the foreground. MIDletControllerEventConsumer I/F method.

    
public voidhandleMIDletForegroundTransferEvent(int originMIDletSuiteId, java.lang.String originMIDletClassName, int targetMIDletSuiteId, java.lang.String targetMIDletClassName)
Process an event to transition the foreground from a current display to a target MIDlet by ID and classname. If the source display does not currently own the foreground the request is ignored. If the target MIDlet is found in the active list then it it set as the foreground. If not found, then it should be added as the next display to get the foreground (when it asks). MIDletControllerEventConsumer I/F method.

param
originMIDletSuiteId ID of MIDlet from which to take forefround ownership away,
param
originMIDletClassName Name of MIDlet from which to take forefround ownership away
param
targetMIDletSuiteId ID of MIDlet to give forefround ownership to,
param
targetMIDletClassName Name of MIDlet to give forefround ownership to


        assertEquals(SUITE_ID, originMIDletSuiteId);
        assertEquals(CLASS_NAME, originMIDletClassName);

        assertEquals(TARGET_SUITE_ID, targetMIDletSuiteId);
        assertEquals(TARGET_CLASS_NAME, targetMIDletClassName);
    
public voidhandleMIDletPauseNotifyEvent(int midletSuiteId, java.lang.String midletClassName)
Process a MIDlet paused notification. MIDletControllerEventConsumer I/F method. TBD: param midletProxy proxy with information about MIDlet

param
midletSuiteId ID of the MIDlet suite
param
midletClassName Class name of the MIDlet


        assertEquals(SUITE_ID, midletSuiteId);
        assertEquals(CLASS_NAME, midletClassName);
    
public voidhandleMIDletResumeRequestEvent(int midletSuiteId, java.lang.String midletClassName)
Processes a MIDLET_RESUME_REQUEST event. MIDletControllerEventConsumer I/F method.

param
midletSuiteId ID of the MIDlet suite
param
midletClassName Class name of the MIDlet


        assertEquals(SUITE_ID, midletSuiteId);
        assertEquals(CLASS_NAME, midletClassName);
    
public voidhandleMIDletRsPauseNotifyEvent(int midletSuiteId, java.lang.String midletClassName)
Handles notification event of MIDlet resources pause. MIDletControllerEventConsumer I/F method.

param
midletSuiteId ID of the MIDlet suite
param
midletClassName Class name of the MIDlet


        assertEquals(SUITE_ID, midletSuiteId);
        assertEquals(CLASS_NAME, midletClassName);
    
public voidhandleMIDletStartErrorEvent(int midletSuiteId, java.lang.String midletClassName, int midletExternalAppId, int error, java.lang.String details)
Process a MIDlet start error event. Notify from last to first added to allow the listener to remove itself without causing a missed notification. MIDletControllerEventConsumer I/F method.

param
midletSuiteId ID of the MIDlet suite
param
midletClassName Class name of the MIDlet
param
midletExternalAppId ID of given by an external application manager
param
error start error code
param
details start error details


        assertEquals(SUITE_ID, midletSuiteId);
        assertEquals(CLASS_NAME, midletClassName);
        assertEquals(externalId, midletExternalAppId);
        assertEquals(errorCode, error);
        assertEquals(ERROR_DETAILES, details);
    
public voidhandlePauseAllEvent()
Process a PAUSE_ALL_EVENT. MIDletControllerEventConsumer I/F method.

        assertTrue(true);
    
public voidhandleSetForegroundByNameRequestEvent(int midletSuiteId, java.lang.String midletClassName)
Processes SET_FOREGROUND_BY_NAME_REQUEST event.

Set specified MIDlet to foreground.

param
midletSuiteId MIDlet's suite ID
param
midletClassName MIDlet's class name


        assertEquals(SUITE_ID, midletSuiteId);
        assertEquals(CLASS_NAME, midletClassName);
    
public voidrunTests()
Runs all tests. If a test throw a NullPointerException, the most likely cause is that the listener has not registered with the event queue for that event type.


                                     
         
        token = getSecurityToken();

        setUp();

        declare("testMIDletStartErrorEvent");
        testMIDletStartErrorEvent();

        declare("testMIDletCreateNotifyEvent");
        testMIDletCreateNotifyEvent();

        declare("testMIDletActiveNotifyEvent");
        testMIDletActiveNotifyEvent();

        declare("testMIDletPauseNotifyEvent");
        testMIDletPauseNotifyEvent();

        declare("testMIDletDestroyNotifyEvent");
        testMIDletDestroyNotifyEvent();

        declare("testMIDletResumeRequest");
        testMIDletResumeRequest();

        declare("testMIDletDestroyRequestEvent");
        testMIDletDestroyRequestEvent();

        declare("testMIDletForegroundTransferEvent");
        testMIDletForegroundTransferEvent();

        declare("testDisplayCreateNotifyEvent");
        testDisplayCreateNotifyEvent();

        declare("testDisplayForegroundRequestEvent");
        testDisplayForegroundRequestEvent();

        declare("testDisplayBackgroundRequestEvent");
        testDisplayBackgroundRequestEvent();

        declare("testDisplayPreemptEvents");
        testDisplayPreemptEvents();

        tearDown();
    
voidsetUp()
Initializes the test fixture with random data, creates the stub event queue, and creates the MIDletControllerEventProducer under test.

        currentIsolateId = rand.nextInt();
        amsIsolateId = rand.nextInt();
        displayId = rand.nextInt();
        displayId2 = rand.nextInt();
        externalId = rand.nextInt();
        errorCode = rand.nextInt();

        queue = new ListenerTestEventQueue();
        producer = new MIDletControllerEventProducer(queue,
            amsIsolateId, currentIsolateId);
        listener = new MIDletControllerEventListener(queue, this);
    
voidtearDown()
Nulls out the stub event queue and the event producer.

        queue = null;
        producer = null;
    
voidtestDisplayBackgroundRequestEvent()
Tests sendDisplayBackgroundRequestEvent().

        producer.sendDisplayBackgroundRequestEvent(displayId);
    
voidtestDisplayCreateNotifyEvent()
Tests sendDisplayCreateNotifyEvent().

        producer.sendDisplayCreateNotifyEvent(displayId, CLASS_NAME);
    
voidtestDisplayForegroundRequestEvent()
Tests sendDisplayForegroundRequestEvent().

        producer.sendDisplayForegroundRequestEvent(displayId, true);
    
voidtestDisplayPreemptEvents()
Tests sendDisplayPreemptStartEvent() and sendDisplayPreemptStopEvent().

        producer.sendDisplayPreemptStartEvent(displayId);
        producer.sendDisplayPreemptStopEvent(displayId2);
    
voidtestMIDletActiveNotifyEvent()
Tests sendMIDletActiveNotifyEvent().

        producer.sendMIDletActiveNotifyEvent(SUITE_ID, CLASS_NAME);
    
voidtestMIDletCreateNotifyEvent()
Tests sendMIDletCreateNotifyEvent().

        producer.sendMIDletCreateNotifyEvent(SUITE_ID, CLASS_NAME,
                                             externalId, DISPLAY_NAME);
    
voidtestMIDletDestroyNotifyEvent()
Tests sendMIDletDestroyNotifyEvent().

        producer.sendMIDletDestroyNotifyEvent(SUITE_ID, CLASS_NAME);
    
voidtestMIDletDestroyRequestEvent()
Tests sendMIDletDestroyRequestEvent().

        producer.sendMIDletDestroyRequestEvent(displayId);
    
voidtestMIDletForegroundTransferEvent()
Tests sendMIDletForegroundTransferEvent().

        producer.sendMIDletForegroundTransferEvent(
            SUITE_ID, CLASS_NAME, TARGET_SUITE_ID, TARGET_CLASS_NAME);
    
voidtestMIDletPauseNotifyEvent()
Tests sendMIDletPauseNotifyEvent().

        producer.sendMIDletPauseNotifyEvent(SUITE_ID, CLASS_NAME);
    
voidtestMIDletResumeRequest()
Tests sendMIDletResumeRequest().

        producer.sendMIDletResumeRequest(SUITE_ID, CLASS_NAME);
    
voidtestMIDletStartErrorEvent()
Tests sendMIDletStartErrorEvent().

        producer.sendMIDletStartErrorEvent(SUITE_ID, CLASS_NAME, externalId,
                                           errorCode, ERROR_DETAILES);