コード例 #1
0
  /*
  public void testReceiveActivities() throws Exception
  {
  	setUpAndStart();

  	protocol.resetEvents();

  	// request timed out
  	protocol.mockErrorReceived(ResponseListener.REQUEST_TIMED_OUT, ServiceObject.ACTIVITY);

  	Assert.assertEquals("Protocol", new Event[]	{
  			new Event(Event.Context.TEST, MockCommunicationManager.SEND_REQUEST, ServerRequest.GET + ":" + ServerRequest.ACTIVITIES)
  		}, protocol.getEvents());

  	// receive activities
  	ServiceObject[] serviceObjects = new ServiceObject[3];
  	{
  		Hashtable ht = new Hashtable();

  		Vector flags = new Vector();
  		flags.addElement("status");

  		Hashtable moreinfo = new Hashtable();
  		moreinfo.put("network", "facebook");

  		ht.put("activityid", new Long(301));
  		ht.put("flaglist", flags);
  		ht.put("type", "contact_received_status_update");
  		ht.put("title", "Cup of tea");
  		ht.put("description", "Having a nice cuppa.");
  		ht.put("time", new Long(123456));
  		//ht.put("store", "facebook");
  		ht.put("moreinfo", moreinfo);
  		serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
  	}
  	{
  		Hashtable ht = new Hashtable();

  		Vector flags = new Vector();
  		flags.addElement("timeline");

  		ht.put("activityid", new Long(302));
  		ht.put("flaglist", flags);
  		ht.put("type", "contact_received_status_update");
  		ht.put("title", "Feet");
  		ht.put("description", "Putting my feet up.");
  		ht.put("time", new Long(1234));

  		serviceObjects[1] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
  	}
  	{
  		Hashtable ht = new Hashtable();

  		Vector flags = new Vector();
  		flags.addElement("timeline");
  		flags.addElement("status");

  		ht.put("activityid", new Long(303));
  		ht.put("flaglist", flags);
  		ht.put("type", "contact_received_status_update");
  		ht.put("title", "Pipe");
  		ht.put("description", "Lighting a pipe.");
  		ht.put("time", new Long(12345));

  		serviceObjects[2] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
  	}
  	protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY);

  	// display friends stream
  	Assert.assertEquals("Listener", new Event[] {
  			new Event(Event.Context.APP, Event.App.START, null),
  			new Event(Event.Context.CONTACTS, Event.Contacts.REFRESH_LIST, null),
  			new Event(Event.Context.APP, Event.App.READY, null),
  			new Event(Event.Context.ACTIVITY, Event.Activities.LIFE_DRIVE_CHANGED, new Integer(2)),
  			new Event(Event.Context.ACTIVITY, Event.Activities.FRIENDS_STREAM_CHANGED, new Integer(2))
  	}, getEvents());

  	ListSelection ls = model.getFriendsStream(0, 20);
  	{
  		Activity activity = (Activity) ls.getEntries()[0];
  		Assert.assertEquals(301, activity.getId());
  		Assert.assertEquals(Activity.TYPE_CONTACT_RECEIVED_STATUS_UPDATE, activity.getType());
  		Assert.assertEquals(EXTERNAL_NETWORKS[1], activity.getSource());
  		Assert.assertEquals("Cup of tea", activity.getTitle());
  		Assert.assertEquals("Having a nice cuppa.", activity.getDescription());
  		Assert.assertEquals(123456000, activity.getTime());
  	}
  	{
  		Activity activity = (Activity) ls.getEntries()[1];
  		Assert.assertEquals(303, activity.getId());
  	}

  	Assert.assertEquals(2, model.getLifeDrive(0, 20).getTotal());

  	// receive response to first request
  	serviceObjects = new ServiceObject[1];
  	{
  		Hashtable ht = new Hashtable();

  		Vector flags = new Vector();
  		flags.addElement("status");

  		ht.put("activityid", new Long(304));
  		ht.put("flaglist", flags);
  		ht.put("type", "contact_received_status_update");
  		ht.put("title", "Hello");
  		ht.put("description", "Don't ignore me!");
  		ht.put("time", new Long(123));

  		serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
  	}
  	protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY);

  	Assert.assertEquals("Listener", new Event[] {
  			new Event(Event.Context.APP, Event.App.START, null),
  			new Event(Event.Context.CONTACTS, Event.Contacts.REFRESH_LIST, null),
  			new Event(Event.Context.APP, Event.App.READY, null),
  			new Event(Event.Context.ACTIVITY, Event.Activities.LIFE_DRIVE_CHANGED, new Integer(2)),
  			new Event(Event.Context.ACTIVITY, Event.Activities.FRIENDS_STREAM_CHANGED, new Integer(2))
  	}, getEvents());

  	Assert.assertEquals(2, model.getLifeDrive(0, 20).getTotal());
  	Assert.assertEquals(2, model.getFriendsStream(0, 20).getTotal());

  	model.exit(false);
  }
  */
  public void testReceiveMoreThan50Activities() throws Exception {
    setUpAndStart();

    // receive activities
    ServiceObject[] serviceObjects = new ServiceObject[71];
    for (int i = 0; i < serviceObjects.length; i++) {
      Hashtable ht = new Hashtable();

      Vector flags = new Vector();
      flags.addElement("status");

      ht.put("activityid", new Long(i));
      ht.put("flaglist", flags);
      ht.put("type", TYPES[i]);
      ht.put("title", "Title");
      ht.put("description", "Description");
      ht.put("time", new Long(i));

      serviceObjects[i] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
    }
    protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY);

    // only 50 most recent are returned (message_email_received is discarded)
    ListSelection ls = model.getFriendsStream(0, 60);

    Assert.assertEquals(50, ls.getTotal());
    {
      Activity activity = (Activity) ls.getEntries()[0];
      Assert.assertEquals(70, activity.getId());
    }
    {
      Activity activity = (Activity) ls.getEntries()[49];
      Assert.assertEquals(20, activity.getId());
    }

    model.exit(false);
  }
