Package org.cafesip.sipunit

Examples of org.cafesip.sipunit.SubscribeSession


  {
    // 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);
    registration = regInfo.getRegistrationArray(0);
    assertEquals(1, registration.getContactArray().length);
    assertEquals(version + 2, regInfo.getVersion().intValue());
    assertEquals(State.TERMINATED, registration.getState());
    contact = registration.getContactArray(0);
    assertEquals(0, contact.getExpires().intValue());
    assertEquals(Event.UNREGISTERED, contact.getEvent());
   
    subscribe = session.newSubsequentSubscribe(0); // 13
    session.sendRequest(subscribe, Response.OK); // 14
   
    tx = session.waitForNotify();
    notify = tx.getRequest(); // 15
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx); // 16
    subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.TERMINATED.toLowerCase(),
        subState.getState());
    regInfo = getRegInfo(notify);
    registration = regInfo.getRegistrationArray(0);
View Full Code Here


  public void testSubscription2()
  {
    getAlicePhone().register(null, 1500);
    assertLastOperationSuccess(getAlicePhone());
   
    SubscribeSession session = new SubscribeSession(getAlicePhone(), "reg");
    Request subscribe = session.newInitialSubscribe(100, getAliceUri());
    session.sendRequest(subscribe, Response.OK);
   
    ServerTransaction tx = session.waitForNotify();
    Request notify = tx.getRequest();
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx);
    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);
    Registration registration = regInfo.getRegistrationArray(0);
    assertEquals(0, regInfo.getVersion().intValue());
    assertEquals(State.ACTIVE, registration.getState());
    assertEquals(getAliceUri(), registration.getAor());
    assertEquals(1, registration.getContactArray().length);
   
   
    getAlicePhone().unregister(null, 2000);
    assertLastOperationSuccess(getAlicePhone());
    tx = session.waitForNotify();
    notify = tx.getRequest();
    session.sendResponse(Response.OK, tx);
    regInfo = getRegInfo(notify);
    registration = regInfo.getRegistrationArray(0);
    assertEquals(1, registration.getContactArray().length);
    assertEquals(1, regInfo.getVersion().intValue());
    assertEquals(State.TERMINATED, registration.getState());
    Contact contact = registration.getContactArray(0);
    assertEquals(0, contact.getExpires().intValue());
    assertEquals(Event.UNREGISTERED, contact.getEvent());
       
    subscribe = session.newSubsequentSubscribe(0);
    session.sendRequest(subscribe, Response.OK);
   
    tx = session.waitForNotify();
    notify = tx.getRequest();
    //System.out.println(notify);
    session.sendResponse(Response.OK, tx);
    subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.TERMINATED.toLowerCase(),
        subState.getState());
    regInfo = getRegInfo(notify);
    registration = regInfo.getRegistrationArray(0);
View Full Code Here

    }
  }
 
    public void testMinExpires() throws Exception
    {      
        SubscribeSession session = new SubscribeSession(getAlicePhone(), "reg");
        Request request = session.newInitialSubscribe(1, getAliceUri());
        Response response = session.sendRequest(request,SipResponse.INTERVAL_TOO_BRIEF);
        MinExpiresHeader minExpiresHeader = (MinExpiresHeader) response.getHeader(MinExpiresHeader.NAME);
        assertNotNull(minExpiresHeader);
    }
