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

TestServiceRequestProtocol

public class TestServiceRequestProtocol extends com.sun.midp.i3test.TestCase
Tests for the LinkPortal class.

Fields Summary
Constructors Summary
Methods Summary
public voidrunTests()
Runs all tests.

        declare("testActual");
        testActual();
    
voidtestActual()
Tests setting and getting of actual data.

        String serviceID = "Test service";
        Isolate is = Isolate.currentIsolate();

        Link reqC2SLink = Link.newLink(is, is);
        Link reqS2CLink = Link.newLink(is, is);
        SystemServiceConnectionLinks requestLinksAMS = 
            new SystemServiceConnectionLinks(reqS2CLink, reqC2SLink);
        SystemServiceConnectionLinks requestLinksClient = 
            new SystemServiceConnectionLinks(reqC2SLink, reqS2CLink);

        // precreated connection between service and client
        Link conSendLink = Link.newLink(is, is);
        Link conRecLink = Link.newLink(is, is);
        SystemServiceConnectionLinks links = 
            new SystemServiceConnectionLinks(conRecLink, conSendLink);

        // start listening for requests
        SystemServiceRequestListenerImpl l = 
            new SystemServiceRequestListenerImpl(serviceID, links);
        ServiceRequestHandlerThread sp = 
            new ServiceRequestHandlerThread(requestLinksAMS, l);

        // request service
        SystemServiceRequestProtocolClient protocol = 
            new SystemServiceRequestProtocolClient(requestLinksClient);
        LinkMessage emptyMsg = LinkMessage.newStringMessage("");
        reqC2SLink.send(emptyMsg);
        protocol.requestService(serviceID);

        // check that service request went without errors
        Object result = sp.await();
        assertTrue("links sent without error", result == null);
        assertTrue("links received without error", l.linksPassed == true);
        
        // check that connection returned as result of request 
        // is expected one
        SystemServiceConnectionLinks con = 
            protocol.getSystemServiceConnectionLinks();
        assertNotSame("link not same", 
                conSendLink, con.getSendLink());
        assertTrue("links equal", 
                conSendLink.equals(con.getSendLink()));
        assertNotSame("link not same", 
                conRecLink, con.getReceiveLink());
        assertTrue("links equal", 
                conRecLink.equals(con.getReceiveLink()));