summaryrefslogtreecommitdiffstats
path: root/test/com
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-07-04 21:17:12 (GMT)
committerNick Hudson <nick.hudson@isode.com>2015-07-22 14:24:27 (GMT)
commit1f2c3add9971e8636013c384938456388b04ed79 (patch)
tree82fb7665833f8ab40f0f4f33524c8ccebcefbcca /test/com
parenta6e8d22d0686d860df735082c151f71157567e06 (diff)
downloadstroke-1f2c3add9971e8636013c384938456388b04ed79.zip
stroke-1f2c3add9971e8636013c384938456388b04ed79.tar.bz2
Update Roster functionalities.
Updates RosterPushResponder, XMPPRoster, XMPPRosterController. Also adds XMPPRosterSignalHandler. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Adds tests for XMPPRosterController, XMPPRosterImpl. All tests passes. Change-Id: Iee3530510342ea5977022237aaa6dfbffa390408
Diffstat (limited to 'test/com')
-rw-r--r--test/com/isode/stroke/roster/XMPPRosterControllerTest.java356
-rw-r--r--test/com/isode/stroke/roster/XMPPRosterImplTest.java110
-rw-r--r--test/com/isode/stroke/roster/XMPPRosterSignalHandler.java110
3 files changed, 576 insertions, 0 deletions
diff --git a/test/com/isode/stroke/roster/XMPPRosterControllerTest.java b/test/com/isode/stroke/roster/XMPPRosterControllerTest.java
new file mode 100644
index 0000000..a3f03b2
--- /dev/null
+++ b/test/com/isode/stroke/roster/XMPPRosterControllerTest.java
@@ -0,0 +1,356 @@
+/*
+ * Copyright (c) 2010-2011 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.roster;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Before;
+import org.junit.Test;
+import com.isode.stroke.roster.XMPPRosterSignalHandler;
+import com.isode.stroke.roster.XMPPRosterController;
+import com.isode.stroke.roster.XMPPRosterImpl;
+import com.isode.stroke.roster.RosterMemoryStorage;
+import com.isode.stroke.elements.RosterItemPayload;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.RosterPayload;
+import com.isode.stroke.elements.IQ;
+import com.isode.stroke.client.DummyStanzaChannel;
+import com.isode.stroke.queries.IQRouter;
+import com.isode.stroke.jid.JID;
+import java.util.Collection;
+import java.util.ArrayList;
+
+public class XMPPRosterControllerTest {
+
+ private DummyStanzaChannel channel_;
+ private IQRouter router_;
+ private XMPPRosterImpl xmppRoster_;
+ private XMPPRosterSignalHandler handler_;
+ private RosterMemoryStorage rosterStorage_;
+ private JID jid1_;
+ private JID jid2_;
+ private JID jid3_;
+
+ @Before
+ public void setUp() {
+ channel_ = new DummyStanzaChannel();
+ router_ = new IQRouter(channel_);
+ router_.setJID(new JID("me@bla.com"));
+ xmppRoster_ = new XMPPRosterImpl();
+ handler_ = new XMPPRosterSignalHandler(xmppRoster_);
+ rosterStorage_ = new RosterMemoryStorage();
+ jid1_ = new JID("foo@bar.com");
+ jid2_ = new JID("alice@wonderland.lit");
+ jid3_ = new JID("jane@austen.lit");
+ }
+
+ private XMPPRosterController createController() {
+ return new XMPPRosterController(router_, xmppRoster_, rosterStorage_);
+ }
+
+ @Test
+ public void testGet_Response() {
+ XMPPRosterController testling = createController();
+
+ testling.requestRoster();
+ RosterPayload payload = new RosterPayload();
+ payload.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Both));
+ payload.addItem(new RosterItemPayload(jid2_, "Alice", RosterItemPayload.Subscription.Both));
+ channel_.onIQReceived.emit(IQ.createResult(new JID("foo@bar.com"), channel_.sentStanzas.get(0).getID(), payload));
+
+ assertEquals(2, handler_.getEventCount());
+ assertNotNull(xmppRoster_.getItem(jid1_));
+ assertNotNull(xmppRoster_.getItem(jid2_));
+ }
+
+ @Test
+ public void testGet_EmptyResponse() {
+ XMPPRosterController controller = new XMPPRosterController(router_, xmppRoster_, rosterStorage_);
+
+ controller.requestRoster();
+
+ channel_.onIQReceived.emit(IQ.createResult(new JID("baz@fum.com/dum"), channel_.sentStanzas.get(0).getID(), null));
+ }
+
+ @Test
+ public void testAdd() {
+ XMPPRosterController controller = new XMPPRosterController(router_, xmppRoster_, rosterStorage_);
+
+ RosterPayload payload = new RosterPayload();
+ payload.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Both));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "eou", payload));
+
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ assertEquals(0, xmppRoster_.getGroupsForJID(jid1_).size());
+ assertTrue(xmppRoster_.containsJID(jid1_));
+ assertEquals("Bob", xmppRoster_.getNameForJID(jid1_));
+ }
+
+ @Test
+ public void testGet_NoRosterInStorage() {
+ XMPPRosterController testling = createController();
+ testling.setUseVersioning(true);
+
+ testling.requestRoster();
+
+ RosterPayload roster = channel_.sentStanzas.get(0).getPayload(new RosterPayload());
+ assertNotNull(roster.getVersion());
+ assertEquals("", roster.getVersion());
+ }
+
+ @Test
+ public void testGet_NoVersionInStorage() {
+ XMPPRosterController testling = createController();
+ testling.setUseVersioning(true);
+ rosterStorage_.setRoster(new RosterPayload());
+
+ testling.requestRoster();
+
+ RosterPayload roster = channel_.sentStanzas.get(0).getPayload(new RosterPayload());
+ assertNotNull(roster.getVersion());
+ assertEquals("", roster.getVersion());
+ }
+
+ @Test
+ public void testGet_VersionInStorage() {
+ XMPPRosterController testling = createController();
+ testling.setUseVersioning(true);
+ RosterPayload payload = new RosterPayload();
+ payload.setVersion("foover");
+ rosterStorage_.setRoster(payload);
+
+ testling.requestRoster();
+
+ RosterPayload roster = channel_.sentStanzas.get(0).getPayload(new RosterPayload());
+ assertNotNull(roster.getVersion());
+ assertEquals("foover", roster.getVersion());
+ }
+
+ @Test
+ public void testGet_ServerDoesNotSupportVersion() {
+ XMPPRosterController testling = createController();
+ RosterPayload payload = new RosterPayload();
+ payload.setVersion("foover");
+ rosterStorage_.setRoster(payload);
+
+ testling.requestRoster();
+
+ RosterPayload roster = channel_.sentStanzas.get(0).getPayload(new RosterPayload());
+ assertNull(roster.getVersion());
+ }
+
+ @Test
+ public void testGet_ResponseWithoutNewVersion() {
+ XMPPRosterController testling = createController();
+ testling.setUseVersioning(true);
+ RosterPayload storedRoster = new RosterPayload();
+ storedRoster.setVersion("version10");
+ storedRoster.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Both));
+ storedRoster.addItem(new RosterItemPayload(jid2_, "Alice", RosterItemPayload.Subscription.Both));
+ rosterStorage_.setRoster(storedRoster);
+ testling.requestRoster();
+
+ channel_.onIQReceived.emit(IQ.createResult(new JID("foo@bar.com"), channel_.sentStanzas.get(0).getID(), null));
+
+ assertEquals(2, handler_.getEventCount());
+ assertNotNull(xmppRoster_.getItem(jid1_));
+ assertNotNull(xmppRoster_.getItem(jid2_));
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid2_, handler_.getLastJID());
+ assertNotNull(rosterStorage_.getRoster());
+ assertNotNull(rosterStorage_.getRoster().getVersion());
+ assertEquals("version10", rosterStorage_.getRoster().getVersion());
+ assertNotNull(rosterStorage_.getRoster().getItem(jid1_));
+ assertNotNull(rosterStorage_.getRoster().getItem(jid2_));
+ }
+
+ @Test
+ public void testGet_ResponseWithNewVersion() {
+ XMPPRosterController testling = createController();
+ testling.setUseVersioning(true);
+ RosterPayload storedRoster = new RosterPayload();
+ storedRoster.setVersion("version10");
+ storedRoster.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Both));
+ rosterStorage_.setRoster(storedRoster);
+ testling.requestRoster();
+
+ RosterPayload serverRoster = new RosterPayload();
+ serverRoster.setVersion("version12");
+ serverRoster.addItem(new RosterItemPayload(jid2_, "Alice", RosterItemPayload.Subscription.Both));
+ Collection<String> groups = new ArrayList<String>();
+ groups.add("foo");
+ groups.add("bar");
+ serverRoster.addItem(new RosterItemPayload(jid3_, "Rabbit", RosterItemPayload.Subscription.Both, groups));
+ channel_.onIQReceived.emit(IQ.createResult(new JID("foo@bar.com"), channel_.sentStanzas.get(0).getID(), serverRoster));
+
+
+ assertEquals(2, handler_.getEventCount());
+ assertNull(xmppRoster_.getItem(jid1_));
+ assertNotNull(xmppRoster_.getItem(jid2_));
+ assertNotNull(xmppRoster_.getItem(jid3_));
+ assertEquals(jid3_, handler_.getLastJID());
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertNotNull(rosterStorage_.getRoster());
+ assertNotNull(rosterStorage_.getRoster().getVersion());
+ assertEquals("version12", rosterStorage_.getRoster().getVersion());
+ assertNull(rosterStorage_.getRoster().getItem(jid1_));
+ assertNotNull(rosterStorage_.getRoster().getItem(jid2_));
+ assertNotNull(rosterStorage_.getRoster().getItem(jid3_));
+ assertEquals(2, rosterStorage_.getRoster().getItem(jid3_).getGroups().size());
+ }
+
+ @Test
+ public void testAddFromNonAccount() {
+ XMPPRosterController testling = createController();
+
+ RosterPayload payload = new RosterPayload();
+ payload.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Both));
+ IQ request = IQ.createRequest(IQ.Type.Set, new JID(), "eou", payload);
+ request.setFrom(jid2_);
+ channel_.onIQReceived.emit(request);
+
+ assertEquals(XMPPRosterEvents.None, handler_.getLastEvent());
+ }
+
+ @Test
+ public void testModify() {
+ XMPPRosterController controller = new XMPPRosterController(router_, xmppRoster_, rosterStorage_);
+ RosterPayload payload1 = new RosterPayload();
+ payload1.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Both));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id1", payload1));
+
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ handler_.reset();
+
+ RosterPayload payload2 = new RosterPayload();
+ payload2.addItem(new RosterItemPayload(jid1_, "Bob2", RosterItemPayload.Subscription.Both));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id2", payload2));
+
+ assertEquals(XMPPRosterEvents.Update, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+
+ assertEquals("Bob2", xmppRoster_.getNameForJID(jid1_));
+ }
+
+ @Test
+ public void testRemove() {
+ XMPPRosterController controller = new XMPPRosterController(router_, xmppRoster_, rosterStorage_);
+ RosterPayload payload1 = new RosterPayload();
+ payload1.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Both));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id1", payload1));
+
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ handler_.reset();
+
+ RosterPayload payload2 = new RosterPayload();
+ payload2.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Remove));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id2", payload2));
+ assertFalse(xmppRoster_.containsJID(jid1_));
+ assertEquals(XMPPRosterEvents.Remove, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ }
+
+ @Test
+ public void testRemove_RosterStorageUpdated() {
+ XMPPRosterController testling = createController();
+ testling.setUseVersioning(true);
+ RosterPayload storedRoster = new RosterPayload();
+ storedRoster.setVersion("version10");
+ storedRoster.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Both));
+ storedRoster.addItem(new RosterItemPayload(jid2_, "Alice", RosterItemPayload.Subscription.Both));
+ rosterStorage_.setRoster(storedRoster);
+ testling.requestRoster();
+ channel_.onIQReceived.emit(IQ.createResult(new JID("foo@bar.com"), channel_.sentStanzas.get(0).getID(), null));
+
+ RosterPayload payload2 = new RosterPayload();
+ payload2.setVersion("version15");
+ payload2.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Remove));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id2", payload2));
+
+ assertNotNull(rosterStorage_.getRoster());
+ assertNotNull(rosterStorage_.getRoster().getVersion());
+ assertEquals("version15", rosterStorage_.getRoster().getVersion());
+ assertNull(rosterStorage_.getRoster().getItem(jid1_));
+ assertNotNull(rosterStorage_.getRoster().getItem(jid2_));
+ }
+
+ @Test
+ public void testMany() {
+ XMPPRosterController controller = new XMPPRosterController(router_, xmppRoster_, rosterStorage_);
+ RosterPayload payload1 = new RosterPayload();
+ payload1.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Both));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id1", payload1));
+
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ handler_.reset();
+
+ RosterPayload payload2 = new RosterPayload();
+ payload2.addItem(new RosterItemPayload(jid2_, "Alice", RosterItemPayload.Subscription.Both));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id2", payload2));
+
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid2_, handler_.getLastJID());
+ handler_.reset();
+
+ RosterPayload payload3 = new RosterPayload();
+ payload3.addItem(new RosterItemPayload(jid1_, "Ernie", RosterItemPayload.Subscription.Both));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id3", payload3));
+
+ assertEquals(XMPPRosterEvents.Update, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ handler_.reset();
+
+ RosterPayload payload4 = new RosterPayload();
+ RosterItemPayload item = new RosterItemPayload(jid3_, "Jane", RosterItemPayload.Subscription.Both);
+ String janesGroup = "Jane's Group";
+ item.addGroup(janesGroup);
+ payload4.addItem(item);
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id4", payload4));
+
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid3_, handler_.getLastJID());
+ assertEquals(1, xmppRoster_.getGroupsForJID(jid3_).size());
+ assertEquals(janesGroup, xmppRoster_.getGroupsForJID(jid3_).toArray()[0]);
+ handler_.reset();
+
+ RosterPayload payload5 = new RosterPayload();
+ payload5.addItem(new RosterItemPayload(jid1_, "Bob", RosterItemPayload.Subscription.Remove));
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id5", payload5));
+ assertFalse(xmppRoster_.containsJID(jid1_));
+ assertEquals(XMPPRosterEvents.Remove, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ handler_.reset();
+
+ RosterPayload payload6 = new RosterPayload();
+ RosterItemPayload item2 = new RosterItemPayload(jid2_, "Little Alice", RosterItemPayload.Subscription.Both);
+ String alicesGroup = "Alice's Group";
+ item2.addGroup(alicesGroup);
+ payload6.addItem(item2);
+ channel_.onIQReceived.emit(IQ.createRequest(IQ.Type.Set, new JID(), "id6", payload6));
+ assertEquals(XMPPRosterEvents.Update, handler_.getLastEvent());
+ assertEquals(jid2_, handler_.getLastJID());
+ assertEquals("Little Alice", xmppRoster_.getNameForJID(jid2_));
+ assertEquals("Jane", xmppRoster_.getNameForJID(jid3_));
+ assertEquals(1, xmppRoster_.getGroupsForJID(jid2_).size());
+ assertEquals(alicesGroup, xmppRoster_.getGroupsForJID(jid2_).toArray()[0]);
+ assertEquals(1, xmppRoster_.getGroupsForJID(jid3_).size());
+ assertEquals(janesGroup, xmppRoster_.getGroupsForJID(jid3_).toArray()[0]);
+ handler_.reset();
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/roster/XMPPRosterImplTest.java b/test/com/isode/stroke/roster/XMPPRosterImplTest.java
new file mode 100644
index 0000000..191beb5
--- /dev/null
+++ b/test/com/isode/stroke/roster/XMPPRosterImplTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2010-2011 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.roster;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Before;
+import org.junit.Test;
+import com.isode.stroke.roster.XMPPRosterSignalHandler;
+import com.isode.stroke.roster.XMPPRosterImpl;
+import com.isode.stroke.elements.RosterItemPayload;
+import com.isode.stroke.jid.JID;
+import java.util.Collection;
+import java.util.ArrayList;
+
+public class XMPPRosterImplTest {
+
+ private XMPPRosterImpl roster_;
+ private XMPPRosterSignalHandler handler_;
+ private JID jid1_;
+ private JID jid2_;
+ private JID jid3_;
+ private Collection<String> groups1_ = new ArrayList<String>();
+ private Collection<String> groups2_ = new ArrayList<String>();
+
+ @Before
+ public void setUp() {
+ jid1_ = new JID("a@b.c");
+ jid2_ = new JID("b@c.d");
+ jid3_ = new JID("c@d.e");
+ roster_ = new XMPPRosterImpl();
+ handler_ = new XMPPRosterSignalHandler(roster_);
+ groups1_.add("bobs");
+ groups1_.add("berts");
+ groups2_.add("ernies");
+ }
+
+ @Test
+ public void testJIDAdded() {
+ roster_.addContact(jid1_, "NewName", groups1_, RosterItemPayload.Subscription.Both);
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ assertEquals("NewName", roster_.getNameForJID(jid1_));
+ assertEquals(groups1_, roster_.getGroupsForJID(jid1_));
+ handler_.reset();
+ roster_.addContact(jid2_, "NameTwo", groups1_, RosterItemPayload.Subscription.Both);
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid2_, handler_.getLastJID());
+ assertEquals("NameTwo", roster_.getNameForJID(jid2_));
+ assertEquals("NewName", roster_.getNameForJID(jid1_));
+ assertEquals(groups1_, roster_.getGroupsForJID(jid2_));
+ assertEquals(groups1_, roster_.getGroupsForJID(jid1_));
+ handler_.reset();
+ roster_.addContact(jid3_, "NewName", groups2_, RosterItemPayload.Subscription.Both);
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid3_, handler_.getLastJID());
+ assertEquals("NewName", roster_.getNameForJID(jid3_));
+ assertEquals(groups2_, roster_.getGroupsForJID(jid3_));
+ }
+
+ @Test
+ public void testJIDRemoved() {
+ roster_.addContact(jid1_, "NewName", groups1_, RosterItemPayload.Subscription.Both);
+ handler_.reset();
+ roster_.removeContact(jid1_);
+ assertEquals(XMPPRosterEvents.Remove, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ handler_.reset();
+ roster_.addContact(jid1_, "NewName2", groups1_, RosterItemPayload.Subscription.Both);
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ assertEquals("NewName2", roster_.getNameForJID(jid1_));
+ roster_.addContact(jid2_, "NewName3", groups1_, RosterItemPayload.Subscription.Both);
+ handler_.reset();
+ roster_.removeContact(jid2_);
+ assertEquals(XMPPRosterEvents.Remove, handler_.getLastEvent());
+ assertEquals(jid2_, handler_.getLastJID());
+ handler_.reset();
+ roster_.removeContact(jid1_);
+ assertEquals(XMPPRosterEvents.Remove, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ }
+
+ @Test
+ public void testJIDUpdated() {
+ roster_.addContact(jid1_, "NewName", groups1_, RosterItemPayload.Subscription.Both);
+ assertEquals(XMPPRosterEvents.Add, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ assertEquals("NewName", roster_.getNameForJID(jid1_));
+ assertEquals(groups1_, roster_.getGroupsForJID(jid1_));
+ handler_.reset();
+ roster_.addContact(jid1_, "NameTwo", groups2_, RosterItemPayload.Subscription.Both);
+ assertEquals(XMPPRosterEvents.Update, handler_.getLastEvent());
+ assertEquals(jid1_, handler_.getLastJID());
+ assertEquals("NameTwo", roster_.getNameForJID(jid1_));
+ assertEquals(groups2_, roster_.getGroupsForJID(jid1_));
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/roster/XMPPRosterSignalHandler.java b/test/com/isode/stroke/roster/XMPPRosterSignalHandler.java
new file mode 100644
index 0000000..a6d69eb
--- /dev/null
+++ b/test/com/isode/stroke/roster/XMPPRosterSignalHandler.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2010-2011 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.roster;
+
+import com.isode.stroke.roster.XMPPRosterImpl;
+import com.isode.stroke.roster.XMPPRosterEvents;
+import com.isode.stroke.signals.SignalConnection;
+import com.isode.stroke.signals.Slot1;
+import com.isode.stroke.signals.Slot3;
+import com.isode.stroke.jid.JID;
+import java.util.Collection;
+import java.util.ArrayList;
+
+enum XMPPRosterEvents {
+ None,
+ Add,
+ Remove,
+ Update
+};
+
+public class XMPPRosterSignalHandler {
+
+ public XMPPRosterSignalHandler(XMPPRoster roster) {
+ this.eventCount = 0;
+ lastEvent_ = XMPPRosterEvents.None;
+ onJIDAddedConnection = roster.onJIDAdded.connect(new Slot1<JID>() {
+ @Override
+ public void call(JID j1) {
+ handleJIDAdded(j1);
+ }
+ });
+
+ onJIDRemovedConnection = roster.onJIDRemoved.connect(new Slot1<JID>() {
+ @Override
+ public void call(JID j1) {
+ handleJIDRemoved(j1);
+ }
+ });
+
+ onJIDUpdatedConnection = roster.onJIDUpdated.connect(new Slot3<JID, String, Collection<String> >() {
+ @Override
+ public void call(JID j1, String s1, Collection<String> c1) {
+ handleJIDUpdated(j1, s1, c1);
+ }
+ });
+ }
+
+ public XMPPRosterEvents getLastEvent() {
+ return lastEvent_;
+ }
+
+ public JID getLastJID() {
+ return lastJID_;
+ }
+
+ public String getLastOldName() {
+ return lastOldName_;
+ }
+
+ public Collection<String> getLastOldGroups() {
+ return lastOldGroups_;
+ }
+
+ public void reset() {
+ lastEvent_ = XMPPRosterEvents.None;
+ }
+
+ public final int getEventCount() {
+ return eventCount;
+ }
+
+ private void handleJIDAdded(final JID jid) {
+ lastJID_ = jid;
+ lastEvent_ = XMPPRosterEvents.Add;
+ eventCount++;
+ }
+
+ private void handleJIDRemoved(final JID jid) {
+ lastJID_ = jid;
+ lastEvent_ = XMPPRosterEvents.Remove;
+ eventCount++;
+ }
+
+ private void handleJIDUpdated(final JID jid, final String oldName, final Collection<String> oldGroups) {
+ assert(lastEvent_ == XMPPRosterEvents.None);
+ lastJID_ = jid;
+ lastOldName_ = oldName;
+ lastOldGroups_ = oldGroups;
+ lastEvent_ = XMPPRosterEvents.Update;
+ eventCount++;
+ }
+
+ private XMPPRosterEvents lastEvent_;
+ private JID lastJID_ = new JID(); //initialized
+ private String lastOldName_ = "";
+ private Collection<String> lastOldGroups_ = new ArrayList<String>(); //initialized
+ private int eventCount;
+ private SignalConnection onJIDAddedConnection;
+ private SignalConnection onJIDRemovedConnection;
+ private SignalConnection onJIDUpdatedConnection;
+} \ No newline at end of file