Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package test.tck.factory;
  
  
  import  junit.framework.*;
  import test.tck.*;
  
  public class AddressFactoryTest extends FactoryTestHarness {
 
     public AddressFactoryTest() {
         super("AddressFactoryTest");
     }
 
     protected javax.sip.address.URI createTiURI(String uriString) {
         javax.sip.address.URI uri = null;
         try {
             uri = .createURI(uriString);
             assertTrue(uri != null);
         } catch (Exception ex) {
             throw new TiUnexpectedError(ex.getMessage());
         }
         return uri;
     }
 
     protected javax.sip.address.URI createRiURI(String uriString) {
         javax.sip.address.URI uri = null;
         try {
             uri = .createURI(uriString);
         } catch (Exception ex) {
             throw new TckInternalError(ex.getMessage());
         }
         return uri;
     }
 
     protected javax.sip.address.SipURI createTiSipURI(
         String name,
         String address) {
         SipURI sipUri = null;
         try {
             sipUri = .createSipURI(nameaddress);
             assertNotNull(sipUri);
         } catch (Exception ex) {
             ex.printStackTrace();
             throw new TiUnexpectedError(ex.getMessage());
         }
         return sipUri;
     }
 
     protected javax.sip.address.SipURI createRiSipURI(
         String name,
         String address) {
         SipURI sipUri = null;
         try {
             sipUri = .createSipURI(nameaddress);
         } catch (Exception ex) {
             throw new TiUnexpectedError(ex.getMessage());
         }
         return sipUri;
     }
 
     protected javax.sip.address.TelURL createTiTelURL(String phoneNumber) {
         TelURL telUrl = null;
         try {
             telUrl = .createTelURL(phoneNumber);
         } catch (Exception ex) {
             throw new TiUnexpectedError(ex.getMessage());
         }
         return telUrl;
     }
 
         TelURL tiTelURL) {
         TelURL telUrl = null;
         try {
             // The API has a bug here - there is no way to retrieve the
             // phone-context parameter. This will be fixed in the next release.
             //int start = tiTelURL.toString().indexOf(':');
             //String phoneNumber = tiTelURL.toString().substring(start+1).trim();
             // String phoneNumber = tiTelURL.getPhoneContext();// JvB: wrong
             String phoneNumber = tiTelURL.getPhoneNumber();
             telUrl = .createTelURL(phoneNumber);
             telUrl.setGlobal(tiTelURL.isGlobal());
             // JvB: set to 'null' should remove it, fixed in impl
             telUrl.setPhoneContexttiTelURL.getPhoneContext() );
         } catch (Exception ex) {
             ex.printStackTrace();
             throw new TiUnexpectedError(ex.getMessage());
         }
         return telUrl;
     }
 
     protected javax.sip.address.TelURL createRiTelURL(String phoneNumber) {
         TelURL telUrl = null;
         try {
             telUrl = .createTelURL(phoneNumber);
         } catch (Exception ex) {
             throw new TckInternalError(ex.getMessage());
         }
        return telUrl;
    }
    protected javax.sip.address.Address createAddress(String address) {
        javax.sip.address.Address addr = null;
        try {
            addr = .createAddress(address);
            assertTrue(addr != null);
        } catch (Exception ex) {
            throw new TiUnexpectedError(ex.getMessage());
        }
        return addr;
    }
        javax.sip.address.URI uri) {
        javax.sip.address.Address addr = null;
        try {
            ..println("Uri = " + uri);
            addr = .createAddress(uri);
            ..println("addr = " + addr);
            ..println("createAddress returns " + .createAddress(uri.toString()));
            assertTrue(
                addr.equals(.createAddress(uri.toString())));
        } catch (Exception ex) {
            throw new TiUnexpectedError(ex.getMessage());
        }
        return addr;
    }
        javax.sip.address.URI uri) {
        javax.sip.address.Address addr = null;
        try {
            addr = .createAddress(uri);
        } catch (Exception ex) {
            throw new TckInternalError(ex.getMessage());
        }
        return addr;
    }
    protected javax.sip.address.Address createRiAddress(String address) {
        javax.sip.address.Address addr = null;
        try {
            addr = .createAddress(address);
            assertTrue(addr != null);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new TckInternalError(ex.getMessage());
        }
        return addr;
    }
        Address tiAddress)
        throws TiUnexpectedError {
        try {
            return .createAddress(tiAddress.toString());
        } catch (Exception ex) {
            throw new TiUnexpectedError(ex.getMessage());
        }
    }
    public void testStar() {
        try {
            Address star = .createAddress"*" );
            assertTruestar.isWildcard() );
            assertTruestar.getURI().isSipURI() );
            assertEquals"*", ((SipURIstar.getURI()).getUser() );
        } catch (ParseException pe) {
            pe.printStackTrace();
            failpe.getMessage() );
        }
    }
    public void testAddressFactory() {
        try {
            for (int i = 0; i < .i++) {
                javax.sip.address.URI uri = this.createTiURI([i]);
                assertNotNull(uri);
                javax.sip.address.Address tiAddress = this.createAddress(uri);
                assertNotNull(tiAddress);
                javax.sip.address.URI riUri = this.createRiURI([i]);
                javax.sip.address.Address riAddress =
                    this.createRiAddress(riUri);
                tiAddress = this.createRiAddress(tiAddress.toString());
                assertEqualsriAddress,
                        this.createRiAddressFromTiAddress(tiAddress) );
            }
            for (int i = 0; i < .i++) {
                javax.sip.address.SipURI tiSipURI;
                javax.sip.address.SipURI riSipURI;
                tiSipURI = this.createTiSipURI(null[i]);
                assertTrue(tiSipURI != null);
                assertTrue(tiSipURI.isSipURI());
                assertTrue(!tiSipURI.isSecure());
                assertTrue(
                    (
                        (SipURI.createURI(
                            "sip:" + [i])).equals(
                        tiSipURI));
                riSipURI = this.createRiSipURI(null[i]);
                javax.sip.address.Address tiAddress =
                    this.createAddress(tiSipURI);
                assertTrue(tiAddress != null);
                javax.sip.address.Address riAddress =
                    this.createRiAddress(riSipURI);
                assertTrue(
                    riAddress.equals(
                        this.createRiAddressFromTiAddress(tiAddress)));
                tiSipURI = this.createTiSipURI("jaintck"[i]);
                assertTrue(tiSipURI != null);
                assertTrue(tiSipURI.isSipURI());
                assertTrue(!tiSipURI.isSecure());
                assertTrue(
                    (
                        (SipURI.createURI(
                            "sip:jaintck@" + [i])).equals(
                        tiSipURI));
                tiAddress = this.createAddress(tiSipURI);
                assertTrue(tiAddress != null);
                riSipURI = this.createRiSipURI("jaintck"[i]);
                riAddress = this.createRiAddress(riSipURI);
                assertTrue(
                    riAddress.equals(
                        this.createRiAddressFromTiAddress(tiAddress)));
            }
            for (int i = 0; i < .i++) {
                javax.sip.address.TelURL tiTelUrl =
                    this.createTiTelURL([i]);
                assertTrue(tiTelUrl != null);
                javax.sip.address.TelURL riTelUrl =
                    this.createRiTelURL([i]);
                ..println"TI:" + tiTelUrl );
                ..println"RI:" + riTelUrl );
                assertEquals(
                    riTelUrlcreateRiTelURLFromTiTelURL(tiTelUrl) );
            }
            for (int i = 0; i < .i++) {
                javax.sip.address.TelURL telUrl =
                    (TelURLthis.createTiURI([i]);
                assertTrue(telUrl != null);
                    int start = telUrl.toString().indexOf(':');
                    String phone = telUrl.toString().substring(start+1).trim();
                javax.sip.address.TelURL tiTelUrl = this.createTiTelURL(phone);
                tiTelUrl.setGlobal(telUrl.isGlobal());
                assertTrue(telUrl.equals(tiTelUrl));
            }
        } catch (Exception ex) {
            throw new TiUnexpectedError(ex.getMessage());
        } finally {
            logTestCompleted("testAddressFactory()");
        }
    }
    public void testTelURL() throws Exception {
        // JvB: This weird-looking tel: URL is actually valid, syntactically speaking
        URI telURL = .createURI"tel:0123456789ABCDEF#*-.();isub=/:-_.!~*'();phone-context=+123-.();-=[]/:" );
        assertTruetelURL instanceof TelURL );
        TelURL t = (TelURLtelURL;
        assertEquals"0123456789ABCDEF#*-.()"t.getPhoneNumber() );
        assertEquals"+123-.()"t.getPhoneContext() );
        assertEquals"/:-_.!~*'()"t.getIsdnSubAddress() );
        assertEquals"[]/:"t.getParameter("-") );
    }
    public void setUp() {
    }
    public static Test suite() {
        return new TestSuite(AddressFactoryTest.class);
    }
    public static void main(String[] args) {
        junit.textui.TestRunner.run(AddressFactoryTest.class);
    }
New to GrepCode? Check out our FAQ X