コード例 #2
0
  public void testReceiveUpdatedFriendStream() throws Exception {
    setUpAndStart();

    protocol.resetEvents();

    // receive activities
    ServiceObject[] serviceObjects = new ServiceObject[2];
    {
      Hashtable ht = new Hashtable();

      Vector flags = new Vector();
      flags.addElement("status");

      ht.put("activityid", new Long(301));
      ht.put("flaglist", flags);
      ht.put("type", "contact_received_status_update");
      ht.put("title", "1");
      ht.put("description", "No Change.");
      ht.put("time", new Long(12003));

      serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
    }
    {
      Hashtable ht = new Hashtable();

      Vector flags = new Vector();
      flags.addElement("status");

      ht.put("activityid", new Long(302));
      ht.put("flaglist", flags);
      ht.put("type", "contact_received_status_update");
      ht.put("title", "2a");
      ht.put("description", "Before change.");
      ht.put("time", new Long(12002));

      serviceObjects[1] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
    }
    protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY);

    // receive notification
    protocol.mockPushReceived(new APIEvent(APIEvent.STATUS_CHANGE));

    Assert.assertEquals(
        "Protocol",
        new Event[] {
          new Event(
              Event.Context.TEST,
              MockCommunicationManager.SEND_REQUEST,
              ServerRequest.GET + ":" + ServerRequest.ACTIVITIES)
        },
        protocol.getEvents());

    // receive new and updated activities
    serviceObjects = new ServiceObject[2];
    {
      Hashtable ht = new Hashtable();

      Vector flags = new Vector();
      flags.addElement("status");

      ht.put("activityid", new Long(302));
      ht.put("flaglist", flags);
      ht.put("type", "contact_received_status_update");
      ht.put("title", "2b");
      ht.put("description", "After change.");
      ht.put("time", new Long(12002));

      serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
    }
    {
      Hashtable ht = new Hashtable();

      Vector flags = new Vector();
      flags.addElement("status");

      ht.put("activityid", new Long(303));
      ht.put("flaglist", flags);
      ht.put("type", "contact_received_status_update");
      ht.put("title", "3");
      ht.put("description", "Added.");
      ht.put("time", new Long(12001));

      serviceObjects[1] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
    }
    protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY);

    // display life drive
    Assert.assertEquals(
        "Listener",
        new Event[] {
          new Event(Event.Context.APP, Event.App.START, null),
          new Event(Event.Context.CONTACTS, Event.Contacts.REFRESH_LIST, null),
          new Event(Event.Context.APP, Event.App.READY, null),
          new Event(Event.Context.CHAT, Event.Chat.READY_FOR_INCOMING_MESSAGES, null),
          new Event(Event.Context.ACTIVITY, Event.Activities.STATUS_STREAM_CHANGED, null),
          new Event(Event.Context.ACTIVITY, Event.Activities.STATUS_STREAM_CHANGED, null)
        },
        getEvents());

    ListSelection ls = model.getFriendsStream(0, 20);
    {
      Activity activity = (Activity) ls.getEntries()[0];
      Assert.assertEquals(301, activity.getId());
    }
    {
      Activity activity = (Activity) ls.getEntries()[1];
      Assert.assertEquals(302, activity.getId());
      Assert.assertEquals("2b", activity.getTitle());
      Assert.assertEquals("After change.", activity.getDescription());
    }
    {
      Activity activity = (Activity) ls.getEntries()[2];
      Assert.assertEquals(303, activity.getId());
    }

    model.exit(false);
  }
