FileDocCategorySizeDatePackage
SipHeaderBaseTest.javaAPI DocphoneME MR2 API (J2ME)6430Wed May 02 18:00:40 BST 2007javax.microedition.sip

SipHeaderBaseTest

public abstract class SipHeaderBaseTest extends com.sun.midp.i3test.TestCase
This is a base class for all Test<HeaderName>Header classes.

Fields Summary
Constructors Summary
Methods Summary
protected SipHeadercreateSipHeader(java.lang.String headerName, java.lang.String headerParam)
Creates SipHeader with the specified name and parameter.

param
headerName header's name.
param
headerParam header's parameter.
return
SipHeader instance if successfully created, null otherwise.

        SipHeader sh;

        try {
           sh = new SipHeader(headerName, headerParam);
        } catch (java.lang.IllegalArgumentException e) {
            sh = null;
            fail("IllegalArgumentException: " + e);
        } catch (Exception e) {
            sh = null;
            fail(e + " was caught");
        }

        return sh;
    
protected booleanequalsIgnoreSpaces(java.lang.String str1, java.lang.String str2)
Compares two strings ignoring the spaces and tabs around delimeters. Comparision is case-insensitive.

param
str1 first string to compare.
param
str2 second string to compare.
return
true if the string are equal, false otherwise.

        String s1 = removeSpaces(str1);
        String s2 = removeSpaces(str2);

        // DEBUG: System.out.println(">>> s1 = '" + s1 + "'");
        // DEBUG: System.out.println(">>> s2 = '" + s2 + "'");
        
        return s1.equalsIgnoreCase(s2);
    
protected java.lang.StringremoveNewLine(java.lang.String str)
Cuts ending CRLF's if any.

param
str string to process.
return
the resulting string.

        int len = Separators.NEWLINE.length();
        
        // Remove CRLF
        while (str.endsWith(Separators.NEWLINE)) {
            str = str.substring(0, str.length() - len);
        }
        
        return str;
    
protected java.lang.StringremoveSpaces(java.lang.String str)
Remove spaces/tabs surrounding delimeters in the string.

param
str string to process.
return
the resulting string.

        String strResult = "";
        boolean delimeterOn = false;
        char ch;
        
        for (int i = 0; i < str.length(); i++) {
            ch = str.charAt(i);
            
            if (delimeterOn) {
                if ((ch == ' ") || (ch == '\t")) {
                    continue; // skip the space/tab
                }
                
                delimeterOn = false;
            }
                
            if (ch == ';" || ch == '/") {
                strResult = strResult.trim();
                delimeterOn = true;
            }
            
            strResult += ch;
        } // end for
        
        return strResult;
    
protected booleantestConstructorNegative(java.lang.String headerName, java.lang.String invalidParam)
Checks if an exception is thrown when attempting to create a header with invalid value.

param
headerName header's name.
param
invalidParam value that is invalid for this type of header.
return
true if the test was passed, false otherwise.

        SipHeader sh;
        boolean result;

        try {
           sh = new SipHeader(headerName, invalidParam);
           result = false;
           fail("Constructor: IAE was not thrown!");
        } catch (java.lang.IllegalArgumentException e) {
            result = true;
        } catch (Exception e) {
            result = false;
            fail(e + " was thrown instead of IAE.");
        }

        return result;
    
protected voidtestSetValue(java.lang.String headerName, java.lang.String headerParam)
Test for setValue() method of Header's subclasses.

param
headerName name of the header.
param
headerParam value and parameters of the header.

        SipHeader sh = createSipHeader(headerName, headerParam);

        if (sh == null) {
            return;
        }
        
        // Here the one common case is tested:
        // if setValue() argument does include header's parameters,
        // IllegalArgumentException must be generated.
        try {
            sh.setValue("test;param1=val1");
            fail("setValue(): IAE was not thrown!");
        } catch (IllegalArgumentException iae) {
            // ok: IAE was thrown
        } catch (Exception e) {
            fail("setValue(): " + e + " was thrown instead of IAE!");
        }
        
        assertTrue(true);
    
protected voidtestToString(java.lang.String headerName, java.lang.String headerParam)
Test for toString() method of Header's subclasses.

param
headerName name of the header.
param
headerParam value and parameters of the header.

        SipHeader sh = createSipHeader(headerName, headerParam);

        if (sh == null) {
            return;
        }
        
        String strHeader = sh.toString();
        
        // Skip CRLF
        strHeader = removeNewLine(strHeader);

        assertTrue("Invalid string representation: '" + strHeader + "'",
            equalsIgnoreSpaces(strHeader, headerName + ": " + headerParam));