Search in sources :

Example 16 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class MUCLightAffiliationsChangeExtensionTest method checkAffiliationsChangeExtension.

@Test
public void checkAffiliationsChangeExtension() throws Exception {
    Message changeAffiliationsMessage = (Message) PacketParserUtils.parseStanza(exampleMessageStanza);
    AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension.from(changeAffiliationsMessage);
    HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
    Assert.assertEquals(affiliations.size(), 3);
    Assert.assertEquals(affiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
    Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
    Assert.assertEquals(affiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none);
}
Also used : Message(org.jivesoftware.smack.packet.Message) Jid(org.jxmpp.jid.Jid) AffiliationsChangeExtension(org.jivesoftware.smackx.muclight.element.MUCLightElements.AffiliationsChangeExtension) Test(org.junit.Test)

Example 17 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class MUCLightBlockingTest method checkUnblockUsersAndRoomsIQ.

@Test
public void checkUnblockUsersAndRoomsIQ() throws Exception {
    HashMap<Jid, Boolean> users = new HashMap<>();
    users.put(JidCreate.from("hag66@shakespeare.lit"), true);
    HashMap<Jid, Boolean> rooms = new HashMap<>();
    rooms.put(JidCreate.from("coven@muclight.shakespeare.lit"), true);
    MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, users);
    mucLightBlockingIQ.setType(Type.set);
    mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
    mucLightBlockingIQ.setStanzaId("unblock1");
    Assert.assertEquals(unblockingUsersAndRoomsExample, mucLightBlockingIQ.toXML().toString());
}
Also used : Jid(org.jxmpp.jid.Jid) HashMap(java.util.HashMap) MUCLightBlockingIQ(org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ) Test(org.junit.Test)

Example 18 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class MUCLightBlockingTest method checkBlockRoomsIQ.

@Test
public void checkBlockRoomsIQ() throws Exception {
    HashMap<Jid, Boolean> rooms = new HashMap<>();
    rooms.put(JidCreate.from("coven@muclight.shakespeare.lit"), false);
    rooms.put(JidCreate.from("chapel@shakespeare.lit"), false);
    MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(rooms, null);
    mucLightBlockingIQ.setType(Type.set);
    mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
    mucLightBlockingIQ.setStanzaId("block1");
    Assert.assertEquals(blockingRoomsIQExample, mucLightBlockingIQ.toXML().toString());
}
Also used : Jid(org.jxmpp.jid.Jid) HashMap(java.util.HashMap) MUCLightBlockingIQ(org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ) Test(org.junit.Test)

Example 19 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class MUCLightBlockingTest method checkBlockUsersIQ.

@Test
public void checkBlockUsersIQ() throws Exception {
    HashMap<Jid, Boolean> users = new HashMap<>();
    users.put(JidCreate.from("hag77@shakespeare.lit"), false);
    users.put(JidCreate.from("hag66@shakespeare.lit"), false);
    MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, users);
    mucLightBlockingIQ.setType(Type.set);
    mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit"));
    mucLightBlockingIQ.setStanzaId("block2");
    Assert.assertEquals(blockingUsersIQExample, mucLightBlockingIQ.toXML().toString());
}
Also used : Jid(org.jxmpp.jid.Jid) HashMap(java.util.HashMap) MUCLightBlockingIQ(org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ) Test(org.junit.Test)

Example 20 with Jid

use of org.jxmpp.jid.Jid in project Smack by igniterealtime.

the class MUCParserUtils method parseItem.

public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
    int initialDepth = parser.getDepth();
    MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
    Resourcepart nick = ParserUtils.getResourcepartAttribute(parser, "nick");
    MUCRole role = MUCRole.fromString(parser.getAttributeValue("", "role"));
    Jid jid = ParserUtils.getJidAttribute(parser);
    Jid actor = null;
    Resourcepart actorNick = null;
    String reason = null;
    outerloop: while (true) {
        int eventType = parser.next();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                String name = parser.getName();
                switch(name) {
                    case "actor":
                        actor = ParserUtils.getJidAttribute(parser);
                        // TODO change to
                        // actorNick = Resourcepart.from(parser.getAttributeValue("", "nick"));
                        // once a newer version of JXMPP is used that supports from(null).
                        String actorNickString = parser.getAttributeValue("", "nick");
                        if (actorNickString != null) {
                            actorNick = Resourcepart.from(actorNickString);
                        }
                        break;
                    case "reason":
                        reason = parser.nextText();
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new MUCItem(affiliation, role, actor, reason, jid, nick, actorNick);
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) MUCAffiliation(org.jivesoftware.smackx.muc.MUCAffiliation) MUCRole(org.jivesoftware.smackx.muc.MUCRole) Jid(org.jxmpp.jid.Jid) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Aggregations

Jid (org.jxmpp.jid.Jid)78 EntityBareJid (org.jxmpp.jid.EntityBareJid)18 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)14 DomainBareJid (org.jxmpp.jid.DomainBareJid)14 EntityFullJid (org.jxmpp.jid.EntityFullJid)12 BareJid (org.jxmpp.jid.BareJid)11 IQ (org.jivesoftware.smack.packet.IQ)7 Presence (org.jivesoftware.smack.packet.Presence)7 MUCLightBlockingIQ (org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ)7 SmackException (org.jivesoftware.smack.SmackException)6 Message (org.jivesoftware.smack.packet.Message)6 WeakHashMap (java.util.WeakHashMap)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)4 Map (java.util.Map)3 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)3 FeatureNotSupportedException (org.jivesoftware.smack.SmackException.FeatureNotSupportedException)3 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)3 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)3