コード例 #3
0
  public void testReceiveActivitiesWithUnknownContacts() throws Exception {
    setUpAndStart();

    protocol.resetEvents();

    // receive activities
    ServiceObject[] serviceObjects = new ServiceObject[2];
    {
      Vector flags = new Vector();
      flags.addElement("status");

      Hashtable contact = new Hashtable();
      contact.put("contactid", new Long(70001));

      Vector contactList = new Vector();
      contactList.addElement(contact);

      Hashtable ht = new Hashtable();
      ht.put("activityid", new Long(301));
      ht.put("flaglist", flags);
      ht.put("type", "contact_received_status_update");
      ht.put("title", "Hi!");
      ht.put("description", "You know me");
      ht.put("time", new Long(123456));
      ht.put("contactlist", contactList);

      serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
    }
    {
      Vector flags = new Vector();
      flags.addElement("status");

      Hashtable contact = new Hashtable();
      contact.put("contactid", new Long(70002));

      Vector contactList = new Vector();
      contactList.addElement(contact);

      Hashtable ht = new Hashtable();
      ht.put("activityid", new Long(302));
      ht.put("flaglist", flags);
      ht.put("type", "contact_received_status_update");
      ht.put("title", "Hi!");
      ht.put("description", "You don't know me");
      ht.put("time", new Long(123456));
      ht.put("contactlist", contactList);

      serviceObjects[1] = new com.zyb.nowplus.data.protocol.types.Activity(ht);
    }

    protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY);

    // only one is displayed
    ListSelection ls = model.getFriendsStream(0, 60);

    Assert.assertEquals(1, ls.getTotal());
    {
      Activity activity = (Activity) ls.getEntries()[0];
      Assert.assertEquals(301, activity.getId());
    }

    // receive new contacts
    Vector detailList = new Vector();
    {
      Hashtable ht = new Hashtable();
      ht.put("key", "vcard.nickname");
      ht.put("val", "lazy.friend");
      detailList.addElement(ht);
    }
    {
      Hashtable ht = new Hashtable();
      ht.put("key", "vcard.name");
      ht.put("val", "Friend;Lazy;");
      detailList.addElement(ht);
    }

    Hashtable ht = new Hashtable();
    ht.put("contactid", new Long(70002));
    ht.put("detaillist", detailList);

    ContactChanges serviceObject = new ContactChanges(ht);
    serviceObject.setCurrentServerRevision(34);

    protocol.mockItemsReceived(
        1, new ServiceObject[] {serviceObject}, ServiceObject.CONTACT_CHANGES);

    // check activities are requested again
    Assert.assertEquals(
        "Protocol",
        new Event[] {
          new Event(
              Event.Context.TEST,
              MockCommunicationManager.SEND_REQUEST,
              ServerRequest.GET + ":" + ServerRequest.ACTIVITIES)
        },
        protocol.getEvents());

    model.exit(false);
  }