mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +01:00
Improve Roster API
Make Roster entries Map from BareJid to RosterEntry, since only bare JIDs are allowed as roster items as per RFC 6121 § 3.1.1 When a user sends a presence subscription request to a potential instant messaging and presence contact, the value of the 'to' attribute MUST be a bare JID <contact@domainpart> rather than a full JID <contact@domainpart/resourcepart>,… Also some further Roster API changes regarding JIDs.
This commit is contained in:
parent
c125a3b055
commit
1d1ea5dd10
11 changed files with 109 additions and 84 deletions
|
@ -63,6 +63,7 @@ import org.jivesoftware.smack.roster.packet.RosterPacket.Item;
|
|||
import org.jivesoftware.smack.roster.packet.SubscriptionPreApproval;
|
||||
import org.jivesoftware.smack.roster.rosterstore.RosterStore;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
@ -104,7 +105,7 @@ public final class Roster extends Manager {
|
|||
* <p>
|
||||
* This method will never return <code>null</code>, instead if the user has not yet logged into
|
||||
* the server all modifying methods of the returned roster object
|
||||
* like {@link Roster#createEntry(Jid, String, String[])},
|
||||
* like {@link Roster#createEntry(BareJid, String, String[])},
|
||||
* {@link Roster#removeEntry(RosterEntry)} , etc. except adding or removing
|
||||
* {@link RosterListener}s will throw an IllegalStateException.
|
||||
* </p>
|
||||
|
@ -136,7 +137,7 @@ public final class Roster extends Manager {
|
|||
/**
|
||||
* Concurrent hash map from JID to its roster entry.
|
||||
*/
|
||||
private final Map<Jid, RosterEntry> entries = new ConcurrentHashMap<>();
|
||||
private final Map<BareJid, RosterEntry> entries = new ConcurrentHashMap<>();
|
||||
|
||||
private final Set<RosterEntry> unfiledEntries = new CopyOnWriteArraySet<>();
|
||||
private final Set<RosterListener> rosterListeners = new LinkedHashSet<>();
|
||||
|
@ -497,7 +498,7 @@ public final class Roster extends Manager {
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void createEntry(Jid user, String name, String[] groups) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public void createEntry(BareJid user, String name, String[] groups) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
|
||||
|
||||
// Create and send roster entry creation packet.
|
||||
|
@ -536,7 +537,7 @@ public final class Roster extends Manager {
|
|||
* @throws FeatureNotSupportedException if pre-approving is not supported.
|
||||
* @since 4.2
|
||||
*/
|
||||
public void preApproveAndCreateEntry(Jid user, String name, String[] groups) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, FeatureNotSupportedException {
|
||||
public void preApproveAndCreateEntry(BareJid user, String name, String[] groups) throws NotLoggedInException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, FeatureNotSupportedException {
|
||||
preApprove(user);
|
||||
createEntry(user, name, groups);
|
||||
}
|
||||
|
@ -608,7 +609,7 @@ public final class Roster extends Manager {
|
|||
|
||||
// Only remove the entry if it's in the entry list.
|
||||
// The actual removal logic takes place in RosterPacketListenerprocess>>Packet(Packet)
|
||||
if (!entries.containsKey(entry.getUser())) {
|
||||
if (!entries.containsKey(entry.getJid())) {
|
||||
return;
|
||||
}
|
||||
RosterPacket packet = new RosterPacket();
|
||||
|
@ -1125,18 +1126,18 @@ public final class Roster extends Manager {
|
|||
Collection<Jid> unchangedEntries, RosterPacket.Item item, RosterEntry entry) {
|
||||
RosterEntry oldEntry;
|
||||
synchronized (rosterListenersAndEntriesLock) {
|
||||
oldEntry = entries.put(item.getUser(), entry);
|
||||
oldEntry = entries.put(item.getJid(), entry);
|
||||
}
|
||||
if (oldEntry == null) {
|
||||
addedEntries.add(item.getUser());
|
||||
addedEntries.add(item.getJid());
|
||||
}
|
||||
else {
|
||||
RosterPacket.Item oldItem = RosterEntry.toRosterItem(oldEntry);
|
||||
if (!oldEntry.equalsDeep(entry) || !item.getGroupNames().equals(oldItem.getGroupNames())) {
|
||||
updatedEntries.add(item.getUser());
|
||||
updatedEntries.add(item.getJid());
|
||||
} else {
|
||||
// Record the entry as unchanged, so that it doesn't end up as deleted entry
|
||||
unchangedEntries.add(item.getUser());
|
||||
unchangedEntries.add(item.getJid());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1181,7 +1182,7 @@ public final class Roster extends Manager {
|
|||
}
|
||||
|
||||
private void deleteEntry(Collection<Jid> deletedEntries, RosterEntry entry) {
|
||||
Jid user = entry.getUser();
|
||||
Jid user = entry.getJid();
|
||||
entries.remove(user);
|
||||
unfiledEntries.remove(entry);
|
||||
presenceMap.remove(user);
|
||||
|
@ -1393,7 +1394,7 @@ public final class Roster extends Manager {
|
|||
}
|
||||
|
||||
for (RosterPacket.Item item : validItems) {
|
||||
RosterEntry entry = new RosterEntry(item.getUser(), item.getName(),
|
||||
RosterEntry entry = new RosterEntry(item.getJid(), item.getName(),
|
||||
item.getItemType(), item.getItemStatus(), item.isApproved(), Roster.this, connection);
|
||||
addUpdateEntry(addedEntries, updatedEntries, unchangedEntries, item, entry);
|
||||
}
|
||||
|
@ -1401,7 +1402,7 @@ public final class Roster extends Manager {
|
|||
// Delete all entries which where not added or updated
|
||||
Set<Jid> toDelete = new HashSet<>();
|
||||
for (RosterEntry entry : entries.values()) {
|
||||
toDelete.add(entry.getUser());
|
||||
toDelete.add(entry.getJid());
|
||||
}
|
||||
toDelete.removeAll(addedEntries);
|
||||
toDelete.removeAll(updatedEntries);
|
||||
|
@ -1423,7 +1424,7 @@ public final class Roster extends Manager {
|
|||
// version we presented the server. So we simply load the roster from the store and
|
||||
// await possible further roster pushes.
|
||||
for (RosterPacket.Item item : rosterStore.getEntries()) {
|
||||
RosterEntry entry = new RosterEntry(item.getUser(), item.getName(),
|
||||
RosterEntry entry = new RosterEntry(item.getJid(), item.getName(),
|
||||
item.getItemType(), item.getItemStatus(), item.isApproved(), Roster.this, connection);
|
||||
addUpdateEntry(addedEntries, updatedEntries, unchangedEntries, item, entry);
|
||||
}
|
||||
|
@ -1493,14 +1494,14 @@ public final class Roster extends Manager {
|
|||
// We assured above that the size of items is exaclty 1, therefore we are able to
|
||||
// safely retrieve this single item here.
|
||||
Item item = items.iterator().next();
|
||||
RosterEntry entry = new RosterEntry(item.getUser(), item.getName(),
|
||||
RosterEntry entry = new RosterEntry(item.getJid(), item.getName(),
|
||||
item.getItemType(), item.getItemStatus(), item.isApproved(), Roster.this, connection);
|
||||
String version = rosterPacket.getVersion();
|
||||
|
||||
if (item.getItemType().equals(RosterPacket.ItemType.remove)) {
|
||||
deleteEntry(deletedEntries, entry);
|
||||
if (rosterStore != null) {
|
||||
rosterStore.removeEntry(entry.getUser(), version);
|
||||
rosterStore.removeEntry(entry.getJid(), version);
|
||||
}
|
||||
}
|
||||
else if (hasValidSubscriptionType(item)) {
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.roster.packet.RosterPacket;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,7 @@ public final class RosterEntry extends Manager {
|
|||
/**
|
||||
* The JID of the entity/user.
|
||||
*/
|
||||
private final Jid user;
|
||||
private final BareJid jid;
|
||||
|
||||
private String name;
|
||||
private RosterPacket.ItemType type;
|
||||
|
@ -61,10 +61,10 @@ public final class RosterEntry extends Manager {
|
|||
* @param approved the pre-approval flag.
|
||||
* @param connection a connection to the XMPP server.
|
||||
*/
|
||||
RosterEntry(Jid user, String name, RosterPacket.ItemType type,
|
||||
RosterEntry(BareJid user, String name, RosterPacket.ItemType type,
|
||||
RosterPacket.ItemStatus status, boolean approved, Roster roster, XMPPConnection connection) {
|
||||
super(connection);
|
||||
this.user = user;
|
||||
this.jid = user;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.status = status;
|
||||
|
@ -76,9 +76,20 @@ public final class RosterEntry extends Manager {
|
|||
* Returns the JID of the user associated with this entry.
|
||||
*
|
||||
* @return the user associated with this entry.
|
||||
* @deprecated use {@link #getJid()} instead.
|
||||
*/
|
||||
public Jid getUser() {
|
||||
return user;
|
||||
@Deprecated
|
||||
public String getUser() {
|
||||
return jid.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JID associated with this entry.
|
||||
*
|
||||
* @return the user associated with this entry.
|
||||
*/
|
||||
public BareJid getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,7 +195,7 @@ public final class RosterEntry extends Manager {
|
|||
if (name != null) {
|
||||
buf.append(name).append(": ");
|
||||
}
|
||||
buf.append(user);
|
||||
buf.append(jid);
|
||||
Collection<RosterGroup> groups = getGroups();
|
||||
if (!groups.isEmpty()) {
|
||||
buf.append(" [");
|
||||
|
@ -203,7 +214,7 @@ public final class RosterEntry extends Manager {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (user == null ? 0 : user.hashCode());
|
||||
return (jid == null ? 0 : jid.hashCode());
|
||||
}
|
||||
|
||||
public boolean equals(Object object) {
|
||||
|
@ -211,7 +222,7 @@ public final class RosterEntry extends Manager {
|
|||
return true;
|
||||
}
|
||||
if (object != null && object instanceof RosterEntry) {
|
||||
return user.equals(((RosterEntry)object).getUser());
|
||||
return jid.equals(((RosterEntry)object).getUser());
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
@ -253,11 +264,11 @@ public final class RosterEntry extends Manager {
|
|||
}
|
||||
else if (!type.equals(other.type))
|
||||
return false;
|
||||
if (user == null) {
|
||||
if (other.user != null)
|
||||
if (jid == null) {
|
||||
if (other.jid != null)
|
||||
return false;
|
||||
}
|
||||
else if (!user.equals(other.user))
|
||||
else if (!jid.equals(other.jid))
|
||||
return false;
|
||||
if (approved != other.approved)
|
||||
return false;
|
||||
|
@ -269,7 +280,7 @@ public final class RosterEntry extends Manager {
|
|||
}
|
||||
|
||||
private static RosterPacket.Item toRosterItem(RosterEntry entry, String name) {
|
||||
RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), name);
|
||||
RosterPacket.Item item = new RosterPacket.Item(entry.getJid(), name);
|
||||
item.setItemType(entry.getType());
|
||||
item.setItemStatus(entry.getStatus());
|
||||
item.setApproved(entry.isApproved());
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jivesoftware.smack.roster;
|
|||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
|
@ -30,7 +29,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.roster.packet.RosterPacket;
|
||||
import org.jxmpp.util.XmppStringUtils;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* A group of roster entries.
|
||||
|
@ -120,17 +119,16 @@ public class RosterGroup {
|
|||
* @param user the XMPP address of the user (eg "jsmith@example.com").
|
||||
* @return the roster entry or <tt>null</tt> if it does not exist in the group.
|
||||
*/
|
||||
public RosterEntry getEntry(String user) {
|
||||
public RosterEntry getEntry(Jid user) {
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
// Roster entries never include a resource so remove the resource
|
||||
// if it's a part of the XMPP address.
|
||||
user = XmppStringUtils.parseBareJid(user);
|
||||
String userLowerCase = user.toLowerCase(Locale.US);
|
||||
user = user.withoutResource();
|
||||
synchronized (entries) {
|
||||
for (RosterEntry entry : entries) {
|
||||
if (entry.getUser().equals(userLowerCase)) {
|
||||
if (entry.getJid().equals(user)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +154,7 @@ public class RosterGroup {
|
|||
* @param user the XMPP address of the user.
|
||||
* @return true if the XMPP address is an entry in this group.
|
||||
*/
|
||||
public boolean contains(String user) {
|
||||
public boolean contains(Jid user) {
|
||||
return getEntry(user) != null;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,9 @@ package org.jivesoftware.smack.roster.packet;
|
|||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -107,7 +108,7 @@ public class RosterPacket extends IQ {
|
|||
|
||||
public static final String GROUP = "group";
|
||||
|
||||
private final Jid user;
|
||||
private final BareJid jid;
|
||||
private String name;
|
||||
private ItemType itemType;
|
||||
private ItemStatus itemStatus;
|
||||
|
@ -117,11 +118,11 @@ public class RosterPacket extends IQ {
|
|||
/**
|
||||
* Creates a new roster item.
|
||||
*
|
||||
* @param user the user.
|
||||
* @param jid the jid.
|
||||
* @param name the user's name.
|
||||
*/
|
||||
public Item(Jid user, String name) {
|
||||
this.user = user;
|
||||
public Item(BareJid jid, String name) {
|
||||
this.jid = Objects.requireNonNull(jid);
|
||||
this.name = name;
|
||||
itemType = null;
|
||||
itemStatus = null;
|
||||
|
@ -132,9 +133,20 @@ public class RosterPacket extends IQ {
|
|||
* Returns the user.
|
||||
*
|
||||
* @return the user.
|
||||
* @deprecated use {@link #getJid()} instead.
|
||||
*/
|
||||
public Jid getUser() {
|
||||
return user;
|
||||
@Deprecated
|
||||
public String getUser() {
|
||||
return jid.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JID of this item.
|
||||
*
|
||||
* @return the JID.
|
||||
*/
|
||||
public BareJid getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -240,7 +252,7 @@ public class RosterPacket extends IQ {
|
|||
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.halfOpenElement(Stanza.ITEM).attribute("jid", user);
|
||||
xml.halfOpenElement(Stanza.ITEM).attribute("jid", jid);
|
||||
xml.optAttribute("name", name);
|
||||
xml.optAttribute("subscription", itemType);
|
||||
xml.optAttribute("ask", itemStatus);
|
||||
|
@ -262,7 +274,7 @@ public class RosterPacket extends IQ {
|
|||
result = prime * result + ((itemStatus == null) ? 0 : itemStatus.hashCode());
|
||||
result = prime * result + ((itemType == null) ? 0 : itemType.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((user == null) ? 0 : user.hashCode());
|
||||
result = prime * result + ((jid == null) ? 0 : jid.hashCode());
|
||||
result = prime * result + ((approved == false) ? 0 : 1);
|
||||
return result;
|
||||
}
|
||||
|
@ -292,11 +304,11 @@ public class RosterPacket extends IQ {
|
|||
}
|
||||
else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (user == null) {
|
||||
if (other.user != null)
|
||||
if (jid == null) {
|
||||
if (other.jid != null)
|
||||
return false;
|
||||
}
|
||||
else if (!user.equals(other.user))
|
||||
else if (!jid.equals(other.jid))
|
||||
return false;
|
||||
if (approved != other.approved)
|
||||
return false;
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.jivesoftware.smack.SmackException;
|
|||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.roster.packet.RosterPacket;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
@ -49,7 +49,7 @@ public class RosterPacketProvider extends IQProvider<RosterPacket> {
|
|||
case "item":
|
||||
String jidString = parser.getAttributeValue("", "jid");
|
||||
String name = parser.getAttributeValue("", "name");
|
||||
Jid jid = JidCreate.from(jidString);
|
||||
BareJid jid = JidCreate.bareFrom(jidString);
|
||||
// Create packet.
|
||||
item = new RosterPacket.Item(jid, name);
|
||||
// Set status.
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.jivesoftware.smack.roster.packet.RosterPacket.Item;
|
|||
import org.jivesoftware.smack.util.FileUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smack.util.stringencoder.Base32;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
@ -184,7 +185,7 @@ public final class DirectoryRosterStore implements RosterStore {
|
|||
}
|
||||
|
||||
String parserName;
|
||||
Jid user = null;
|
||||
BareJid user = null;
|
||||
String name = null;
|
||||
String type = null;
|
||||
String status = null;
|
||||
|
@ -207,7 +208,7 @@ public final class DirectoryRosterStore implements RosterStore {
|
|||
}
|
||||
else if (parserName.equals("user")) {
|
||||
parser.next();
|
||||
user = JidCreate.from(parser.getText());
|
||||
user = JidCreate.bareFrom(parser.getText());
|
||||
}
|
||||
else if (parserName.equals("name")) {
|
||||
parser.next();
|
||||
|
@ -291,7 +292,7 @@ public final class DirectoryRosterStore implements RosterStore {
|
|||
private boolean addEntryRaw (Item item) {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
xml.openElement("item");
|
||||
xml.element("user", item.getUser());
|
||||
xml.element("user", item.getJid());
|
||||
xml.optElement("name", item.getName());
|
||||
xml.optElement("type", item.getItemType());
|
||||
xml.optElement("status", item.getItemStatus());
|
||||
|
@ -303,7 +304,7 @@ public final class DirectoryRosterStore implements RosterStore {
|
|||
}
|
||||
xml.closeElement("item");
|
||||
|
||||
return FileUtils.writeFile(getBareJidFile(item.getUser()), xml.toString());
|
||||
return FileUtils.writeFile(getBareJidFile(item.getJid()), xml.toString());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.jivesoftware.smack.util.PacketParserUtils;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
@ -133,7 +134,7 @@ public class RosterTest extends InitSmackIm {
|
|||
@Test
|
||||
public void testAddRosterItem() throws Throwable {
|
||||
// Constants for the new contact
|
||||
final Jid contactJID = JidCreate.from("nurse@example.com");
|
||||
final BareJid contactJID = JidCreate.bareFrom("nurse@example.com");
|
||||
final String contactName = "Nurse";
|
||||
final String[] contactGroup = {"Servants"};
|
||||
|
||||
|
@ -146,9 +147,9 @@ public class RosterTest extends InitSmackIm {
|
|||
final RosterUpdateResponder serverSimulator = new RosterUpdateResponder() {
|
||||
void verifyUpdateRequest(final RosterPacket updateRequest) {
|
||||
final Item item = updateRequest.getRosterItems().iterator().next();
|
||||
assertSame("The provided JID doesn't match the requested!",
|
||||
assertEquals("The provided JID doesn't match the requested!",
|
||||
contactJID,
|
||||
item.getUser());
|
||||
item.getJid());
|
||||
assertSame("The provided name doesn't match the requested!",
|
||||
contactName,
|
||||
item.getName());
|
||||
|
@ -217,9 +218,9 @@ public class RosterTest extends InitSmackIm {
|
|||
final RosterUpdateResponder serverSimulator = new RosterUpdateResponder() {
|
||||
void verifyUpdateRequest(final RosterPacket updateRequest) {
|
||||
final Item item = updateRequest.getRosterItems().iterator().next();
|
||||
assertSame("The provided JID doesn't match the requested!",
|
||||
assertEquals("The provided JID doesn't match the requested!",
|
||||
contactJID,
|
||||
item.getUser());
|
||||
item.getJid());
|
||||
assertSame("The provided name doesn't match the requested!",
|
||||
contactName,
|
||||
item.getName());
|
||||
|
@ -290,9 +291,9 @@ public class RosterTest extends InitSmackIm {
|
|||
final RosterUpdateResponder serverSimulator = new RosterUpdateResponder() {
|
||||
void verifyUpdateRequest(final RosterPacket updateRequest) {
|
||||
final Item item = updateRequest.getRosterItems().iterator().next();
|
||||
assertSame("The provided JID doesn't match the requested!",
|
||||
assertEquals("The provided JID doesn't match the requested!",
|
||||
contactJID,
|
||||
item.getUser());
|
||||
item.getJid());
|
||||
}
|
||||
};
|
||||
serverSimulator.start();
|
||||
|
@ -370,7 +371,7 @@ public class RosterTest extends InitSmackIm {
|
|||
*/
|
||||
@Test
|
||||
public void testIgnoreInvalidFrom() throws XmppStringprepException {
|
||||
final Jid spammerJid = JidCreate.from("spam@example.com");
|
||||
final BareJid spammerJid = JidCreate.bareFrom("spam@example.com");
|
||||
RosterPacket packet = new RosterPacket();
|
||||
packet.setType(Type.set);
|
||||
packet.setTo(connection.getUser());
|
||||
|
@ -398,7 +399,7 @@ public class RosterTest extends InitSmackIm {
|
|||
@Test(timeout=5000)
|
||||
public void testAddEmptyGroupEntry() throws Throwable {
|
||||
// Constants for the new contact
|
||||
final Jid contactJID = JidCreate.from("nurse@example.com");
|
||||
final BareJid contactJID = JidCreate.bareFrom("nurse@example.com");
|
||||
final String contactName = "Nurse";
|
||||
final String[] contactGroup = {""};
|
||||
|
||||
|
@ -413,7 +414,7 @@ public class RosterTest extends InitSmackIm {
|
|||
final Item item = updateRequest.getRosterItems().iterator().next();
|
||||
assertSame("The provided JID doesn't match the requested!",
|
||||
contactJID,
|
||||
item.getUser());
|
||||
item.getJid());
|
||||
assertSame("The provided name doesn't match the requested!",
|
||||
contactName,
|
||||
item.getName());
|
||||
|
@ -518,7 +519,7 @@ public class RosterTest extends InitSmackIm {
|
|||
rosterPush.setTo(connection.getUser());
|
||||
|
||||
// prepare the buddy's item entry which should be removed
|
||||
final RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName());
|
||||
final RosterPacket.Item item = new RosterPacket.Item(entry.getJid(), entry.getName());
|
||||
item.setItemType(ItemType.remove);
|
||||
rosterPush.addRosterItem(item);
|
||||
|
||||
|
@ -555,18 +556,18 @@ public class RosterTest extends InitSmackIm {
|
|||
rosterResult.setStanzaId(rosterRequest.getStanzaId());
|
||||
|
||||
// prepare romeo's roster entry
|
||||
final Item romeo = new Item(JidCreate.from("romeo@example.net"), "Romeo");
|
||||
final Item romeo = new Item(JidCreate.bareFrom("romeo@example.net"), "Romeo");
|
||||
romeo.addGroupName("Friends");
|
||||
romeo.setItemType(ItemType.both);
|
||||
rosterResult.addRosterItem(romeo);
|
||||
|
||||
// prepare mercutio's roster entry
|
||||
final Item mercutio = new Item(JidCreate.from("mercutio@example.com"), "Mercutio");
|
||||
final Item mercutio = new Item(JidCreate.bareFrom("mercutio@example.com"), "Mercutio");
|
||||
mercutio.setItemType(ItemType.from);
|
||||
rosterResult.addRosterItem(mercutio);
|
||||
|
||||
// prepare benvolio's roster entry
|
||||
final Item benvolio = new Item(JidCreate.from("benvolio@example.net"), "Benvolio");
|
||||
final Item benvolio = new Item(JidCreate.bareFrom("benvolio@example.net"), "Benvolio");
|
||||
benvolio.setItemType(ItemType.both);
|
||||
rosterResult.addRosterItem(benvolio);
|
||||
|
||||
|
|
|
@ -160,13 +160,13 @@ public class RosterVersioningTest {
|
|||
|
||||
Roster roster = Roster.getInstanceFor(connection);
|
||||
assertEquals("Size of roster", 1, roster.getEntries().size());
|
||||
RosterEntry entry = roster.getEntry(vaglafItem.getUser());
|
||||
RosterEntry entry = roster.getEntry(vaglafItem.getJid());
|
||||
assertNotNull("Roster contains vaglaf entry", entry);
|
||||
assertEquals("vaglaf entry in roster equals the sent entry", vaglafItem, RosterEntry.toRosterItem(entry));
|
||||
|
||||
RosterStore store = roster.getRosterStore();
|
||||
assertEquals("Size of store", 1, store.getEntries().size());
|
||||
Item item = store.getEntry(vaglafItem.getUser());
|
||||
Item item = store.getEntry(vaglafItem.getJid());
|
||||
assertNotNull("Store contains vaglaf entry");
|
||||
assertEquals("vaglaf entry in store equals the sent entry", vaglafItem, item);
|
||||
}
|
||||
|
@ -214,20 +214,20 @@ public class RosterVersioningTest {
|
|||
rosterPush.setType(Type.set);
|
||||
rosterPush.setVersion("v98");
|
||||
|
||||
Item item = new Item(JidCreate.from("vaglaf@example.com"), "vaglaf the only");
|
||||
Item item = new Item(JidCreate.bareFrom("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(JidCreate.from("vaglaf@example.com")));
|
||||
assertNull("Store doses not contain vaglaf", store.getEntry(JidCreate.bareFrom("vaglaf@example.com")));
|
||||
assertEquals("Expect store version after push", "v98", store.getRosterVersion());
|
||||
}
|
||||
}
|
||||
|
||||
private static Item vaglafItem() throws XmppStringprepException {
|
||||
Item item = new Item(JidCreate.from("vaglaf@example.com"), "vaglaf the only");
|
||||
Item item = new Item(JidCreate.bareFrom("vaglaf@example.com"), "vaglaf the only");
|
||||
item.setItemType(ItemType.both);
|
||||
item.addGroupName("all");
|
||||
item.addGroupName("friends");
|
||||
|
@ -236,14 +236,14 @@ public class RosterVersioningTest {
|
|||
}
|
||||
|
||||
private static void populateStore(RosterStore store) throws IOException {
|
||||
store.addEntry(new RosterPacket.Item(JidCreate.from("geoff@example.com"), "geoff hurley"), "");
|
||||
store.addEntry(new RosterPacket.Item(JidCreate.bareFrom("geoff@example.com"), "geoff hurley"), "");
|
||||
|
||||
RosterPacket.Item item = new RosterPacket.Item(JidCreate.from("joe@example.com"), "joe stevens");
|
||||
RosterPacket.Item item = new RosterPacket.Item(JidCreate.bareFrom("joe@example.com"), "joe stevens");
|
||||
item.addGroupName("friends");
|
||||
item.addGroupName("partners");
|
||||
store.addEntry(item, "");
|
||||
|
||||
item = new RosterPacket.Item(JidCreate.from("higgins@example.com"), "higgins mcmann");
|
||||
item = new RosterPacket.Item(JidCreate.bareFrom("higgins@example.com"), "higgins mcmann");
|
||||
item.addGroupName("all");
|
||||
item.addGroupName("friends");
|
||||
store.addEntry(item, "v96");
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.jivesoftware.smack.roster.packet.SubscriptionPreApproval;
|
|||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
|
@ -77,7 +78,7 @@ public class SubscriptionPreApprovalTest extends InitSmackIm {
|
|||
|
||||
@Test
|
||||
public void testPreApproveAndCreate() throws Throwable {
|
||||
final Jid contactJID = JidCreate.from("preapproval@example.com");
|
||||
final BareJid contactJID = JidCreate.bareFrom("preapproval@example.com");
|
||||
final String contactName = "PreApproval";
|
||||
final String[] contactGroup = {};
|
||||
connection.enableStreamFeature(SubscriptionPreApproval.INSTANCE);
|
||||
|
@ -88,7 +89,7 @@ public class SubscriptionPreApprovalTest extends InitSmackIm {
|
|||
final Item item = updateRequest.getRosterItems().iterator().next();
|
||||
assertSame("The provided JID doesn't match the requested!",
|
||||
contactJID,
|
||||
item.getUser());
|
||||
item.getJid());
|
||||
assertSame("The provided name doesn't match the requested!",
|
||||
contactName,
|
||||
item.getName());
|
||||
|
|
|
@ -34,7 +34,7 @@ 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.BareJid;
|
||||
import org.jxmpp.jid.JidTestUtil;
|
||||
|
||||
/**
|
||||
|
@ -88,7 +88,7 @@ public class DirectoryRosterStoreTest {
|
|||
|
||||
assertEquals("Initial roster version", "", store.getRosterVersion());
|
||||
|
||||
Jid userName = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
|
||||
BareJid userName = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
|
||||
|
||||
final RosterPacket.Item item1 = new Item(userName, null);
|
||||
final String version1 = "1";
|
||||
|
@ -99,7 +99,7 @@ public class DirectoryRosterStoreTest {
|
|||
RosterPacket.Item storedItem = store.getEntry(userName);
|
||||
assertNotNull("Added entry not found found", storedItem);
|
||||
assertEquals("User of added entry",
|
||||
item1.getUser(), storedItem.getUser());
|
||||
item1.getJid(), storedItem.getJid());
|
||||
assertEquals("Name of added entry",
|
||||
item1.getName(), storedItem.getName());
|
||||
assertEquals("Groups", item1.getGroupNames(), storedItem.getGroupNames());
|
||||
|
@ -123,7 +123,7 @@ public class DirectoryRosterStoreTest {
|
|||
storedItem = store.getEntry(userName);
|
||||
assertNotNull("Added entry not found", storedItem);
|
||||
assertEquals("User of added entry",
|
||||
item2.getUser(), storedItem.getUser());
|
||||
item2.getJid(), storedItem.getJid());
|
||||
assertEquals("Name of added entry",
|
||||
item2.getName(), storedItem.getName());
|
||||
assertEquals("Groups", item2.getGroupNames(), storedItem.getGroupNames());
|
||||
|
@ -160,7 +160,7 @@ public class DirectoryRosterStoreTest {
|
|||
storedItem = store.getEntry(JidTestUtil.BARE_JID_1);
|
||||
assertNotNull("Added entry not found", storedItem);
|
||||
assertEquals("User of added entry",
|
||||
item3.getUser(), storedItem.getUser());
|
||||
item3.getJid(), storedItem.getJid());
|
||||
assertEquals("Name of added entry",
|
||||
item3.getName(), storedItem.getName());
|
||||
assertEquals("Groups", item3.getGroupNames(), storedItem.getGroupNames());
|
||||
|
@ -175,7 +175,7 @@ public class DirectoryRosterStoreTest {
|
|||
storedItem = store.getEntry(JidTestUtil.BARE_JID_2);
|
||||
assertNotNull("Added entry not found", storedItem);
|
||||
assertEquals("User of added entry",
|
||||
item4.getUser(), storedItem.getUser());
|
||||
item4.getJid(), storedItem.getJid());
|
||||
assertEquals("Name of added entry",
|
||||
item4.getName(), storedItem.getName());
|
||||
assertEquals("Groups", item4.getGroupNames(), storedItem.getGroupNames());
|
||||
|
|
|
@ -87,7 +87,7 @@ public class RosterExchange implements ExtensionElement {
|
|||
groupNames = groupNamesList.toArray(new String[groupNamesList.size()]);
|
||||
|
||||
// Create a new Entry based on the rosterEntry and add it to the packet
|
||||
RemoteRosterEntry remoteRosterEntry = new RemoteRosterEntry(rosterEntry.getUser(),
|
||||
RemoteRosterEntry remoteRosterEntry = new RemoteRosterEntry(rosterEntry.getJid(),
|
||||
rosterEntry.getName(), groupNames);
|
||||
|
||||
addRosterEntry(remoteRosterEntry);
|
||||
|
|
Loading…
Reference in a new issue