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

TestSystemService

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

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


        declare("testRemote");
        testRemote();

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

        SystemServiceManager manager = SystemServiceManager.getInstance(token);
        SimpleSystemService service = new SimpleSystemService();
        manager.registerService(service);

        SystemServiceRequestor serviceRequestor = 
            SystemServiceRequestor.getInstance(token);

        SystemServiceConnection con = null;
        con = serviceRequestor.requestService(
                TestSystemService.SERVICE_ID);

        try {
            // receive string from service
            SystemServiceMessage msg = con.receive();
            String testString = msg.getDataInput().readUTF();

            // convert string to upper case and sent it back to service
            msg = SystemServiceMessage.newMessage();
            msg.getDataOutput().writeUTF(testString.toUpperCase());
            con.send(msg);
        } catch (Throwable t) {
            System.err.println("Exception: " + t);
        }

        manager.shutdown();

        assertTrue("Strings match", service.stringsMatch);
    
voidtestRemote()


        SystemServiceManager manager = SystemServiceManager.getInstance(token);
        SimpleSystemService service = new SimpleSystemService();
        manager.registerService(service);

        SystemServiceRequestHandler requestHandler = 
            new SystemServiceRequestHandler(manager);

        Isolate serviceIsolate = Isolate.currentIsolate();
        Isolate clientIsolate = new Isolate(
                "com.sun.midp.services.SystemServiceIsolate", 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();
        
        manager.shutdown();

        assertTrue("Strings match", service.stringsMatch);