Package rocks.xmpp.core.roster.model

Examples of rocks.xmpp.core.roster.model.Roster


*/
public class ContactExchangeManagerTest extends ExtensionTest {

    @BeforeClass
    public void prepareRoster() throws Exception {
        Roster roster = new Roster();
        roster.getContacts().add(new Contact(Jid.valueOf("juliet@example.net"), "juliet", "friends", "friends2"));
        roster.getContacts().add(new Contact(Jid.valueOf("romeo@example.net"), "romeo", "friends"));
        IQ iq = new IQ(AbstractIQ.Type.SET, roster);
        // Simulate a roster push in order to fill the roster.
        xmppSession.handleElement(iq);
    }
View Full Code Here


        JAXBContext jaxbContext = JAXBContext.newInstance(IQ.class, Roster.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);

        Roster roster = new Roster();
        List<Contact> contacts = new ArrayList<>();
        contacts.add(new Contact(new Jid("domain")));
        roster.getContacts().addAll(contacts);
        IQ iq = new IQ("1", IQ.Type.GET, roster);

        marshaller.marshal(iq, prefixFreeWriter);
        Assert.assertEquals("<iq id=\"1\" type=\"get\"><query xmlns=\"jabber:iq:roster\"><item jid=\"domain\"></item></query></iq>", writer.toString());
    }
View Full Code Here

    }

    @Test
    public void marshalBodyWithMultipleStanzas() throws XMLStreamException, JAXBException {
        IQ iq = new IQ("1", IQ.Type.GET);
        iq.setExtension(new Roster());
        Body body = Body.builder()
                .wrappedObjects(Arrays.<Object>asList(iq, new Presence())).build();

        Assert.assertEquals(marshal(body), "<body xmlns=\"http://jabber.org/protocol/httpbind\"><iq xmlns=\"jabber:client\" id=\"1\" type=\"get\"><query xmlns=\"jabber:iq:roster\"></query></iq><presence xmlns=\"jabber:client\"></presence></body>");
    }
View Full Code Here

                    Assert.assertEquals(e.getUpdatedContacts().get(0).getName(), "Name");
                }
            }
        });

        Roster roster1 = new Roster();
        roster1.getContacts().add(new Contact(Jid.valueOf("contact1@domain")));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact2@domain")));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact3@domain")));
        rosterManager.updateRoster(roster1, false);
        rosterPushCount[0]++;

        Roster roster2 = new Roster();
        roster2.getContacts().add(new Contact(Jid.valueOf("contact4@domain")));
        rosterManager.updateRoster(roster2, true);

        rosterPushCount[0]++;
        Roster roster3 = new Roster();
        Contact contact = new Contact(Jid.valueOf("contact2@domain"));
        contact.setSubscription(Contact.Subscription.REMOVE);
        roster3.getContacts().add(contact);
        rosterManager.updateRoster(roster3, true);

        rosterPushCount[0]++;
        Roster roster4 = new Roster();
        Contact contact2 = new Contact(Jid.valueOf("contact1@domain"));
        contact2.setName("Name");
        roster4.getContacts().add(contact2);
        rosterManager.updateRoster(roster4, true);
    }
View Full Code Here

    @Test
    public void testRosterGroups() {
        RosterManager rosterManager = new RosterManager(new TestXmppSession());

        Roster roster1 = new Roster();
        roster1.getContacts().add(new Contact(Jid.valueOf("contact1@domain"), "contact1", "Group1"));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact2@domain"), "contact2", "Group2"));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact4@domain"), "contact4", "Group3"));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact3@domain"), "contact3", "Group3"));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact5@domain"), "contact5", "Group3"));
        rosterManager.updateRoster(roster1, false);

        List<ContactGroup> list = new ArrayList<>(rosterManager.getContactGroups());
        Assert.assertEquals(list.size(), 3);
        Assert.assertEquals(list.get(0).getName(), "Group1");
View Full Code Here

    @Test
    public void testNestedRosterGroups() {
        RosterManager rosterManager = new RosterManager(new TestXmppSession());
        rosterManager.setGroupDelimiter("::");
        Roster roster1 = new Roster();
        roster1.getContacts().add(new Contact(Jid.valueOf("contact3@domain"), "contact3", "Group3::SubGroup"));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact4@domain"), "contact4", "Group3::SubGroup::3rdLevel"));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact5@domain"), "contact5", "Group3"));
        rosterManager.updateRoster(roster1, false);

        List<ContactGroup> list = new ArrayList<>(rosterManager.getContactGroups());
        Assert.assertEquals(list.size(), 1);
        Assert.assertEquals(list.get(0).getContacts().iterator().next().getJid(), Jid.valueOf("contact5@domain"));
