final StringBuilder sb = new StringBuilder(); sb.append("<iq id=\"rostertest2\" type=\"set\" ") .append("to=\"").append(connection.getUser()).append("\">") .append("<query xmlns=\"jabber:iq:roster\">") .append("<item jid=\"").append(contactJID).append("\">")
final StringBuilder sb = new StringBuilder(); sb.append("<iq id=\"rostertest1\" type=\"set\" ") .append("to=\"").append(connection.getUser()).append("\">") .append("<query xmlns=\"jabber:iq:roster\">") .append("<item jid=\"").append(contactJID).append("\"/>")
rosterPush.setTo(connection.getUser()); rosterPush.addRosterItem(item); connection.processStanza(rosterPush);
rosterPush.setTo(connection.getUser()); rosterPush.addRosterItem(item); connection.processStanza(rosterPush);
/** * Remove all roster entries by iterating trough {@link Roster#getEntries()} * and simulating receiving roster pushes from the server. * * @param connection the dummy connection of which the provided roster belongs to. * @param roster the roster (or buddy list) which should be initialized. */ public static void removeAllRosterEntries(DummyConnection connection, Roster roster) { for (RosterEntry entry : roster.getEntries()) { // prepare the roster push packet final RosterPacket rosterPush = new RosterPacket(); rosterPush.setType(Type.set); rosterPush.setTo(connection.getUser()); // prepare the buddy's item entry which should be removed final RosterPacket.Item item = new RosterPacket.Item(entry.getJid(), entry.getName()); item.setItemType(ItemType.remove); rosterPush.addRosterItem(item); // simulate receiving the roster push connection.processStanza(rosterPush); } }
/** * 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() throws XmppStringprepException { final BareJid spammerJid = JidCreate.entityBareFrom("spam@example.com"); RosterPacket packet = new RosterPacket(); packet.setType(Type.set); packet.setTo(connection.getUser()); packet.setFrom(JidCreate.entityBareFrom("mallory@example.com")); packet.addRosterItem(new Item(spammerJid, "Cool products!")); final String requestId = packet.getStanzaId(); // Simulate receiving the roster push connection.processStanza(packet); // Smack should reply with an error IQ ErrorIQ errorIQ = connection.getSentPacket(); assertEquals(requestId, errorIQ.getStanzaId()); assertEquals(Condition.service_unavailable, errorIQ.getError().getCondition()); assertNull("Contact was added to roster", Roster.getInstanceFor(connection).getEntry(spammerJid)); }
rosterResult.setTo(connection.getUser()); rosterResult.setType(Type.result); rosterResult.setStanzaId(rosterRequest.getStanzaId());