FileDocCategorySizeDatePackage
TestCBSOpenClose.javaAPI DocphoneME MR2 API (J2ME)4491Wed May 02 18:00:32 BST 2007com.sun.midp.io.j2me.cbs

TestCBSOpenClose

public class TestCBSOpenClose extends com.sun.midp.i3test.TestCase implements Runnable
Tests if an CBS connection can simply be open and closed without sending or receiving any messages. This test also tries to find failures when closing a connection more than once (A valid case).

Fields Summary
private final String
TEST_NAME
The fully qualified name of this test.
private final String
CBS_CLIENT_DEVICE_ID
The device ID ("phone number") of the recipient.
private final int
CBS_CLIENT_PORT
The application ID of the recipient.
private final String
CBS_CLIENT_ADDRESS1
The CBS client address with a host name (Illegal).
private final String
CBS_CLIENT_ADDRESS2
The CBS client address without a host name (Legal).
private javax.wireless.messaging.MessageConnection
con
The CBS connection.
private boolean
passed
Test passed/failed flag.
Constructors Summary
Methods Summary
voidcleanUp()
Provide clean-up services, following the run of this test.

        closeConnection();
    
private voidcloseConnection()
Close the CBS connection.

        try {
            con.close();
        } catch (IOException ioe) {
            // Fail silently.
        } catch (Exception e) {
            // Fail silently.
        }
    
private voidcreateClientConnection(java.lang.String clientAddress)
Create and open an CBS connection.

param
clientAddress The CBS address of the client.


        con = (MessageConnection)Connector.open(clientAddress);
    
public voidrun()
Simply close the open connection. If successful, this test passes.


        try {

            closeConnection();

            /* 
             * Close connection again. This is allowed by the spec
             * and shouldn't cause any exceptions to be thrown.
             */
	    closeConnection();

            passed = true;
            assertTrue("This indicates we passed.", passed);

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    
public voidrunTests()
Main entry point.


        setUp();

        declare(TEST_NAME);

        run();

        cleanUp();
    
voidsetUp()
Set up the physical connection.



              
      

        // Try an illegal address first.
        try {
            createClientConnection(CBS_CLIENT_ADDRESS1);
        } catch (IllegalArgumentException iae) {
            // This is a good thing. Cannot have a host name in address.
        } catch (IOException ioe) {
            System.out.println(TEST_NAME + " set-up failed:");
            ioe.printStackTrace();
        }

        // Now try a legal address.
        try {
            createClientConnection(CBS_CLIENT_ADDRESS2);
        } catch (IOException ioe) {
            System.out.println(TEST_NAME + " set-up failed:");
            ioe.printStackTrace();
        }