View Full Code Here

    public void testRosterIntegrity() {

        RosterManager rosterManager = new RosterManager(new TestXmppSession());

        // Initial roster
        Roster roster1 = new Roster();
        roster1.getContacts().add(new Contact(Jid.valueOf("contact1@domain"), "contact1", "group1"));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact2@domain"), "contact2", "group2"));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact3@domain"), "contact3", true, Contact.Subscription.FROM));
        roster1.getContacts().add(new Contact(Jid.valueOf("contact4@domain"), "contact4", true, Contact.Subscription.FROM, "group2"));
        rosterManager.updateRoster(roster1, false);

        Assert.assertEquals(rosterManager.getUnaffiliatedContacts().size(), 1);
        Assert.assertEquals(rosterManager.getUnaffiliatedContacts().iterator().next().getSubscription(), Contact.Subscription.FROM);
        List<ContactGroup> groups = new ArrayList<>(rosterManager.getContactGroups());
        Assert.assertEquals(groups.get(0).getContacts().size(), 1);
        Assert.assertEquals(groups.get(1).getContacts().size(), 2);

        Roster roster2 = new Roster();
        roster2.getContacts().add(new Contact(Jid.valueOf("contact3@domain"), "contact3", true, Contact.Subscription.BOTH));
        rosterManager.updateRoster(roster2, true);

        Assert.assertEquals(rosterManager.getUnaffiliatedContacts().size(), 1);
        Assert.assertEquals(rosterManager.getUnaffiliatedContacts().iterator().next().getSubscription(), Contact.Subscription.BOTH);

        Assert.assertEquals(rosterManager.getContactGroups().size(), 2);

        Roster roster3 = new Roster();
        roster3.getContacts().add(new Contact(Jid.valueOf("contact2@domain"), "contact2", true, Contact.Subscription.TO, "group1"));
        rosterManager.updateRoster(roster3, true);

        groups = new ArrayList<>(rosterManager.getContactGroups());
        List<Contact> contacts = new ArrayList<>(groups.get(0).getContacts());
        Assert.assertEquals(groups.get(0).getContacts().size(), 2);
        Assert.assertEquals(contacts.get(1).getSubscription(), Contact.Subscription.TO);
        Assert.assertTrue(contacts.get(1).isPending());
        Assert.assertEquals(groups.get(1).getContacts().size(), 1);

        Roster roster4 = new Roster();
        Contact contact2 = new Contact(Jid.valueOf("contact3@domain"), "", false, Contact.Subscription.REMOVE);
        roster4.getContacts().add(contact2);
        rosterManager.updateRoster(roster4, true);
        Assert.assertTrue(rosterManager.getUnaffiliatedContacts().isEmpty());
    }
View Full Code Here

        xmppSession.addIQListener(new IQListener() {
            @Override
            public void handle(IQEvent e) {
                if (e.isIncoming() && !e.isConsumed()) {
                    IQ iq = e.getIQ();
                    Roster roster = iq.getExtension(Roster.class);
                    if (roster != null) {
                        // 2.1.6.  Roster Push
                        if (iq.getType() == IQ.Type.SET) {
                            // A receiving client MUST ignore the stanza unless it has no 'from' attribute (i.e., implicitly from the bare JID of the user's account) or it has a 'from' attribute whose value matches the user's bare JID <user@domainpart>.
                            if (iq.getFrom() == null || iq.getFrom().equals(xmppSession.getConnectedResource().asBareJid())) {
View Full Code Here

     * Requests the roster from the server. When the server returns the result, the {@link RosterListener} are notified.
     * That means, you should first {@linkplain #addRosterListener(RosterListener) register} a {@link RosterListener} prior to calling this method.
     */
    public void requestRoster() {
        IQ iq = new IQ(IQ.Type.GET);
        iq.setExtension(new Roster());
        this.xmppSession.send(iq);
    }
View Full Code Here

     */
    public void addContact(Contact contact, boolean requestSubscription, String status) throws XmppException {
        if (contact == null) {
            throw new IllegalArgumentException("contact must not be null.");
        }
        Roster roster = new Roster();
        roster.getContacts().add(contact);
        xmppSession.query(new IQ(IQ.Type.SET, roster));
        if (requestSubscription) {
            xmppSession.getPresenceManager().requestSubscription(contact.getJid(), status);
        }
    }
View Full Code Here

TOP

Related Classes of rocks.xmpp.core.roster.model.Roster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.