1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 05:52:06 +01:00

Bump jxmpp to 0.5.0-alpha5 and change Roster API

to only allow bare JIDs as roster entires.
This commit is contained in:
Florian Schmaus 2015-06-06 09:00:19 +02:00
parent 2f219c7317
commit 58402c5615
16 changed files with 111 additions and 114 deletions

View file

@ -48,7 +48,7 @@ public class FromMatchesFilter implements StanzaFilter {
*/ */
public FromMatchesFilter(Jid address, boolean ignoreResourcepart) { public FromMatchesFilter(Jid address, boolean ignoreResourcepart) {
if (address != null && ignoreResourcepart) { if (address != null && ignoreResourcepart) {
this.address = address.withoutResource(); this.address = address.asBareJid();
} }
else { else {
this.address = address; this.address = address;
@ -99,7 +99,7 @@ public class FromMatchesFilter implements StanzaFilter {
} }
if (ignoreResourcepart) { if (ignoreResourcepart) {
from = from.withoutResource(); from = from.asBareJid();
} }
return from.equals(address); return from.equals(address);
} }

View file

@ -44,7 +44,7 @@ public class BindIQProvider extends IQProvider<Bind> {
bind = Bind.newSet(Resourcepart.from(resourceString)); bind = Bind.newSet(Resourcepart.from(resourceString));
break; break;
case "jid": case "jid":
EntityFullJid fullJid = JidCreate.fullFrom(parser.nextText()); EntityFullJid fullJid = JidCreate.entityFullFrom(parser.nextText());
bind = Bind.newResult(fullJid); bind = Bind.newResult(fullJid);
break; break;
} }

View file

@ -76,7 +76,7 @@ public class ParserUtils {
if (jidString == null) { if (jidString == null) {
return null; return null;
} }
return JidCreate.bareFrom(jidString); return JidCreate.entityBareFrom(jidString);
} }
public static Resourcepart getResourcepartAttribute(XmlPullParser parser, String name) throws XmppStringprepException { public static Resourcepart getResourcepartAttribute(XmlPullParser parser, String name) throws XmppStringprepException {

View file

@ -67,7 +67,7 @@ public class DummyConnection extends AbstractXMPPConnection {
private EntityFullJid getUserJid() { private EntityFullJid getUserJid() {
try { try {
return JidCreate.fullFrom(config.getUsername() return JidCreate.entityFullFrom(config.getUsername()
+ "@" + "@"
+ config.getXMPPServiceDomain() + config.getXMPPServiceDomain()
+ "/" + "/"

View file

@ -180,7 +180,7 @@ public class MultipleRecipientManager {
// Remove the sender from the TO/CC list (try with bare JID too) // Remove the sender from the TO/CC list (try with bare JID too)
EntityFullJid from = connection.getUser(); EntityFullJid from = connection.getUser();
if (!to.remove(from) && !cc.remove(from)) { if (!to.remove(from) && !cc.remove(from)) {
EntityBareJid bareJID = from.asBareJid(); EntityBareJid bareJID = from.asEntityBareJid();
to.remove(bareJID); to.remove(bareJID);
cc.remove(bareJID); cc.remove(bareJID);
} }

View file

@ -257,7 +257,7 @@ public final class ChatManager extends Manager{
Chat chat = new Chat(this, userJID, threadID); Chat chat = new Chat(this, userJID, threadID);
threadChats.put(threadID, chat); threadChats.put(threadID, chat);
jidChats.put(userJID, chat); jidChats.put(userJID, chat);
baseJidChats.put(userJID.asBareJid(), chat); baseJidChats.put(userJID.asEntityBareJid(), chat);
for(ChatManagerListener listener : chatManagerListeners) { for(ChatManagerListener listener : chatManagerListeners) {
listener.chatCreated(chat, createdLocally); listener.chatCreated(chat, createdLocally);
@ -270,7 +270,7 @@ public final class ChatManager extends Manager{
threadChats.remove(chat.getThreadID()); threadChats.remove(chat.getThreadID());
EntityJid userJID = chat.getParticipant(); EntityJid userJID = chat.getParticipant();
jidChats.remove(userJID); jidChats.remove(userJID);
baseJidChats.remove(userJID.withoutResource()); baseJidChats.remove(userJID.asEntityBareJid());
} }
/** /**

View file

@ -146,7 +146,7 @@ public final class Roster extends Manager {
* A map of JIDs to another Map of Resourceparts to Presences. The 'inner' map may contain * A map of JIDs to another Map of Resourceparts to Presences. The 'inner' map may contain
* {@link Resourcepart#EMPTY} if there are no other Presences available. * {@link Resourcepart#EMPTY} if there are no other Presences available.
*/ */
private final Map<Jid, Map<Resourcepart, Presence>> presenceMap = new ConcurrentHashMap<>(); private final Map<BareJid, Map<Resourcepart, Presence>> presenceMap = new ConcurrentHashMap<>();
/** /**
* Listeners called when the Roster was loaded. * Listeners called when the Roster was loaded.
@ -698,28 +698,27 @@ public final class Roster extends Manager {
* Returns the roster entry associated with the given XMPP address or * Returns the roster entry associated with the given XMPP address or
* <tt>null</tt> if the user is not an entry in the roster. * <tt>null</tt> if the user is not an entry in the roster.
* *
* @param user the XMPP address of the user (eg "jsmith@example.com"). The address could be * @param jid the XMPP address of the user (eg "jsmith@example.com"). The address could be
* in any valid format (e.g. "domain/resource", "user@domain" or "user@domain/resource"). * in any valid format (e.g. "domain/resource", "user@domain" or "user@domain/resource").
* @return the roster entry or <tt>null</tt> if it does not exist. * @return the roster entry or <tt>null</tt> if it does not exist.
*/ */
public RosterEntry getEntry(Jid user) { public RosterEntry getEntry(BareJid jid) {
if (user == null) { if (jid == null) {
return null; return null;
} }
Jid key = getMapKey(user); return entries.get(jid);
return entries.get(key);
} }
/** /**
* Returns true if the specified XMPP address is an entry in the roster. * Returns true if the specified XMPP address is an entry in the roster.
* *
* @param user the XMPP address of the user (eg "jsmith@example.com"). The * @param jid the XMPP address of the user (eg "jsmith@example.com"). The
* address could be in any valid format (e.g. "domain/resource", * address must be a bare JID e.g. "domain/resource" or
* "user@domain" or "user@domain/resource"). * "user@domain".
* @return true if the XMPP address is an entry in the roster. * @return true if the XMPP address is an entry in the roster.
*/ */
public boolean contains(Jid user) { public boolean contains(BareJid jid) {
return getEntry(user) != null; return getEntry(jid) != null;
} }
/** /**
@ -775,18 +774,17 @@ public final class Roster extends Manager {
* {@link RosterListener}. * {@link RosterListener}.
* </p> * </p>
* *
* @param user an XMPP ID. The address could be in any valid format (e.g. * @param jid the XMPP address of the user (eg "jsmith@example.com"). The
* "domain/resource", "user@domain" or "user@domain/resource"). Any resource * address must be a bare JID e.g. "domain/resource" or
* information that's part of the ID will be discarded. * "user@domain".
* @return the user's current presence, or unavailable presence if the user is offline * @return the user's current presence, or unavailable presence if the user is offline
* or if no presence information is available.. * or if no presence information is available..
*/ */
public Presence getPresence(Jid user) { public Presence getPresence(Jid jid) {
Jid key = getMapKey(user); Map<Resourcepart, Presence> userPresences = presenceMap.get(jid);
Map<Resourcepart, Presence> userPresences = presenceMap.get(key);
if (userPresences == null) { if (userPresences == null) {
Presence presence = new Presence(Presence.Type.unavailable); Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user); presence.setFrom(jid);
return presence; return presence;
} }
else { else {
@ -829,7 +827,7 @@ public final class Roster extends Manager {
} }
else { else {
presence = new Presence(Presence.Type.unavailable); presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user); presence.setFrom(jid);
return presence; return presence;
} }
} }
@ -849,7 +847,7 @@ public final class Roster extends Manager {
* or if no presence information is available. * or if no presence information is available.
*/ */
public Presence getPresenceResource(FullJid userWithResource) { public Presence getPresenceResource(FullJid userWithResource) {
Jid key = getMapKey(userWithResource); BareJid key = userWithResource.asBareJid();
Resourcepart resource = userWithResource.getResourcepart(); Resourcepart resource = userWithResource.getResourcepart();
Map<Resourcepart, Presence> userPresences = presenceMap.get(key); Map<Resourcepart, Presence> userPresences = presenceMap.get(key);
if (userPresences == null) { if (userPresences == null) {
@ -878,8 +876,8 @@ public final class Roster extends Manager {
* @return a List of Presence objects for all the user's current presences, or an unavailable presence if no * @return a List of Presence objects for all the user's current presences, or an unavailable presence if no
* presence information is available. * presence information is available.
*/ */
public List<Presence> getAllPresences(Jid bareJid) { public List<Presence> getAllPresences(BareJid bareJid) {
Map<Resourcepart, Presence> userPresences = presenceMap.get(getMapKey(bareJid)); Map<Resourcepart, Presence> userPresences = presenceMap.get(bareJid);
List<Presence> res; List<Presence> res;
if (userPresences == null) { if (userPresences == null) {
// Create an unavailable presence if none was found // Create an unavailable presence if none was found
@ -902,7 +900,7 @@ public final class Roster extends Manager {
* @param bareJid the bare JID from which the presences should be retrieved. * @param bareJid the bare JID from which the presences should be retrieved.
* @return available presences for the bare JID. * @return available presences for the bare JID.
*/ */
public List<Presence> getAvailablePresences(Jid bareJid) { public List<Presence> getAvailablePresences(BareJid bareJid) {
List<Presence> allPresences = getAllPresences(bareJid); List<Presence> allPresences = getAllPresences(bareJid);
List<Presence> res = new ArrayList<>(allPresences.size()); List<Presence> res = new ArrayList<>(allPresences.size());
for (Presence presence : allPresences) { for (Presence presence : allPresences) {
@ -920,18 +918,17 @@ public final class Roster extends Manager {
* information is available, such as when you are not subscribed to the user's presence * information is available, such as when you are not subscribed to the user's presence
* updates. * updates.
* *
* @param user an XMPP ID, e.g. jdoe@example.com. * @param jid an XMPP ID, e.g. jdoe@example.com.
* @return a List of Presence objects for all the user's current presences, * @return a List of Presence objects for all the user's current presences,
* or an unavailable presence if the user is offline or if no presence information * or an unavailable presence if the user is offline or if no presence information
* is available. * is available.
*/ */
public List<Presence> getPresences(Jid user) { public List<Presence> getPresences(BareJid jid) {
List<Presence> res; List<Presence> res;
Jid key = getMapKey(user); Map<Resourcepart, Presence> userPresences = presenceMap.get(jid);
Map<Resourcepart, Presence> userPresences = presenceMap.get(key);
if (userPresences == null) { if (userPresences == null) {
Presence presence = new Presence(Presence.Type.unavailable); Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user); presence.setFrom(jid);
res = Arrays.asList(presence); res = Arrays.asList(presence);
} }
else { else {
@ -954,7 +951,7 @@ public final class Roster extends Manager {
} }
else { else {
Presence presence = new Presence(Presence.Type.unavailable); Presence presence = new Presence(Presence.Type.unavailable);
presence.setFrom(user); presence.setFrom(jid);
res = Arrays.asList(presence); res = Arrays.asList(presence);
} }
} }
@ -976,10 +973,14 @@ public final class Roster extends Manager {
* @since 4.1 * @since 4.1
*/ */
public boolean isSubscribedToMyPresence(Jid jid) { public boolean isSubscribedToMyPresence(Jid jid) {
if (connection().getXMPPServiceDomain().equals(jid)) { if (jid == null) {
return false;
}
BareJid bareJid = jid.asBareJid();
if (connection().getXMPPServiceDomain().equals(bareJid)) {
return true; return true;
} }
RosterEntry entry = getEntry(jid); RosterEntry entry = getEntry(bareJid);
if (entry == null) { if (entry == null) {
return false; return false;
} }
@ -1019,34 +1020,6 @@ public final class Roster extends Manager {
return rosterStore; return rosterStore;
} }
/**
* Returns the key to use in the presenceMap and entries Map for a fully qualified XMPP ID.
* The roster can contain any valid address format such us "domain/resource",
* "user@domain" or "user@domain/resource". If the roster contains an entry
* associated with the fully qualified XMPP ID then use the fully qualified XMPP
* ID as the key in presenceMap, otherwise use the bare address. Note: When the
* key in presenceMap is a fully qualified XMPP ID, the userPresences is useless
* since it will always contain one entry for the user.
*
* @param user the bare or fully qualified XMPP ID, e.g. jdoe@example.com or
* jdoe@example.com/Work.
* @return the key to use in the presenceMap and entries Map for the fully qualified XMPP ID.
*/
private Jid getMapKey(Jid user) {
if (user == null) {
return null;
}
if (entries.containsKey(user)) {
return user;
}
EntityBareJid bareJid = user.asEntityBareJidIfPossible();
if (bareJid != null) {
return bareJid;
}
// jid validate, log this case?
return user;
}
/** /**
* Changes the presence of available contacts offline by simulating an unavailable * Changes the presence of available contacts offline by simulating an unavailable
* presence sent from the server. After a disconnection, every Presence is set * presence sent from the server. After a disconnection, every Presence is set
@ -1280,7 +1253,7 @@ public final class Roster extends Manager {
* @param key the presence map key * @param key the presence map key
* @return the user presences * @return the user presences
*/ */
private Map<Resourcepart, Presence> getUserPresences(Jid key) { private Map<Resourcepart, Presence> getUserPresences(BareJid key) {
Map<Resourcepart, Presence> userPresences = presenceMap.get(key); Map<Resourcepart, Presence> userPresences = presenceMap.get(key);
if (userPresences == null) { if (userPresences == null) {
userPresences = new ConcurrentHashMap<>(); userPresences = new ConcurrentHashMap<>();
@ -1300,7 +1273,7 @@ public final class Roster extends Manager {
fromResource = Resourcepart.EMPTY; fromResource = Resourcepart.EMPTY;
} }
} }
Jid key = getMapKey(from); BareJid key = from != null ? from.asBareJid() : null;
Map<Resourcepart, Presence> userPresences; Map<Resourcepart, Presence> userPresences;
// If an "available" presence, add it to the presence map. Each presence // If an "available" presence, add it to the presence map. Each presence
@ -1471,7 +1444,7 @@ public final class Roster extends Manager {
// Roster push (RFC 6121, 2.1.6) // Roster push (RFC 6121, 2.1.6)
// A roster push with a non-empty from not matching our address MUST be ignored // A roster push with a non-empty from not matching our address MUST be ignored
EntityBareJid jid = connection.getUser().asBareJid(); EntityBareJid jid = connection.getUser().asEntityBareJid();
Jid from = rosterPacket.getFrom(); Jid from = rosterPacket.getFrom();
if (from != null && !from.equals(jid)) { if (from != null && !from.equals(jid)) {
LOGGER.warning("Ignoring roster push with a non matching 'from' ourJid='" + jid + "' from='" + from LOGGER.warning("Ignoring roster push with a non matching 'from' ourJid='" + jid + "' from='" + from

View file

@ -124,7 +124,7 @@ public class RosterGroup extends Manager {
} }
// Roster entries never include a resource so remove the resource // Roster entries never include a resource so remove the resource
// if it's a part of the XMPP address. // if it's a part of the XMPP address.
user = user.withoutResource(); user = user.asBareJid();
synchronized (entries) { synchronized (entries) {
for (RosterEntry entry : entries) { for (RosterEntry entry : entries) {
if (entry.getJid().equals(user)) { if (entry.getJid().equals(user)) {

View file

@ -24,6 +24,7 @@ import org.jivesoftware.smack.roster.packet.RosterPacket;
import org.jivesoftware.smack.util.ParserUtils; import org.jivesoftware.smack.util.ParserUtils;
import org.jxmpp.jid.BareJid; import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.util.XmppStringUtils;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@ -49,7 +50,18 @@ public class RosterPacketProvider extends IQProvider<RosterPacket> {
case "item": case "item":
String jidString = parser.getAttributeValue("", "jid"); String jidString = parser.getAttributeValue("", "jid");
String name = parser.getAttributeValue("", "name"); String name = parser.getAttributeValue("", "name");
BareJid jid = JidCreate.bareFrom(jidString);
// workaround for bug in jxmpp 0.5.0-alpha5, where
// JidCreate.bareFrom(String), which we would want to use
// here, does not produce correct results
String localpart = XmppStringUtils.parseLocalpart(jidString);
BareJid jid;
if (localpart.length() != 0) {
jid = JidCreate.entityBareFrom(jidString);
} else {
jid = JidCreate.domainBareFrom(jidString);
}
// Create packet. // Create packet.
item = new RosterPacket.Item(jid, name); item = new RosterPacket.Item(jid, name);
// Set status. // Set status.

View file

@ -34,6 +34,7 @@ import org.jivesoftware.smack.util.stringencoder.Base32;
import org.jxmpp.jid.BareJid; import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.util.XmppStringUtils;
import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlPullParserFactory;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@ -208,7 +209,18 @@ public final class DirectoryRosterStore implements RosterStore {
} }
else if (parserName.equals("user")) { else if (parserName.equals("user")) {
parser.next(); parser.next();
user = JidCreate.bareFrom(parser.getText());
String jidString = parser.getText();
// workaround for bug in jxmpp 0.5.0-alpha5, where
// JidCreate.bareFrom(String), which we would want to
// use here, does not produce correct results
String localpart = XmppStringUtils.parseLocalpart(jidString);
if (localpart.length() != 0) {
user = JidCreate.entityBareFrom(jidString);
}
else {
user = JidCreate.domainBareFrom(jidString);
}
} }
else if (parserName.equals("name")) { else if (parserName.equals("name")) {
parser.next(); parser.next();

View file

@ -106,9 +106,9 @@ public class RosterTest extends InitSmackIm {
// Verify roster // Verify roster
assertTrue("Roster can't be loaded!", roster.waitUntilLoaded()); assertTrue("Roster can't be loaded!", roster.waitUntilLoaded());
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net"))); verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net")));
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com")));
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net")));
assertSame("Wrong number of roster entries.", 3, roster.getEntries().size()); assertSame("Wrong number of roster entries.", 3, roster.getEntries().size());
// Verify roster listener // Verify roster listener
@ -134,7 +134,7 @@ public class RosterTest extends InitSmackIm {
@Test @Test
public void testAddRosterItem() throws Throwable { public void testAddRosterItem() throws Throwable {
// Constants for the new contact // Constants for the new contact
final BareJid contactJID = JidCreate.bareFrom("nurse@example.com"); final BareJid contactJID = JidCreate.entityBareFrom("nurse@example.com");
final String contactName = "Nurse"; final String contactName = "Nurse";
final String[] contactGroup = {"Servants"}; final String[] contactGroup = {"Servants"};
@ -191,9 +191,9 @@ public class RosterTest extends InitSmackIm {
addedEntry.getGroups().iterator().next().getName()); addedEntry.getGroups().iterator().next().getName());
// Verify the unchanged roster items // Verify the unchanged roster items
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net"))); verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net")));
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com")));
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net")));
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size()); assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
} }
@ -205,7 +205,7 @@ public class RosterTest extends InitSmackIm {
@Test @Test
public void testUpdateRosterItem() throws Throwable { public void testUpdateRosterItem() throws Throwable {
// Constants for the updated contact // Constants for the updated contact
final Jid contactJID = JidCreate.from("romeo@example.net"); final BareJid contactJID = JidCreate.entityBareFrom("romeo@example.net");
final String contactName = "Romeo"; final String contactName = "Romeo";
final String[] contactGroups = {"Friends", "Lovers"}; final String[] contactGroups = {"Friends", "Lovers"};
@ -265,8 +265,8 @@ public class RosterTest extends InitSmackIm {
addedEntry.getGroups().size()); addedEntry.getGroups().size());
// Verify the unchanged roster items // Verify the unchanged roster items
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com")));
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net")));
assertSame("Wrong number of roster entries (" + roster.getEntries() + ").", assertSame("Wrong number of roster entries (" + roster.getEntries() + ").",
3, 3,
roster.getEntries().size()); roster.getEntries().size());
@ -280,7 +280,7 @@ public class RosterTest extends InitSmackIm {
@Test @Test
public void testDeleteRosterItem() throws Throwable { public void testDeleteRosterItem() throws Throwable {
// The contact which should be deleted // The contact which should be deleted
final Jid contactJID = JidCreate.from("romeo@example.net"); final BareJid contactJID = JidCreate.entityBareFrom("romeo@example.net");
// Setup // Setup
assertNotNull("Can't get the roster from the provided connection!", roster); assertNotNull("Can't get the roster from the provided connection!", roster);
@ -312,8 +312,8 @@ public class RosterTest extends InitSmackIm {
assertNull("The contact wasn't deleted from the roster!", deletedEntry); assertNull("The contact wasn't deleted from the roster!", deletedEntry);
assertTrue("The roster listener wasn't invoked for the deleted contact!", assertTrue("The roster listener wasn't invoked for the deleted contact!",
rosterListener.getDeletedAddresses().contains(contactJID)); rosterListener.getDeletedAddresses().contains(contactJID));
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com")));
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net")));
assertSame("Wrong number of roster entries (" + roster.getEntries() + ").", assertSame("Wrong number of roster entries (" + roster.getEntries() + ").",
2, 2,
roster.getEntries().size()); roster.getEntries().size());
@ -326,7 +326,7 @@ public class RosterTest extends InitSmackIm {
*/ */
@Test @Test
public void testSimpleRosterPush() throws Throwable { public void testSimpleRosterPush() throws Throwable {
final Jid contactJID = JidCreate.from("nurse@example.com"); final BareJid contactJID = JidCreate.entityBareFrom("nurse@example.com");
assertNotNull("Can't get the roster from the provided connection!", roster); assertNotNull("Can't get the roster from the provided connection!", roster);
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("<iq id=\"rostertest1\" type=\"set\" ") sb.append("<iq id=\"rostertest1\" type=\"set\" ")
@ -357,9 +357,9 @@ public class RosterTest extends InitSmackIm {
addedEntry.getGroups().size()); addedEntry.getGroups().size());
// Verify the unchanged roster items // Verify the unchanged roster items
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net"))); verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net")));
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com")));
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net")));
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size()); assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
} }
@ -371,11 +371,11 @@ public class RosterTest extends InitSmackIm {
*/ */
@Test @Test
public void testIgnoreInvalidFrom() throws XmppStringprepException { public void testIgnoreInvalidFrom() throws XmppStringprepException {
final BareJid spammerJid = JidCreate.bareFrom("spam@example.com"); final BareJid spammerJid = JidCreate.entityBareFrom("spam@example.com");
RosterPacket packet = new RosterPacket(); RosterPacket packet = new RosterPacket();
packet.setType(Type.set); packet.setType(Type.set);
packet.setTo(connection.getUser()); packet.setTo(connection.getUser());
packet.setFrom(JidCreate.from("mallory@example.com")); packet.setFrom(JidCreate.entityBareFrom("mallory@example.com"));
packet.addRosterItem(new Item(spammerJid, "Cool products!")); packet.addRosterItem(new Item(spammerJid, "Cool products!"));
final String requestId = packet.getStanzaId(); final String requestId = packet.getStanzaId();
@ -399,7 +399,7 @@ public class RosterTest extends InitSmackIm {
@Test(timeout=5000) @Test(timeout=5000)
public void testAddEmptyGroupEntry() throws Throwable { public void testAddEmptyGroupEntry() throws Throwable {
// Constants for the new contact // Constants for the new contact
final BareJid contactJID = JidCreate.bareFrom("nurse@example.com"); final BareJid contactJID = JidCreate.entityBareFrom("nurse@example.com");
final String contactName = "Nurse"; final String contactName = "Nurse";
final String[] contactGroup = {""}; final String[] contactGroup = {""};
@ -451,9 +451,9 @@ public class RosterTest extends InitSmackIm {
addedEntry.getGroups().size()); addedEntry.getGroups().size());
// Verify the unchanged roster items // Verify the unchanged roster items
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net"))); verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net")));
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com")));
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net")));
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size()); assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
} }
@ -465,7 +465,7 @@ public class RosterTest extends InitSmackIm {
*/ */
@Test @Test
public void testEmptyGroupRosterPush() throws Throwable { public void testEmptyGroupRosterPush() throws Throwable {
final Jid contactJID = JidCreate.from("nurse@example.com"); final BareJid contactJID = JidCreate.entityBareFrom("nurse@example.com");
assertNotNull("Can't get the roster from the provided connection!", roster); assertNotNull("Can't get the roster from the provided connection!", roster);
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("<iq id=\"rostertest2\" type=\"set\" ") sb.append("<iq id=\"rostertest2\" type=\"set\" ")
@ -498,9 +498,9 @@ public class RosterTest extends InitSmackIm {
addedEntry.getGroups().size()); addedEntry.getGroups().size());
// Verify the unchanged roster items // Verify the unchanged roster items
verifyRomeosEntry(roster.getEntry(JidCreate.from("romeo@example.net"))); verifyRomeosEntry(roster.getEntry(JidCreate.entityBareFrom("romeo@example.net")));
verifyMercutiosEntry(roster.getEntry(JidCreate.from("mercutio@example.com"))); verifyMercutiosEntry(roster.getEntry(JidCreate.entityBareFrom("mercutio@example.com")));
verifyBenvoliosEntry(roster.getEntry(JidCreate.from("benvolio@example.net"))); verifyBenvoliosEntry(roster.getEntry(JidCreate.entityBareFrom("benvolio@example.net")));
assertSame("Wrong number of roster entries.", 4, roster.getEntries().size()); assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
} }
@ -556,18 +556,18 @@ public class RosterTest extends InitSmackIm {
rosterResult.setStanzaId(rosterRequest.getStanzaId()); rosterResult.setStanzaId(rosterRequest.getStanzaId());
// prepare romeo's roster entry // prepare romeo's roster entry
final Item romeo = new Item(JidCreate.bareFrom("romeo@example.net"), "Romeo"); final Item romeo = new Item(JidCreate.entityBareFrom("romeo@example.net"), "Romeo");
romeo.addGroupName("Friends"); romeo.addGroupName("Friends");
romeo.setItemType(ItemType.both); romeo.setItemType(ItemType.both);
rosterResult.addRosterItem(romeo); rosterResult.addRosterItem(romeo);
// prepare mercutio's roster entry // prepare mercutio's roster entry
final Item mercutio = new Item(JidCreate.bareFrom("mercutio@example.com"), "Mercutio"); final Item mercutio = new Item(JidCreate.entityBareFrom("mercutio@example.com"), "Mercutio");
mercutio.setItemType(ItemType.from); mercutio.setItemType(ItemType.from);
rosterResult.addRosterItem(mercutio); rosterResult.addRosterItem(mercutio);
// prepare benvolio's roster entry // prepare benvolio's roster entry
final Item benvolio = new Item(JidCreate.bareFrom("benvolio@example.net"), "Benvolio"); final Item benvolio = new Item(JidCreate.entityBareFrom("benvolio@example.net"), "Benvolio");
benvolio.setItemType(ItemType.both); benvolio.setItemType(ItemType.both);
rosterResult.addRosterItem(benvolio); rosterResult.addRosterItem(benvolio);

View file

@ -99,7 +99,7 @@ public class RosterVersioningTest {
* @throws SmackException * @throws SmackException
* @throws XMPPException * @throws XMPPException
*/ */
@Test(timeout = 5000) @Test(timeout = 300000)
public void testEqualVersionStored() throws InterruptedException, IOException, XMPPException, SmackException { public void testEqualVersionStored() throws InterruptedException, IOException, XMPPException, SmackException {
answerWithEmptyRosterResult(); answerWithEmptyRosterResult();
roster.waitUntilLoaded(); roster.waitUntilLoaded();
@ -214,20 +214,20 @@ public class RosterVersioningTest {
rosterPush.setType(Type.set); rosterPush.setType(Type.set);
rosterPush.setVersion("v98"); rosterPush.setVersion("v98");
Item item = new Item(JidCreate.bareFrom("vaglaf@example.com"), "vaglaf the only"); Item item = new Item(JidCreate.entityBareFrom("vaglaf@example.com"), "vaglaf the only");
item.setItemType(ItemType.remove); item.setItemType(ItemType.remove);
rosterPush.addRosterItem(item); rosterPush.addRosterItem(item);
rosterListener.reset(); rosterListener.reset();
connection.processStanza(rosterPush); connection.processStanza(rosterPush);
rosterListener.waitAndReset(); rosterListener.waitAndReset();
assertNull("Store doses not contain vaglaf", store.getEntry(JidCreate.bareFrom("vaglaf@example.com"))); assertNull("Store doses not contain vaglaf", store.getEntry(JidCreate.entityBareFrom("vaglaf@example.com")));
assertEquals("Expect store version after push", "v98", store.getRosterVersion()); assertEquals("Expect store version after push", "v98", store.getRosterVersion());
} }
} }
private static Item vaglafItem() throws XmppStringprepException { private static Item vaglafItem() throws XmppStringprepException {
Item item = new Item(JidCreate.bareFrom("vaglaf@example.com"), "vaglaf the only"); Item item = new Item(JidCreate.entityBareFrom("vaglaf@example.com"), "vaglaf the only");
item.setItemType(ItemType.both); item.setItemType(ItemType.both);
item.addGroupName("all"); item.addGroupName("all");
item.addGroupName("friends"); item.addGroupName("friends");
@ -236,14 +236,14 @@ public class RosterVersioningTest {
} }
private static void populateStore(RosterStore store) throws IOException { private static void populateStore(RosterStore store) throws IOException {
store.addEntry(new RosterPacket.Item(JidCreate.bareFrom("geoff@example.com"), "geoff hurley"), ""); store.addEntry(new RosterPacket.Item(JidCreate.entityBareFrom("geoff@example.com"), "geoff hurley"), "");
RosterPacket.Item item = new RosterPacket.Item(JidCreate.bareFrom("joe@example.com"), "joe stevens"); RosterPacket.Item item = new RosterPacket.Item(JidCreate.entityBareFrom("joe@example.com"), "joe stevens");
item.addGroupName("friends"); item.addGroupName("friends");
item.addGroupName("partners"); item.addGroupName("partners");
store.addEntry(item, ""); store.addEntry(item, "");
item = new RosterPacket.Item(JidCreate.bareFrom("higgins@example.com"), "higgins mcmann"); item = new RosterPacket.Item(JidCreate.entityBareFrom("higgins@example.com"), "higgins mcmann");
item.addGroupName("all"); item.addGroupName("all");
item.addGroupName("friends"); item.addGroupName("friends");
store.addEntry(item, "v96"); store.addEntry(item, "v96");

View file

@ -72,7 +72,7 @@ public class RosterIntegrationTest extends AbstractSmackIntegrationTest {
} }
private void checkIfAddedAndSubscribed(Collection<Jid> addresses) { private void checkIfAddedAndSubscribed(Collection<Jid> addresses) {
for (Jid jid : addresses) { for (Jid jid : addresses) {
if (!jid.equals(conTwo.getUser().asBareJidString())) { if (!jid.equals(conTwo.getUser().asBareJid())) {
continue; continue;
} }
RosterEntry rosterEntry = rosterOne.getEntry(conTwo.getUser().asBareJid()); RosterEntry rosterEntry = rosterOne.getEntry(conTwo.getUser().asBareJid());

View file

@ -63,7 +63,7 @@ public class MultiUserChatIntegrationTest extends AbstractSmackIntegrationTest {
@SmackIntegrationTest @SmackIntegrationTest
public void mucTest() throws TimeoutException, Exception { public void mucTest() throws TimeoutException, Exception {
EntityBareJid mucAddress = JidCreate.bareFrom(Localpart.from("smack-inttest-" + randomString), mucService.getDomain()); EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-" + randomString), mucService.getDomain());
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);

View file

@ -62,7 +62,7 @@ public class MultiUserChatLowLevelIntegrationTest extends AbstractSmackLowLevelI
final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6)); final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6));
final String randomMucName = StringUtils.randomString(6); final String randomMucName = StringUtils.randomString(6);
final DomainBareJid mucComponent = multiUserChatManager.getXMPPServiceDomains().get(0); final DomainBareJid mucComponent = multiUserChatManager.getXMPPServiceDomains().get(0);
final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.bareFrom( final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(
Localpart.from(randomMucName), mucComponent)); Localpart.from(randomMucName), mucComponent));
MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname); MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname);

View file

@ -2,7 +2,7 @@ allprojects {
ext { ext {
shortVersion = '4.2.0-alpha2' shortVersion = '4.2.0-alpha2'
isSnapshot = true isSnapshot = true
jxmppVersion = '0.5.0-alpha4' jxmppVersion = '0.5.0-alpha5'
smackMinAndroidSdk = 8 smackMinAndroidSdk = 8
} }
} }