mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
Use Jid (and subclasses) from jxmpp-jid
Fixes SMACK-634
This commit is contained in:
parent
0ee2d9ed1e
commit
5bb4727c57
180 changed files with 1510 additions and 1032 deletions
|
@ -32,6 +32,8 @@ import org.jivesoftware.smack.test.util.WaitForPacketListener;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
|
||||
public class ChatConnectionTest {
|
||||
|
||||
|
@ -219,7 +221,7 @@ public class ChatConnectionTest {
|
|||
*/
|
||||
@Test
|
||||
public void chatFoundWhenNoThreadFullJid() {
|
||||
Chat outgoing = cm.createChat("you@testserver", null);
|
||||
Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
|
||||
|
||||
Stanza incomingChat = createChatPacket(null, true);
|
||||
processServerMessage(incomingChat);
|
||||
|
@ -235,7 +237,7 @@ public class ChatConnectionTest {
|
|||
*/
|
||||
@Test
|
||||
public void chatFoundWhenNoThreadBaseJid() {
|
||||
Chat outgoing = cm.createChat("you@testserver", null);
|
||||
Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
|
||||
|
||||
Stanza incomingChat = createChatPacket(null, false);
|
||||
processServerMessage(incomingChat);
|
||||
|
@ -251,7 +253,7 @@ public class ChatConnectionTest {
|
|||
*/
|
||||
@Test
|
||||
public void chatFoundWithSameThreadFullJid() {
|
||||
Chat outgoing = cm.createChat("you@testserver", null);
|
||||
Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
|
||||
|
||||
Stanza incomingChat = createChatPacket(outgoing.getThreadID(), true);
|
||||
processServerMessage(incomingChat);
|
||||
|
@ -267,7 +269,7 @@ public class ChatConnectionTest {
|
|||
*/
|
||||
@Test
|
||||
public void chatFoundWithSameThreadBaseJid() {
|
||||
Chat outgoing = cm.createChat("you@testserver", null);
|
||||
Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
|
||||
|
||||
Stanza incomingChat = createChatPacket(outgoing.getThreadID(), false);
|
||||
processServerMessage(incomingChat);
|
||||
|
@ -283,7 +285,7 @@ public class ChatConnectionTest {
|
|||
*/
|
||||
@Test
|
||||
public void chatNotFoundWithDiffThreadBaseJid() {
|
||||
Chat outgoing = cm.createChat("you@testserver", null);
|
||||
Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
|
||||
|
||||
Stanza incomingChat = createChatPacket(outgoing.getThreadID() + "ff", false);
|
||||
processServerMessage(incomingChat);
|
||||
|
@ -299,7 +301,7 @@ public class ChatConnectionTest {
|
|||
*/
|
||||
@Test
|
||||
public void chatNotFoundWithDiffThreadFullJid() {
|
||||
Chat outgoing = cm.createChat("you@testserver", null);
|
||||
Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
|
||||
|
||||
Stanza incomingChat = createChatPacket(outgoing.getThreadID() + "ff", true);
|
||||
processServerMessage(incomingChat);
|
||||
|
@ -321,9 +323,15 @@ public class ChatConnectionTest {
|
|||
}
|
||||
|
||||
private Message createChatPacket(final String threadId, final boolean isFullJid) {
|
||||
Message chatMsg = new Message("me@testserver", Message.Type.chat);
|
||||
Message chatMsg = new Message(JidTestUtil.BARE_JID_1, Message.Type.chat);
|
||||
chatMsg.setBody("the body message - " + System.currentTimeMillis());
|
||||
chatMsg.setFrom("you@testserver" + (isFullJid ? "/resource" : ""));
|
||||
Jid jid;
|
||||
if (isFullJid) {
|
||||
jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
|
||||
} else {
|
||||
jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
|
||||
}
|
||||
chatMsg.setFrom(jid);
|
||||
chatMsg.setThread(threadId);
|
||||
return chatMsg;
|
||||
}
|
||||
|
|
|
@ -45,11 +45,6 @@ public class RosterOfflineTest {
|
|||
assertNotNull(roster);
|
||||
}
|
||||
|
||||
@Test(expected = SmackException.class)
|
||||
public void shouldThrowExceptionOnCreateEntry() throws Exception {
|
||||
roster.createEntry("test", "test", null);
|
||||
}
|
||||
|
||||
@Test(expected = SmackException.class)
|
||||
public void shouldThrowExceptionOnReload() throws Exception {
|
||||
roster.reload();
|
||||
|
|
|
@ -50,6 +50,9 @@ import org.jivesoftware.smack.util.PacketParserUtils;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
|
@ -104,18 +107,18 @@ public class RosterTest extends InitSmackIm {
|
|||
|
||||
// Verify roster
|
||||
assertTrue("Roster can't be loaded!", roster.waitUntilLoaded());
|
||||
verifyRomeosEntry(roster.getEntry("romeo@example.net"));
|
||||
verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
|
||||
verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
|
||||
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net")));
|
||||
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
|
||||
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
|
||||
assertSame("Wrong number of roster entries.", 3, roster.getEntries().size());
|
||||
|
||||
// Verify roster listener
|
||||
assertTrue("The roster listener wasn't invoked for Romeo.",
|
||||
rosterListener.getAddedAddresses().contains("romeo@example.net"));
|
||||
rosterListener.addedAddressesContains("romeo@example.net"));
|
||||
assertTrue("The roster listener wasn't invoked for Mercutio.",
|
||||
rosterListener.getAddedAddresses().contains("mercutio@example.com"));
|
||||
rosterListener.addedAddressesContains("mercutio@example.com"));
|
||||
assertTrue("The roster listener wasn't invoked for Benvolio.",
|
||||
rosterListener.getAddedAddresses().contains("benvolio@example.net"));
|
||||
rosterListener.addedAddressesContains("benvolio@example.net"));
|
||||
assertSame("RosterListeners implies that a item was deleted!",
|
||||
0,
|
||||
rosterListener.getDeletedAddresses().size());
|
||||
|
@ -132,7 +135,7 @@ public class RosterTest extends InitSmackIm {
|
|||
@Test
|
||||
public void testAddRosterItem() throws Throwable {
|
||||
// Constants for the new contact
|
||||
final String contactJID = "nurse@example.com";
|
||||
final Jid contactJID = JidCreate.from("nurse@example.com");
|
||||
final String contactName = "Nurse";
|
||||
final String[] contactGroup = {"Servants"};
|
||||
|
||||
|
@ -189,9 +192,9 @@ public class RosterTest extends InitSmackIm {
|
|||
addedEntry.getGroups().iterator().next().getName());
|
||||
|
||||
// Verify the unchanged roster items
|
||||
verifyRomeosEntry(roster.getEntry("romeo@example.net"));
|
||||
verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
|
||||
verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
|
||||
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net")));
|
||||
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
|
||||
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
|
||||
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
|
||||
}
|
||||
|
||||
|
@ -203,7 +206,7 @@ public class RosterTest extends InitSmackIm {
|
|||
@Test
|
||||
public void testUpdateRosterItem() throws Throwable {
|
||||
// Constants for the updated contact
|
||||
final String contactJID = "romeo@example.net";
|
||||
final Jid contactJID = JidCreate.from("romeo@example.net");
|
||||
final String contactName = "Romeo";
|
||||
final String[] contactGroups = {"Friends", "Lovers"};
|
||||
|
||||
|
@ -263,8 +266,8 @@ public class RosterTest extends InitSmackIm {
|
|||
addedEntry.getGroups().size());
|
||||
|
||||
// Verify the unchanged roster items
|
||||
verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
|
||||
verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
|
||||
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
|
||||
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
|
||||
assertSame("Wrong number of roster entries (" + roster.getEntries() + ").",
|
||||
3,
|
||||
roster.getEntries().size());
|
||||
|
@ -278,7 +281,7 @@ public class RosterTest extends InitSmackIm {
|
|||
@Test
|
||||
public void testDeleteRosterItem() throws Throwable {
|
||||
// The contact which should be deleted
|
||||
final String contactJID = "romeo@example.net";
|
||||
final Jid contactJID = JidCreate.from("romeo@example.net");
|
||||
|
||||
// Setup
|
||||
assertNotNull("Can't get the roster from the provided connection!", roster);
|
||||
|
@ -310,8 +313,8 @@ public class RosterTest extends InitSmackIm {
|
|||
assertNull("The contact wasn't deleted from the roster!", deletedEntry);
|
||||
assertTrue("The roster listener wasn't invoked for the deleted contact!",
|
||||
rosterListener.getDeletedAddresses().contains(contactJID));
|
||||
verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
|
||||
verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
|
||||
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
|
||||
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
|
||||
assertSame("Wrong number of roster entries (" + roster.getEntries() + ").",
|
||||
2,
|
||||
roster.getEntries().size());
|
||||
|
@ -324,7 +327,7 @@ public class RosterTest extends InitSmackIm {
|
|||
*/
|
||||
@Test
|
||||
public void testSimpleRosterPush() throws Throwable {
|
||||
final String contactJID = "nurse@example.com";
|
||||
final Jid contactJID = JidCreate.from("nurse@example.com");
|
||||
assertNotNull("Can't get the roster from the provided connection!", roster);
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("<iq id=\"rostertest1\" type=\"set\" ")
|
||||
|
@ -355,24 +358,26 @@ public class RosterTest extends InitSmackIm {
|
|||
addedEntry.getGroups().size());
|
||||
|
||||
// Verify the unchanged roster items
|
||||
verifyRomeosEntry(roster.getEntry("romeo@example.net"));
|
||||
verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
|
||||
verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
|
||||
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net")));
|
||||
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
|
||||
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
|
||||
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that roster pushes with invalid from are ignored.
|
||||
* @throws XmppStringprepException
|
||||
*
|
||||
* @see <a href="http://xmpp.org/rfcs/rfc6121.html#roster-syntax-actions-push">RFC 6121, Section 2.1.6</a>
|
||||
*/
|
||||
@Test
|
||||
public void testIgnoreInvalidFrom() {
|
||||
public void testIgnoreInvalidFrom() throws XmppStringprepException {
|
||||
final Jid spammerJid = JidCreate.from("spam@example.com");
|
||||
RosterPacket packet = new RosterPacket();
|
||||
packet.setType(Type.set);
|
||||
packet.setTo(connection.getUser());
|
||||
packet.setFrom("mallory@example.com");
|
||||
packet.addRosterItem(new Item("spam@example.com", "Cool products!"));
|
||||
packet.setFrom(JidCreate.from("mallory@example.com"));
|
||||
packet.addRosterItem(new Item(spammerJid, "Cool products!"));
|
||||
|
||||
final String requestId = packet.getStanzaId();
|
||||
// Simulate receiving the roster push
|
||||
|
@ -383,7 +388,7 @@ public class RosterTest extends InitSmackIm {
|
|||
assertEquals(requestId, errorIQ.getStanzaId());
|
||||
assertEquals(Condition.service_unavailable, errorIQ.getError().getCondition());
|
||||
|
||||
assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry("spam@example.com"));
|
||||
assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry(spammerJid));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -395,7 +400,7 @@ public class RosterTest extends InitSmackIm {
|
|||
@Test(timeout=5000)
|
||||
public void testAddEmptyGroupEntry() throws Throwable {
|
||||
// Constants for the new contact
|
||||
final String contactJID = "nurse@example.com";
|
||||
final Jid contactJID = JidCreate.from("nurse@example.com");
|
||||
final String contactName = "Nurse";
|
||||
final String[] contactGroup = {""};
|
||||
|
||||
|
@ -447,9 +452,9 @@ public class RosterTest extends InitSmackIm {
|
|||
addedEntry.getGroups().size());
|
||||
|
||||
// Verify the unchanged roster items
|
||||
verifyRomeosEntry(roster.getEntry("romeo@example.net"));
|
||||
verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
|
||||
verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
|
||||
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net")));
|
||||
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
|
||||
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
|
||||
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
|
||||
}
|
||||
|
||||
|
@ -461,7 +466,7 @@ public class RosterTest extends InitSmackIm {
|
|||
*/
|
||||
@Test
|
||||
public void testEmptyGroupRosterPush() throws Throwable {
|
||||
final String contactJID = "nurse@example.com";
|
||||
final Jid contactJID = JidCreate.from("nurse@example.com");
|
||||
assertNotNull("Can't get the roster from the provided connection!", roster);
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("<iq id=\"rostertest2\" type=\"set\" ")
|
||||
|
@ -494,9 +499,9 @@ public class RosterTest extends InitSmackIm {
|
|||
addedEntry.getGroups().size());
|
||||
|
||||
// Verify the unchanged roster items
|
||||
verifyRomeosEntry(roster.getEntry("romeo@example.net"));
|
||||
verifyMercutiosEntry(roster.getEntry("mercutio@example.com"));
|
||||
verifyBenvoliosEntry(roster.getEntry("benvolio@example.net"));
|
||||
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net")));
|
||||
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com")));
|
||||
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net")));
|
||||
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
|
||||
}
|
||||
|
||||
|
@ -533,8 +538,9 @@ public class RosterTest extends InitSmackIm {
|
|||
* @param connection the dummy connection of which the provided roster belongs to.
|
||||
* @param roster the roster (or buddy list) which should be initialized.
|
||||
* @throws SmackException
|
||||
* @throws XmppStringprepException
|
||||
*/
|
||||
private void initRoster() throws InterruptedException, XMPPException, SmackException {
|
||||
private void initRoster() throws InterruptedException, XMPPException, SmackException, XmppStringprepException {
|
||||
roster.reload();
|
||||
while (true) {
|
||||
final Stanza sentPacket = connection.getSentPacket();
|
||||
|
@ -552,18 +558,18 @@ public class RosterTest extends InitSmackIm {
|
|||
rosterResult.setStanzaId(rosterRequest.getStanzaId());
|
||||
|
||||
// prepare romeo's roster entry
|
||||
final Item romeo = new Item("romeo@example.net", "Romeo");
|
||||
final Item romeo = new Item(JidCreate.from("romeo@example.net"), "Romeo");
|
||||
romeo.addGroupName("Friends");
|
||||
romeo.setItemType(ItemType.both);
|
||||
rosterResult.addRosterItem(romeo);
|
||||
|
||||
// prepare mercutio's roster entry
|
||||
final Item mercutio = new Item("mercutio@example.com", "Mercutio");
|
||||
final Item mercutio = new Item(JidCreate.from("mercutio@example.com"), "Mercutio");
|
||||
mercutio.setItemType(ItemType.from);
|
||||
rosterResult.addRosterItem(mercutio);
|
||||
|
||||
// prepare benvolio's roster entry
|
||||
final Item benvolio = new Item("benvolio@example.net", "Benvolio");
|
||||
final Item benvolio = new Item(JidCreate.from("benvolio@example.net"), "Benvolio");
|
||||
benvolio.setItemType(ItemType.both);
|
||||
rosterResult.addRosterItem(benvolio);
|
||||
|
||||
|
@ -704,34 +710,34 @@ public class RosterTest extends InitSmackIm {
|
|||
* This class can be used to check if the RosterListener was invoked.
|
||||
*/
|
||||
public static class TestRosterListener extends WaitForPacketListener implements RosterListener {
|
||||
private final List<String> addressesAdded = new CopyOnWriteArrayList<>();
|
||||
private final List<String> addressesDeleted = new CopyOnWriteArrayList<>();
|
||||
private final List<String> addressesUpdated = new CopyOnWriteArrayList<>();
|
||||
private final List<Jid> addressesAdded = new CopyOnWriteArrayList<>();
|
||||
private final List<Jid> addressesDeleted = new CopyOnWriteArrayList<>();
|
||||
private final List<Jid> addressesUpdated = new CopyOnWriteArrayList<>();
|
||||
|
||||
public synchronized void entriesAdded(Collection<String> addresses) {
|
||||
public synchronized void entriesAdded(Collection<Jid> addresses) {
|
||||
addressesAdded.addAll(addresses);
|
||||
if (SmackConfiguration.DEBUG) {
|
||||
for (String address : addresses) {
|
||||
for (Jid address : addresses) {
|
||||
System.out.println("Roster entry for " + address + " added.");
|
||||
}
|
||||
}
|
||||
reportInvoked();
|
||||
}
|
||||
|
||||
public synchronized void entriesDeleted(Collection<String> addresses) {
|
||||
public synchronized void entriesDeleted(Collection<Jid> addresses) {
|
||||
addressesDeleted.addAll(addresses);
|
||||
if (SmackConfiguration.DEBUG) {
|
||||
for (String address : addresses) {
|
||||
for (Jid address : addresses) {
|
||||
System.out.println("Roster entry for " + address + " deleted.");
|
||||
}
|
||||
}
|
||||
reportInvoked();
|
||||
}
|
||||
|
||||
public synchronized void entriesUpdated(Collection<String> addresses) {
|
||||
public synchronized void entriesUpdated(Collection<Jid> addresses) {
|
||||
addressesUpdated.addAll(addresses);
|
||||
if (SmackConfiguration.DEBUG) {
|
||||
for (String address : addresses) {
|
||||
for (Jid address : addresses) {
|
||||
System.out.println("Roster entry for " + address + " updated.");
|
||||
}
|
||||
}
|
||||
|
@ -750,7 +756,7 @@ public class RosterTest extends InitSmackIm {
|
|||
*
|
||||
* @return the collection of addresses which were added.
|
||||
*/
|
||||
public Collection<String> getAddedAddresses() {
|
||||
public Collection<Jid> getAddedAddresses() {
|
||||
return Collections.unmodifiableCollection(addressesAdded);
|
||||
}
|
||||
|
||||
|
@ -759,7 +765,7 @@ public class RosterTest extends InitSmackIm {
|
|||
*
|
||||
* @return the collection of addresses which were deleted.
|
||||
*/
|
||||
public Collection<String> getDeletedAddresses() {
|
||||
public Collection<Jid> getDeletedAddresses() {
|
||||
return Collections.unmodifiableCollection(addressesDeleted);
|
||||
}
|
||||
|
||||
|
@ -768,10 +774,43 @@ public class RosterTest extends InitSmackIm {
|
|||
*
|
||||
* @return the collection of addresses which were updated.
|
||||
*/
|
||||
public Collection<String> getUpdatedAddresses() {
|
||||
public Collection<Jid> getUpdatedAddresses() {
|
||||
return Collections.unmodifiableCollection(addressesUpdated);
|
||||
}
|
||||
|
||||
public boolean addedAddressesContains(String jidString) {
|
||||
Jid jid;
|
||||
try {
|
||||
jid = JidCreate.from(jidString);
|
||||
}
|
||||
catch (XmppStringprepException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
return addressesAdded.contains(jid);
|
||||
}
|
||||
|
||||
public boolean deletedAddressesContains(String jidString) {
|
||||
Jid jid;
|
||||
try {
|
||||
jid = JidCreate.from(jidString);
|
||||
}
|
||||
catch (XmppStringprepException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
return addressesDeleted.contains(jid);
|
||||
}
|
||||
|
||||
public boolean updatedAddressesContains(String jidString) {
|
||||
Jid jid;
|
||||
try {
|
||||
jid = JidCreate.from(jidString);
|
||||
}
|
||||
catch (XmppStringprepException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
return addressesUpdated.contains(jid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the lists of added, deleted or updated items.
|
||||
*/
|
||||
|
|
|
@ -44,6 +44,8 @@ import org.junit.Before;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
/**
|
||||
* Tests that verify the correct behavior of the {@link Roster} implementation
|
||||
|
@ -130,9 +132,10 @@ public class RosterVersioningTest {
|
|||
* Tests that a non-empty roster result empties the store.
|
||||
* @throws SmackException
|
||||
* @throws XMPPException
|
||||
* @throws XmppStringprepException
|
||||
*/
|
||||
@Test(timeout = 5000)
|
||||
public void testOtherVersionStored() throws InterruptedException, XMPPException, SmackException {
|
||||
public void testOtherVersionStored() throws InterruptedException, XMPPException, SmackException, XmppStringprepException {
|
||||
Item vaglafItem = vaglafItem();
|
||||
|
||||
// We expect that the roster request is the only packet sent. This is not part of the specification,
|
||||
|
@ -181,7 +184,7 @@ public class RosterVersioningTest {
|
|||
// Simulate a roster push adding vaglaf
|
||||
{
|
||||
RosterPacket rosterPush = new RosterPacket();
|
||||
rosterPush.setTo("rostertest@example.com/home");
|
||||
rosterPush.setTo(JidCreate.from("rostertest@example.com/home"));
|
||||
rosterPush.setType(Type.set);
|
||||
rosterPush.setVersion("v97");
|
||||
|
||||
|
@ -193,7 +196,7 @@ public class RosterVersioningTest {
|
|||
|
||||
assertEquals("Expect store version after push", "v97", store.getRosterVersion());
|
||||
|
||||
Item storedItem = store.getEntry("vaglaf@example.com");
|
||||
Item storedItem = store.getEntry(JidCreate.from("vaglaf@example.com"));
|
||||
assertNotNull("Expect vaglaf to be added", storedItem);
|
||||
assertEquals("Expect vaglaf to be equal to pushed item", pushedItem, storedItem);
|
||||
|
||||
|
@ -207,24 +210,24 @@ public class RosterVersioningTest {
|
|||
// Simulate a roster push removing vaglaf
|
||||
{
|
||||
RosterPacket rosterPush = new RosterPacket();
|
||||
rosterPush.setTo("rostertest@example.com/home");
|
||||
rosterPush.setTo(JidCreate.from("rostertest@example.com/home"));
|
||||
rosterPush.setType(Type.set);
|
||||
rosterPush.setVersion("v98");
|
||||
|
||||
Item item = new Item("vaglaf@example.com", "vaglaf the only");
|
||||
Item item = new Item(JidCreate.from("vaglaf@example.com"), "vaglaf the only");
|
||||
item.setItemType(ItemType.remove);
|
||||
rosterPush.addRosterItem(item);
|
||||
rosterListener.reset();
|
||||
connection.processPacket(rosterPush);
|
||||
rosterListener.waitAndReset();
|
||||
|
||||
assertNull("Store doses not contain vaglaf", store.getEntry("vaglaf@example.com"));
|
||||
assertNull("Store doses not contain vaglaf", store.getEntry(JidCreate.from("vaglaf@example.com")));
|
||||
assertEquals("Expect store version after push", "v98", store.getRosterVersion());
|
||||
}
|
||||
}
|
||||
|
||||
private Item vaglafItem() {
|
||||
Item item = new Item("vaglaf@example.com", "vaglaf the only");
|
||||
private Item vaglafItem() throws XmppStringprepException {
|
||||
Item item = new Item(JidCreate.from("vaglaf@example.com"), "vaglaf the only");
|
||||
item.setItemType(ItemType.both);
|
||||
item.addGroupName("all");
|
||||
item.addGroupName("friends");
|
||||
|
@ -233,14 +236,14 @@ public class RosterVersioningTest {
|
|||
}
|
||||
|
||||
private void populateStore(RosterStore store) throws IOException {
|
||||
store.addEntry(new RosterPacket.Item("geoff@example.com", "geoff hurley"), "");
|
||||
store.addEntry(new RosterPacket.Item(JidCreate.from("geoff@example.com"), "geoff hurley"), "");
|
||||
|
||||
RosterPacket.Item item = new RosterPacket.Item("joe@example.com", "joe stevens");
|
||||
RosterPacket.Item item = new RosterPacket.Item(JidCreate.from("joe@example.com"), "joe stevens");
|
||||
item.addGroupName("friends");
|
||||
item.addGroupName("partners");
|
||||
store.addEntry(item, "");
|
||||
|
||||
item = new RosterPacket.Item("higgins@example.com", "higgins mcmann");
|
||||
item = new RosterPacket.Item(JidCreate.from("higgins@example.com"), "higgins mcmann");
|
||||
item.addGroupName("all");
|
||||
item.addGroupName("friends");
|
||||
store.addEntry(item, "v96");
|
||||
|
|
|
@ -34,6 +34,9 @@ import org.junit.Before;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
/**
|
||||
* Tests the implementation of {@link DirectoryRosterStore}.
|
||||
|
@ -86,7 +89,7 @@ public class DirectoryRosterStoreTest {
|
|||
|
||||
assertEquals("Initial roster version", "", store.getRosterVersion());
|
||||
|
||||
String userName = "user@example.com";
|
||||
Jid userName = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
|
||||
|
||||
final RosterPacket.Item item1 = new Item(userName, null);
|
||||
final String version1 = "1";
|
||||
|
@ -130,13 +133,13 @@ public class DirectoryRosterStoreTest {
|
|||
List<Item> entries = store.getEntries();
|
||||
assertEquals("Number of entries", 1, entries.size());
|
||||
|
||||
final RosterPacket.Item item3 = new Item("foobar@example.com", "Foo Bar");
|
||||
final RosterPacket.Item item3 = new Item(JidTestUtil.BARE_JID_1, "Foo Bar");
|
||||
item3.addGroupName("The Foo Fighters");
|
||||
item3.addGroupName("Bar Friends");
|
||||
item3.setItemStatus(ItemStatus.unsubscribe);
|
||||
item3.setItemType(ItemType.both);
|
||||
|
||||
final RosterPacket.Item item4 = new Item("baz@example.com", "Baba Baz");
|
||||
final RosterPacket.Item item4 = new Item(JidTestUtil.BARE_JID_2, "Baba Baz");
|
||||
item4.addGroupName("The Foo Fighters");
|
||||
item4.addGroupName("Bar Friends");
|
||||
item4.setItemStatus(ItemStatus.subscribe);
|
||||
|
@ -149,7 +152,7 @@ public class DirectoryRosterStoreTest {
|
|||
String version3 = "3";
|
||||
store.resetEntries(items34, version3);
|
||||
|
||||
storedItem = store.getEntry("foobar@example.com");
|
||||
storedItem = store.getEntry(JidTestUtil.BARE_JID_1);
|
||||
assertNotNull("Added entry not found", storedItem);
|
||||
assertEquals("User of added entry",
|
||||
item3.getUser(), storedItem.getUser());
|
||||
|
@ -162,7 +165,7 @@ public class DirectoryRosterStoreTest {
|
|||
item3.getItemStatus(), storedItem.getItemStatus());
|
||||
|
||||
|
||||
storedItem = store.getEntry("baz@example.com");
|
||||
storedItem = store.getEntry(JidTestUtil.BARE_JID_2);
|
||||
assertNotNull("Added entry not found", storedItem);
|
||||
assertEquals("User of added entry",
|
||||
item4.getUser(), storedItem.getUser());
|
||||
|
@ -178,7 +181,7 @@ public class DirectoryRosterStoreTest {
|
|||
assertEquals("Number of entries", 2, entries.size());
|
||||
|
||||
String version4 = "4";
|
||||
store.removeEntry("baz@example.com", version4);
|
||||
store.removeEntry(JidTestUtil.BARE_JID_2, version4);
|
||||
assertEquals("Removing entry sets version correctly",
|
||||
version4, store.getRosterVersion());
|
||||
assertNull("Removed entry is gone", store.getEntry(userName));
|
||||
|
@ -195,7 +198,7 @@ public class DirectoryRosterStoreTest {
|
|||
File storeDir = tmpFolder.newFolder();
|
||||
DirectoryRosterStore store = DirectoryRosterStore.init(storeDir);
|
||||
|
||||
String user = "../_#;\"'\\&@example.com";
|
||||
Jid user = JidCreate.from(".._#;'&@example.com");
|
||||
String name = "\n../_#\0\t;\"'&@\\";
|
||||
String group1 = "\t;\"'&@\\\n../_#\0";
|
||||
String group2 = "#\0\t;\"'&@\\\n../_";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue