FileDocCategorySizeDatePackage
TestPushRegistry.javaAPI DocphoneME MR2 API (J2ME)4096Wed May 02 18:00:14 BST 2007com.sun.midp.io.j2me.socket

TestPushRegistry

public class TestPushRegistry extends TestCase
Test of SocketConnection function that unblocks a pending read when the connection is closed.

Fields Summary
boolean
exceptionThrownAsExpected
String[]
negativeFilters
String[]
positiveFilters
String
connection
Constructors Summary
Methods Summary
public voidrunTests()
Start PushRegistry tests for socket connection

        declare("Test PushRegistry for socket connection");

        testPushFilters();
    
voidtestPushFilters()


      
        ProtocolPushImpl pushImpl = null;
        int i = 0;

        exceptionThrownAsExpected = true;

        try {
            pushImpl = (ProtocolPushImpl)ProtocolPush.getInstance(connection);
        }
        catch (Exception cce) {
            exceptionThrownAsExpected = false;
        }

        if (exceptionThrownAsExpected) {
            for (i = negativeFilters.length; --i >= 0 && exceptionThrownAsExpected; ) {
                exceptionThrownAsExpected = false;
                try {
                    pushImpl.checkRegistration(connection,
                                               "com.sun.midp.io.j2me.socket.TestPushRegistry.MyTestMIDlet",
                                               negativeFilters[i]);
                    System.err.println("failed with no exception at " + negativeFilters[i]);
                }
                catch (IllegalArgumentException iae) {
                    exceptionThrownAsExpected = true;
                }
                catch (Exception ex) {
                    System.err.println("failed with " + ex + " at " + negativeFilters[i]);
                }
            }
        }

        if (exceptionThrownAsExpected) {
            try {
                for (i = positiveFilters.length; --i >= 0 && exceptionThrownAsExpected; ) {
                    pushImpl.checkRegistration(connection,
                                               "com.sun.midp.io.j2me.socket.TestPushRegistry.MyTestMIDlet",
                                               positiveFilters[i]);
                }
            }
            catch (Exception ex) {
                System.err.println("failed with " + ex + " at " + positiveFilters[i]);
                exceptionThrownAsExpected = false;
            }
        }

        assertTrue("Verify PushRegistry for socket connection", exceptionThrownAsExpected);