/** * Creates a new message to the specified recipient and with the specified body. * * @param to the user to send the message to. * @param body the body of the message. * @throws XmppStringprepException if 'to' is not a valid XMPP address. */ public Message(String to, String body) throws XmppStringprepException { this(JidCreate.from(to), body); }
public boolean addedAddressesContains(String jidString) { Jid jid; try { jid = JidCreate.from(jidString); } catch (XmppStringprepException e) { throw new IllegalArgumentException(e); } return addressesAdded.contains(jid); }
public boolean deletedAddressesContains(String jidString) { Jid jid; try { jid = JidCreate.from(jidString); } catch (XmppStringprepException e) { throw new IllegalArgumentException(e); } return addressesDeleted.contains(jid); }
public boolean updatedAddressesContains(String jidString) { Jid jid; try { jid = JidCreate.from(jidString); } catch (XmppStringprepException e) { throw new IllegalArgumentException(e); } return addressesUpdated.contains(jid); }
@Test public void checkUpdatePrefsStanza() throws Exception { List<Jid> alwaysJids = new ArrayList<>(); alwaysJids.add(JidCreate.from("romeo@montague.lit")); alwaysJids.add(JidCreate.from("other@montague.lit")); List<Jid> neverJids = new ArrayList<>(); neverJids.add(JidCreate.from("montague@montague.lit")); MamPrefsIQ mamPrefIQ = new MamPrefsIQ(alwaysJids, neverJids, DefaultBehavior.roster); mamPrefIQ.setStanzaId("sarasa"); Assert.assertEquals(mamPrefIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString(), updatePrefsStanzaExample); }
@Test public void checkAffiliationsChangeExtension() throws Exception { Message changeAffiliationsMessage = 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); }
@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(StreamOpen.CLIENT_NAMESPACE).toString()); }
@Test public void checkUnblockContactIQStanza() throws Exception { List<Jid> jids = new ArrayList<>(); jids.add(JidCreate.from("romeo@montague.net")); jids.add(JidCreate.from("pepe@montague.net")); UnblockContactsIQ unblockContactIQ = new UnblockContactsIQ(jids); unblockContactIQ.setStanzaId("unblock1"); Assert.assertEquals(unblockContactIQExample, unblockContactIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }
@Test public void checkBlockContactIQStanza() throws Exception { List<Jid> jids = new ArrayList<>(); jids.add(JidCreate.from("romeo@montague.net")); jids.add(JidCreate.from("pepe@montague.net")); BlockContactsIQ blockContactIQ = new BlockContactsIQ(jids); blockContactIQ.setStanzaId("block1"); Assert.assertEquals(blockContactIQExample, blockContactIQ.toXML(null).toString()); }
@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(StreamOpen.CLIENT_NAMESPACE).toString()); }
@Test public void checkUnblockContactPushIQ() throws Exception { IQ iq = PacketParserUtils.parseStanza(unblockContactPushIQExample); UnblockContactsIQ unblockContactIQ = (UnblockContactsIQ) iq; Assert.assertEquals(JidCreate.from("romeo@montague.net"), unblockContactIQ.getJids().get(0)); Assert.assertEquals(JidCreate.from("pepe@montague.net"), unblockContactIQ.getJids().get(1)); }
@Test public void checkAffiliationsChangeExtensionWithVersion() throws Exception { Message changeAffiliationsMessage = PacketParserUtils.parseStanza(exampleMessageStanzaWithVersion); AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension .from(changeAffiliationsMessage); HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations(); Assert.assertEquals(affiliations.size(), 2); Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member); Assert.assertEquals(affiliations.get(JidCreate.from("sarasa3@shakespeare.lit")), MUCLightAffiliation.none); Assert.assertEquals(affiliationsChangeExtension.getVersion(), "qwerty"); }
@Test public void checkBlockListIQ() throws Exception { IQ iq = PacketParserUtils.parseStanza(blockListIQExample); BlockListIQ blockListIQ = (BlockListIQ) iq; Assert.assertEquals(2, blockListIQ.getBlockedJids().size()); Assert.assertEquals(JidCreate.from("romeo@montague.net"), blockListIQ.getBlockedJids().get(0)); Assert.assertEquals(JidCreate.from("iago@shakespeare.lit"), blockListIQ.getBlockedJids().get(1)); IQ iq2 = PacketParserUtils.parseStanza(emptyBlockListIQExample); BlockListIQ emptyBlockListIQ = (BlockListIQ) iq2; Assert.assertEquals(0, emptyBlockListIQ.getBlockedJids().size()); }
@Test public void checkMUCLightGetInfoIQStanzaWithoutVersion() throws Exception { MUCLightGetInfoIQ mucLightGetInfoIQWithoutVersion = new MUCLightGetInfoIQ( JidCreate.from("coven@muclight.shakespeare.lit"), null); mucLightGetInfoIQWithoutVersion.setStanzaId("getinfo1"); Assert.assertEquals(mucLightGetInfoIQWithoutVersion.toXML(StreamOpen.CLIENT_NAMESPACE).toString(), exampleWithoutVersion); }
@Test public void checkChangeRoomNameStanza() throws Exception { MUCLightSetConfigsIQ mucLightChangeRoomNameIQ = new MUCLightSetConfigsIQ( JidCreate.from("coven@muclight.shakespeare.lit"), "A Darker Cave", null); mucLightChangeRoomNameIQ.setStanzaId("roomName1"); Assert.assertEquals(changeRoomNameIQExample, mucLightChangeRoomNameIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }
@Test public void checkGetBlockingListIQ() throws Exception { MUCLightBlockingIQ mucLightBlockingIQ = new MUCLightBlockingIQ(null, null); mucLightBlockingIQ.setType(Type.get); mucLightBlockingIQ.setStanzaId("getblock1"); mucLightBlockingIQ.setTo(JidCreate.from("muclight.shakespeare.lit")); Assert.assertEquals(getBlockingListIQExample, mucLightBlockingIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }
@Test public void checkMarkableExtension() throws Exception { Message message = new Message(JidCreate.from("ingrichard@royalty.england.lit/throne")); message.setStanzaId("message-1"); message.setBody("My lord, dispatch; read o'er these articles."); message.addExtension(ChatMarkersElements.MarkableExtension.INSTANCE); Assert.assertEquals(markableMessageStanza, message.toXML(null).toString()); }
@Test public void checkDisplayedExtension() throws Exception { Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster")); message.setStanzaId("message-2"); message.addExtension(new ChatMarkersElements.DisplayedExtension("message-1")); Assert.assertEquals(displayedMessageStanza, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }
@Test public void checkReceivedExtension() throws Exception { Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster")); message.setStanzaId("message-2"); message.addExtension(new ChatMarkersElements.ReceivedExtension("message-1")); Assert.assertEquals(receivedMessageStanza, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }
@Test public void checkBoBIQRequest() throws Exception { BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1"); BoBIQ createdBoBIQ = new BoBIQ(bobHash); createdBoBIQ.setStanzaId("sarasa"); createdBoBIQ.setTo(JidCreate.from("ladymacbeth@shakespeare.lit/castle")); createdBoBIQ.setType(Type.get); Assert.assertEquals(sampleBoBIQRequest, createdBoBIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString()); }