View Full Code Here

  {
    PublishSession publishSession = new PublishSession(getAlicePhone());
        Request publish = publishSession.newPublish(getClass().getResourceAsStream("publish1.xml"), 60); // 1
        publishSession.sendRequest(publish, SipResponse.OK); // 2
       
        SubscribeSession presenceSession = new SubscribeSession(getBobPhone(), "presence");
    Request subscribe = presenceSession.newInitialSubscribe(0, getAliceUri()); // 3
    presenceSession.sendRequest(subscribe, Response.OK); // 4

    ServerTransaction tx = presenceSession.waitForNotify(); // 5
    System.out.println("5:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 6
    Presence presence = getPresence(tx.getRequest());
    assertEquals(Basic.CLOSED, presence.getTupleArray()[0].getStatus().getBasic());
   
   
    SubscribeSession winfoSession = new SubscribeSession(getAlicePhone(), "presence.winfo"); // 7
    subscribe = winfoSession.newInitialSubscribe(60, getAliceUri());
    winfoSession.sendRequest(subscribe, Response.OK); // 8
   
    tx = winfoSession.waitForNotify(); // 9
    Request notify = tx.getRequest();
    System.out.println("9:\n" +notify);
    winfoSession.sendResponse(Response.OK, tx); // 10
    SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertEquals(WatcherInfoEventPackage.NAME, ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Watcherinfo watcherinfo = getWatcherinfo(notify);
    assertEquals(0, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    WatcherList watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getAliceUri(), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    Watcher watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.TIMEOUT, watcher.getEvent());
    assertEquals(getBobUri(), watcher.getStringValue());
    assertEquals(Status.WAITING, watcher.getStatus())
   
   
    HttpClient httpClient = new HttpClient();
    PutMethod put = new PutMethod(getHttpXcapUri() + ALICE_PRES_RULES_URI); // 11
   
    InputStream is = WatcherInfoTest.class.getResourceAsStream("/xcap-root/pres-rules/users/put/elementCondAliceBob.xml");
    RequestEntity entity = new InputStreamRequestEntity(is, "application/xcap-el+xml");
    put.setRequestEntity(entity);
   
    int result = httpClient.executeMethod(put);
    assertEquals(200, result); // 12
    put.releaseConnection();
   
    presenceSession = new SubscribeSession(getBobPhone(), "presence");
    subscribe = presenceSession.newInitialSubscribe(0, getAliceUri()); // 13
    presenceSession.sendRequest(subscribe, Response.OK); // 14

    tx = presenceSession.waitForNotify(); // 15
    System.out.println("15:\n" + tx.getRequest());
View Full Code Here

    }
  }
 
    public void testMinExpires() throws Exception
    {      
        SubscribeSession session = new SubscribeSession(getAlicePhone(), "presence.winfo");
        Request request = session.newInitialSubscribe(1, getAliceUri());
        Response response = session.sendRequest(request, SipResponse.INTERVAL_TOO_BRIEF);
        MinExpiresHeader minExpiresHeader = (MinExpiresHeader) response.getHeader(MinExpiresHeader.NAME);
        assertNotNull(minExpiresHeader);
    }
View Full Code Here

          |                   |<--------------------|
     * </pre>
   */
  public void testSubscription()
  {   
    SubscribeSession winfoSession = new SubscribeSession(getBobPhone(), "presence.winfo"); // 1
    Request subscribe = winfoSession.newInitialSubscribe(100, getBobUri());
    winfoSession.sendRequest(subscribe, Response.OK); // 2
   
    ServerTransaction tx = winfoSession.waitForNotify(); // 3
    Request notify = tx.getRequest();
    //System.out.println(notify);
    winfoSession.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(WatcherInfoEventPackage.NAME, ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Watcherinfo watcherinfo = getWatcherinfo(notify);
    assertEquals(0, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    WatcherList watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getBobUri(), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(0, watcherList.getWatcherArray().length);
   
   
    SubscribeSession presenceSession = new SubscribeSession(getAlicePhone(), "presence");
    subscribe = presenceSession.newInitialSubscribe(100, getBobUri()); // 5
    presenceSession.sendRequest(subscribe, Response.OK); // 6
   
    tx = winfoSession.waitForNotify(); // 7
    notify = tx.getRequest();
    //System.out.println(notify);
    winfoSession.sendResponse(Response.OK, tx); // 8
    watcherinfo = getWatcherinfo(notify);
    assertEquals(1, watcherinfo.getVersion().intValue());
    watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(1, watcherList.sizeOfWatcherArray());
    Watcher watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.SUBSCRIBE, watcher.getEvent());
    assertEquals(getAliceUri(), watcher.getStringValue());
    assertEquals(Status.ACTIVE, watcher.getStatus());
   
   
    tx = presenceSession.waitForNotify(); // 9
    presenceSession.sendResponse(Response.OK, tx); // 10
   
   
    subscribe = presenceSession.newSubsequentSubscribe(0); // 11
    presenceSession.sendRequest(subscribe, Response.OK); // 12
   
    tx = winfoSession.waitForNotify(); // 13
    notify = tx.getRequest();
    // System.out.println(notify);
    winfoSession.sendResponse(Response.OK, tx); // 14
    watcherinfo = getWatcherinfo(notify);
    assertEquals(2, watcherinfo.getVersion().intValue());
    watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(1, watcherList.sizeOfWatcherArray());
    watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.TIMEOUT, watcher.getEvent());
    assertEquals(getAliceUri(), watcher.getStringValue());
    assertEquals(Status.TERMINATED, watcher.getStatus());
   
    tx = presenceSession.waitForNotify(); // 15
    presenceSession.sendResponse(Response.OK, tx); // 16
   
    subscribe = winfoSession.newSubsequentSubscribe(0); // 17
    winfoSession.sendRequest(subscribe, Response.OK); //18
   
    tx = winfoSession.waitForNotify(); // 19
View Full Code Here

          |------------------>|                     |
     * </pre>
   */
  public void testSubscription2()
  {   
    SubscribeSession presenceSession = new SubscribeSession(getAlicePhone(), "presence");
    Request subscribe = presenceSession.newInitialSubscribe(100, getBobUri()); // 1
    presenceSession.sendRequest(subscribe, Response.OK); // 2

    ServerTransaction tx = presenceSession.waitForNotify(); // 3
    presenceSession.sendResponse(Response.OK, tx); // 4
   
    SubscribeSession winfoSession = new SubscribeSession(getBobPhone(), "presence.winfo"); // 5
    subscribe = winfoSession.newInitialSubscribe(0, getBobUri());
    winfoSession.sendRequest(subscribe, Response.OK); // 6
   
    tx = winfoSession.waitForNotify(); // 7
    Request notify = tx.getRequest();
    //System.out.println(notify);
    winfoSession.sendResponse(Response.OK, tx); // 8
    SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.TERMINATED.toLowerCase(), subState.getState().toLowerCase());
    assertEquals(WatcherInfoEventPackage.NAME, ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Watcherinfo watcherinfo = getWatcherinfo(notify);
    assertEquals(0, watcherinfo.getVersion().intValue());
View Full Code Here

  {
    PublishSession publishSession = new PublishSession(getBobPhone());
        Request publish = publishSession.newPublish(getClass().getResourceAsStream("publish1.xml"), 60); // 1
        publishSession.sendRequest(publish, SipResponse.OK); // 2
   
    SubscribeSession presenceSession = new SubscribeSession(getAlicePhone(), "presence");
    Request subscribe = presenceSession.newInitialSubscribe(100, getBobUri()); // 3
    presenceSession.sendRequest(subscribe, Response.OK); // 4

    ServerTransaction tx = presenceSession.waitForNotify(); // 5
    //System.out.println("3:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 6
    Presence presence = getPresence(tx.getRequest());
    assertEquals(Basic.OPEN, presence.getTupleArray()[0].getStatus().getBasic());
   
   
    SubscribeSession winfoSession = new SubscribeSession(getBobPhone(), "presence.winfo"); // 7
    subscribe = winfoSession.newInitialSubscribe(60, getBobUri());
    winfoSession.sendRequest(subscribe, Response.OK); // 8
   
    tx = winfoSession.waitForNotify(); // 9
    Request notify = tx.getRequest();
    //System.out.println(notify);
    winfoSession.sendResponse(Response.OK, tx); // 10
    SubscriptionStateHeader subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertEquals(WatcherInfoEventPackage.NAME, ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    Watcherinfo watcherinfo = getWatcherinfo(notify);
    assertEquals(0, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    WatcherList watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getBobUri(), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    Watcher watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.SUBSCRIBE, watcher.getEvent());
    assertEquals(getAliceUri(), watcher.getStringValue());
    assertEquals(Status.ACTIVE, watcher.getStatus());
   
   
    HttpClient httpClient = new HttpClient();
    PutMethod put = new PutMethod(getHttpXcapUri() + BOB_PRES_RULES_URI); // 11
   
    InputStream is = WatcherInfoTest.class.getResourceAsStream("/xcap-root/pres-rules/users/put/elementPoliteBlock.xml");
    RequestEntity entity = new InputStreamRequestEntity(is, "application/xcap-el+xml");
    put.setRequestEntity(entity);
   
    int result = httpClient.executeMethod(put);
    assertEquals(200, result); // 12
    put.releaseConnection();
   
    tx = presenceSession.waitForNotify(); // 13
    //System.out.println("11:\n" + tx.getRequest());
    presenceSession.sendResponse(Response.OK, tx); // 14
    presence = getPresence(tx.getRequest());
    assertEquals(Basic.CLOSED, presence.getTupleArray()[0].getStatus().getBasic());
   
    tx = winfoSession.waitForNotify(); // 15
    notify = tx.getRequest();
    winfoSession.sendResponse(Response.OK, tx); // 16
    System.out.println(notify);
    subState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
    assertEquals(SubscriptionStateHeader.ACTIVE.toLowerCase(), subState.getState().toLowerCase());
    assertEquals(WatcherInfoEventPackage.NAME, ((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType());
    watcherinfo = getWatcherinfo(notify);
    assertEquals(1, watcherinfo.getVersion().intValue());
    assertEquals(Watcherinfo.State.FULL, watcherinfo.getState());
    assertEquals(1, watcherinfo.getWatcherListArray().length);
    watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(getBobUri(), watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(1, watcherList.getWatcherArray().length);
    watcher = watcherList.getWatcherArray(0);
    assertEquals(Event.SUBSCRIBE, watcher.getEvent());
    assertEquals(getAliceUri(), watcher.getStringValue());
    assertEquals(Status.ACTIVE, watcher.getStatus());
     
   
    subscribe = winfoSession.newSubsequentSubscribe(0); // 17
    winfoSession.sendRequest(subscribe, Response.OK); // 18
       
    tx = winfoSession.waitForNotify(); // 19
    winfoSession.sendResponse(Response.OK, tx); // 20
   
   
    subscribe = presenceSession.newSubsequentSubscribe(0); // 21
    presenceSession.sendRequest(subscribe, Response.OK); // 22
       
View Full Code Here

    publishSession.sendRequest(publish, Response.OK); // 14
    }

    public void testMinExpires() throws Exception
    {      
        SubscribeSession session = new SubscribeSession(getAlicePhone(), "presence");
        Request request = session.newInitialSubscribe(1, getAliceUri());
        Response response = session.sendRequest(request, SipResponse.INTERVAL_TOO_BRIEF);
        MinExpiresHeader minExpiresHeader = (MinExpiresHeader) response.getHeader(MinExpiresHeader.NAME);
        assertNotNull(minExpiresHeader);
    }
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
  public void testBadEvent() throws Exception
    {      
        SubscribeSession session = new SubscribeSession(getAlicePhone(), "unknown");
        Request request = session.newInitialSubscribe(100, getAliceUri());
        Response response = session.sendRequest(request, SipResponse.BAD_EVENT);
        Iterator it = response.getHeaders(AllowEventsHeader.NAME);
        List<String> l = new ArrayList<String>();
        while (it.hasNext())
    {
      AllowEventsHeader allowEventsHeader = (AllowEventsHeader) it.next();
View Full Code Here

TOP

Related Classes of org.cafesip.sipunit.SubscribeSession

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.