Package org.cafesip.sipunit

Examples of org.cafesip.sipunit.RegisterSession


     * </pre>
   */
  public void testSubscription()
  {
    // Ensure Alice is not registered
    RegisterSession registerSession = new RegisterSession(getAlicePhone());
    registerSession.register(null, 0);
   
    SubscribeSession session = new SubscribeSession(getAlicePhone(), "reg");
    Request subscribe = session.newInitialSubscribe(100, getAliceUri()); // 1
    session.sendRequest(subscribe, Response.OK); // 2
   
    ServerTransaction tx = session.waitForNotify();
    Request notify = tx.getRequest(); // 3
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx); // 4
    SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertBetween(95, 100, subState.getExpires());
    assertEquals("reg", ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Reginfo regInfo = getRegInfo(notify);
    int version = regInfo.getVersion().intValue();
    Registration registration = regInfo.getRegistrationArray(0);
    assertEquals(State.INIT, registration.getState());
    assertEquals(getAliceUri(), registration.getAor());
    assertEquals(0, registration.getContactArray().length);
   
    registerSession.register(null, 1800); // 5 and 6
   
    tx = session.waitForNotify();
    notify = tx.getRequest(); // 7
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx); // 8
    regInfo = getRegInfo(notify);
    registration = regInfo.getRegistrationArray(0);
    assertEquals(1, registration.getContactArray().length);
    assertEquals(version + 1, regInfo.getVersion().intValue());
    assertEquals(State.ACTIVE, registration.getState());
    Contact contact = registration.getContactArray(0);
    assertBetween(1795, 1800, contact.getExpires().intValue());
    assertEquals(Event.REGISTERED, contact.getEvent());
   
    registerSession.register(null, 0); // 9 and  10
    tx = session.waitForNotify();
    notify = tx.getRequest(); // 11
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx); // 12
    regInfo = getRegInfo(notify);
View Full Code Here


 
  @SuppressWarnings("unchecked")
  public void testSimpleRegister() throws Exception
  {
    RegisterSession session = new RegisterSession(getAlicePhone());
    Request request = session.createRegister(null, 1800);
    Response response =
      session.sendRegistrationMessage(request, Response.OK);
    ListIterator<ContactHeader> contacts = response.getHeaders(ContactHeader.NAME);
    ContactHeader contact = contacts.next();
    assertBetween(1795, 1800, contact.getExpires());
    assertEquals(getAlicePhone().getContactInfo().getContactHeader().getAddress(), contact.getAddress());
    assertFalse(contacts.hasNext());
   

        request = session.createRegister(null, 0);
    response =   session.sendRegistrationMessage(request, Response.OK);
    contacts = response.getHeaders(ContactHeader.NAME);
    assertFalse(contacts.hasNext());
  }
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  public void testMultipleContacts() throws Exception
  {
    RegisterSession session =  new RegisterSession(getAlicePhone());
    Request request = session.createRegister(null, 1800);
    ContactHeader contact2 = newContact("<sip:localhost>");
    contact2.setExpires(1500);
    request.addHeader(contact2);
    Response response =
      session.sendRegistrationMessage(request, Response.OK);
    ListIterator<ContactHeader> contacts = response.getHeaders(ContactHeader.NAME);
    while (contacts.hasNext()) {
      ContactHeader contact = (ContactHeader) contacts.next();
      if (contact.getExpires() > 1795 && contact.getExpires() <= 1800)
        assertEquals(getAlicePhone().getContactInfo().getContactHeader().getAddress(), contact.getAddress());
      else
      {
        assertBetween(contact2.getExpires() -5, contact2.getExpires(), contact.getExpires());
        assertEquals(contact2.getAddress(), contact.getAddress())
      }
    }
   
        request = session.createRegister(contact2.getAddress().toString(), 0);
    response =   session.sendRegistrationMessage(request, Response.OK);
    contacts = response.getHeaders(ContactHeader.NAME);
    ContactHeader contact = contacts.next();
    assertBetween(1780, 1800, contact.getExpires());
    assertEquals(getAlicePhone().getContactInfo().getContactHeader().getAddress(), contact.getAddress());
    assertFalse(contacts.hasNext());
View Full Code Here

    assertFalse(contacts.hasNext());
  }
 
  public void testWilcard() throws Exception
  {
    RegisterSession session =  new RegisterSession(getAlicePhone());
    Request request = session.createRegister(null, 1800);
    ContactHeader contact2 = newContact("<sip:localhost>");
    contact2.setExpires(1500);
    request.addHeader(contact2);
    Response response =
      session.sendRegistrationMessage(request, Response.OK);
   
        request = session.createRegister("*", 0);
    response =   session.sendRegistrationMessage(request, Response.OK);
    assertFalse(response.getHeaders(ContactHeader.NAME).hasNext());
  }
