FileDocCategorySizeDatePackage
TestSystemServiceRequest.javaAPI DocphoneME MR2 API (J2ME)4336Wed May 02 18:00:10 BST 2007com.sun.midp.services

TestSystemServiceRequest

public class TestSystemServiceRequest extends com.sun.midp.i3test.TestCase
Tests for system service requesting functionality

Fields Summary
public static final String
SERVICE_ID
Constructors Summary
Methods Summary
public voidrunTests()
Runs all tests.


        declare("testRemote");
        testRemote();

        declare("testLocal");
        testLocal();
    
voidtestLocal()

        SystemServiceManager serviceManager = new DummySystemServiceManager();
        DummySystemService service = new DummySystemService();
        serviceManager.registerService(service);

        SystemServiceRequestorLocal serviceRequestor = 
            new SystemServiceRequestorLocal(serviceManager);
        serviceRequestor.requestService(SERVICE_ID);
    
        assertTrue("Service requested", service.wasRequested);

    
voidtestRemote()


        SystemServiceManager serviceManager = new DummySystemServiceManager();
        DummySystemService service = new DummySystemService();
        serviceManager.registerService(service);

        SystemServiceRequestHandler requestHandler = 
            new SystemServiceRequestHandler(serviceManager);

        Isolate serviceIsolate = Isolate.currentIsolate();
        Isolate clientIsolate = new Isolate(
                "com.sun.midp.services.SystemServiceRequestIsolate", null);
        clientIsolate.start();

        IsolateSystemServiceRequestHandler isolateRequestHandler = 
            requestHandler.newIsolateRequestHandler(clientIsolate);

        Link namedPortalLink = Link.newLink(serviceIsolate, clientIsolate);
        Link[] clientLinks = { namedPortalLink };
        LinkPortal.setLinks(clientIsolate, clientLinks);
        NamedLinkPortal.sendLinks(namedPortalLink);

        requestHandler.handleIsolateRequests(isolateRequestHandler);

        clientIsolate.waitForExit();
        
        assertTrue("Service requested", service.wasRequested);