Search in sources :

Example 96 with Message

use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.

the class MUCLightConfigurationsChangeExtensionTest method checkConfigsChangeExtension.

@Test
public void checkConfigsChangeExtension() throws Exception {
    Message configurationsMessage = (Message) PacketParserUtils.parseStanza(messageWithConfigsChangeExample);
    ConfigurationsChangeExtension configurationsChangeExtension = ConfigurationsChangeExtension.from(configurationsMessage);
    Assert.assertEquals("zaqwsx", configurationsChangeExtension.getPrevVersion());
    Assert.assertEquals("zxcvbnm", configurationsChangeExtension.getVersion());
    Assert.assertEquals("A Darker Cave", configurationsChangeExtension.getRoomName());
    Assert.assertNull(configurationsChangeExtension.getSubject());
    Assert.assertEquals("blue", configurationsChangeExtension.getCustomConfigs().get("color"));
    Assert.assertEquals(messageWithConfigsChangeExample, configurationsMessage.toXML().toString());
}
Also used : Message(org.jivesoftware.smack.packet.Message) ConfigurationsChangeExtension(org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationsChangeExtension) Test(org.junit.Test)

Example 97 with Message

use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.

the class QueryArchiveTest method checkMamQueryResults.

@Test
public void checkMamQueryResults() throws Exception {
    Message message = new Message();
    message.setStanzaId("iasd207");
    message.setFrom(JidCreate.from("coven@chat.shakespeare.lit"));
    message.setTo(JidCreate.from("hag66@shakespeare.lit/pda"));
    GregorianCalendar calendar = new GregorianCalendar(2002, 10 - 1, 13, 23, 58, 37);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = calendar.getTime();
    DelayInformation delay = new DelayInformation(date);
    Message forwardedMessage = new Message();
    forwardedMessage.setFrom(JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
    forwardedMessage.setStanzaId("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
    forwardedMessage.setType(Type.chat);
    forwardedMessage.setBody("Thrice the brinded cat hath mew.");
    Forwarded forwarded = new Forwarded(delay, forwardedMessage);
    message.addExtension(new MamResultExtension("g27", "34482-21985-73620", forwarded));
    Assert.assertEquals(message.toXML().toString(), mamQueryResultExample);
    MamResultExtension mamResultExtension = MamResultExtension.from(message);
    Assert.assertEquals(mamResultExtension.getId(), "34482-21985-73620");
    Assert.assertEquals(mamResultExtension.getForwarded().getDelayInformation().getStamp(), date);
    Message resultMessage = (Message) mamResultExtension.getForwarded().getForwardedStanza();
    Assert.assertEquals(resultMessage.getFrom(), JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
    Assert.assertEquals(resultMessage.getStanzaId(), "162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
    Assert.assertEquals(resultMessage.getType(), Type.chat);
    Assert.assertEquals(resultMessage.getBody(), "Thrice the brinded cat hath mew.");
}
Also used : Message(org.jivesoftware.smack.packet.Message) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) GregorianCalendar(java.util.GregorianCalendar) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) MamResultExtension(org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension) Date(java.util.Date) Test(org.junit.Test)

Example 98 with Message

use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.

the class MUCLightAffiliationsChangeExtensionTest method checkAffiliationsChangeExtensionWithPrevVersion.

@Test
public void checkAffiliationsChangeExtensionWithPrevVersion() throws Exception {
    Message changeAffiliationsMessage = (Message) PacketParserUtils.parseStanza(exampleMessageStanzaWithPrevVersion);
    AffiliationsChangeExtension affiliationsChangeExtension = AffiliationsChangeExtension.from(changeAffiliationsMessage);
    HashMap<Jid, MUCLightAffiliation> affiliations = affiliationsChangeExtension.getAffiliations();
    Assert.assertEquals(affiliations.size(), 2);
    Assert.assertEquals(affiliations.get(JidCreate.from("sarasa2@shakespeare.lit")), MUCLightAffiliation.owner);
    Assert.assertEquals(affiliations.get(JidCreate.from("sarasa1@shakespeare.lit")), MUCLightAffiliation.member);
    Assert.assertEquals(affiliationsChangeExtension.getPrevVersion(), "njiokm");
    Assert.assertEquals(affiliationsChangeExtension.getVersion(), "qwerty");
}
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 99 with Message

use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.

the class MUCLightAffiliationsChangeExtensionTest method checkAffiliationsChangeExtensionWithVersion.

@Test
public void checkAffiliationsChangeExtensionWithVersion() throws Exception {
    Message changeAffiliationsMessage = (Message) 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");
}
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 100 with Message

use of org.jivesoftware.smack.packet.Message in project Smack by igniterealtime.

the class MultiUserChatTest method testDiscussionHistory.

public void testDiscussionHistory() {
    try {
        // User1 sends some messages to the room
        muc.sendMessage("Message 1");
        muc.sendMessage("Message 2");
        // Wait 5 seconds before sending the last message
        Thread.sleep(5000);
        muc.sendMessage("Message 3");
        // User2 joins the room requesting to receive the messages of the last 2 seconds.
        MultiUserChat muc2 = new MultiUserChat(getConnection(1), room);
        DiscussionHistory history = new DiscussionHistory();
        history.setSeconds(2);
        muc2.join("testbot2", null, history, SmackConfiguration.getPacketReplyTimeout());
        Message msg;
        // Get first historic message
        msg = muc2.nextMessage(1000);
        assertNotNull("First message is null", msg);
        DelayInformation delay = DelayInformationManager.getDelayInformation(msg);
        assertNotNull("Message contains no delay information", delay);
        SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
        UTC_FORMAT.setTimeZone(TimeZone.getDefault());
        System.out.println(UTC_FORMAT.format(delay.getStamp()));
        assertEquals("Body of first message is incorrect", "Message 3", msg.getBody());
        // Try to get second historic message 
        msg = muc2.nextMessage(1000);
        assertNull("Second message is not null", msg);
        // User3 joins the room requesting to receive the last 2 messages.
        MultiUserChat muc3 = new MultiUserChat(getConnection(2), room);
        history = new DiscussionHistory();
        history.setMaxStanzas(2);
        muc3.join("testbot3", null, history, SmackConfiguration.getPacketReplyTimeout());
        // Get first historic message 
        msg = muc3.nextMessage(1000);
        assertNotNull("First message is null", msg);
        assertEquals("Body of first message is incorrect", "Message 2", msg.getBody());
        // Get second historic message 
        msg = muc3.nextMessage(1000);
        assertNotNull("Second message is null", msg);
        assertEquals("Body of second message is incorrect", "Message 3", msg.getBody());
        // Try to get third historic message 
        msg = muc3.nextMessage(1000);
        assertNull("Third message is not null", msg);
        // User2 leaves the room
        muc2.leave();
        // User3 leaves the room
        muc3.leave();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) DelayInformation(org.jivesoftware.smackx.packet.DelayInformation) SimpleDateFormat(java.text.SimpleDateFormat) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

Message (org.jivesoftware.smack.packet.Message)142 Test (org.junit.Test)57 Presence (org.jivesoftware.smack.packet.Presence)17 StanzaCollector (org.jivesoftware.smack.StanzaCollector)14 MessageTypeFilter (org.jivesoftware.smack.filter.MessageTypeFilter)12 Stanza (org.jivesoftware.smack.packet.Stanza)12 XMPPException (org.jivesoftware.smack.XMPPException)11 XMPPConnection (org.jivesoftware.smack.XMPPConnection)9 Date (java.util.Date)8 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)8 AccountItem (com.xabber.android.data.account.AccountItem)7 Chat (org.jivesoftware.smack.Chat)7 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)7 XmlPullParser (org.xmlpull.v1.XmlPullParser)7 ArrayList (java.util.ArrayList)6 Jid (org.jxmpp.jid.Jid)6 NetworkException (com.xabber.android.data.NetworkException)5 Forwarded (org.jivesoftware.smackx.forward.packet.Forwarded)5 GeoLocation (org.jivesoftware.smackx.geoloc.packet.GeoLocation)5 IOException (java.io.IOException)4