View Full Code Here

    response =   session.sendRegistrationMessage(request, Response.OK);
    assertFalse(response.getHeaders(ContactHeader.NAME).hasNext());
  }
   
  public void testLowerCSeq() throws Exception {
    RegisterSession session =  new RegisterSession(getAlicePhone());
    session.register(1800);
   
    Request request = session.createRegister(null, 0);
    CSeqHeader cseq = (CSeqHeader) request.getHeader(CSeqHeader.NAME);
    cseq.setSeqNumber(cseq.getSeqNumber() - 2);
    Response response = session.sendRegistrationMessage(request, Response.SERVER_INTERNAL_ERROR);
    assertEquals("Lower CSeq", response.getReasonPhrase());
  }
View Full Code Here

    assertEquals("Lower CSeq", response.getReasonPhrase());
  }
 
 
  public void testInvalidWilcard() throws Exception
    RegisterSession session =  new RegisterSession(getAlicePhone());
    Request request = session.createRegister("*", 1800);
    Response response =
      session.sendRegistrationMessage(request, Response.BAD_REQUEST);
    assertEquals("Invalid wildcard", response.getReasonPhrase());
  }
View Full Code Here

      session.sendRegistrationMessage(request, Response.BAD_REQUEST);
    assertEquals("Invalid wildcard", response.getReasonPhrase());
  }
 
  public void testInvalidWilcard2() throws Exception
    RegisterSession session =  new RegisterSession(getAlicePhone());
    Request request = session.createRegister(null, 0);
    ContactHeader contact = __headerFactory.createContactHeader();
    contact.setWildCard();
    request.addHeader(contact);
    Response response =
      session.sendRegistrationMessage(request, Response.BAD_REQUEST);
    assertEquals("Invalid wildcard", response.getReasonPhrase());
  }
View Full Code Here

      session.sendRegistrationMessage(request, Response.BAD_REQUEST);
    assertEquals("Invalid wildcard", response.getReasonPhrase());
  }
 
  public void testMinExpires() throws Exception
    RegisterSession session =  new RegisterSession(getAlicePhone());
    Request request = session.createRegister(null, 2);
    Response response = session.sendRegistrationMessage(request, Response.INTERVAL_TOO_BRIEF);
    MinExpiresHeader minExpiresHeader = (MinExpiresHeader) response.getHeader(MinExpiresHeader.NAME);
        assertNotNull(minExpiresHeader);
  }
View Full Code Here

        assertNotNull(minExpiresHeader);
  }
 

  public void testRequires() throws Exception
    RegisterSession session =  new RegisterSession(getAlicePhone());
    Request request = session.createRegister(null, 1800);
    request.addHeader(__headerFactory.createRequireHeader("ext1"));
    request.addHeader(__headerFactory.createRequireHeader("ext2"));
    Response response =
      session.sendRegistrationMessage(request, Response.BAD_EXTENSION);

    assertHeaderContains(response, UnsupportedHeader.NAME, "ext1");
    assertHeaderContains(response, UnsupportedHeader.NAME, "ext2");

  }
View Full Code Here

    assertHeaderContains(response, UnsupportedHeader.NAME, "ext2");

  }
 
  public void testNoContact() throws Exception
    RegisterSession session =  new RegisterSession(getAlicePhone());
    session.register(1800);
    List<String> expectedContacts = new ArrayList<String>();
    expectedContacts.add(getAlicePhone().getContactInfo().getURI());
    sendRegisterNoContact(session, expectedContacts);
  }
View Full Code Here

TOP

Related Classes of org.cafesip.sipunit.RegisterSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.