Search in sources :

Example 1 with XHTMLExtension

use of org.jivesoftware.smackx.packet.XHTMLExtension in project Smack by igniterealtime.

the class MultiUserChatTest method testInvitationWithMessage.

public void testInvitationWithMessage() {
    final String[] answer = new String[2];
    try {
        // User2 joins the new room
        MultiUserChat muc2 = new MultiUserChat(getConnection(1), room);
        muc2.join("testbot2");
        // User3 is listening to MUC invitations
        MultiUserChat.addInvitationListener(getConnection(2), new InvitationListener() {

            public void invitationReceived(XMPPConnection conn, String room, String inviter, String reason, String password, Message message) {
                // Indicate that the invitation was received
                answer[0] = reason;
                XHTMLExtension extension = (XHTMLExtension) message.getExtension("html", "http://jabber.org/protocol/xhtml-im");
                assertNotNull("An extension was not found in the invitation", extension);
                answer[1] = (String) extension.getBodies().next();
            }
        });
        // User2 invites user3 to join to the room
        Message msg = new Message();
        XHTMLExtension xhtmlExtension = new XHTMLExtension();
        xhtmlExtension.addBody("<body>Meet me in this excellent room</body>");
        msg.addExtension(xhtmlExtension);
        muc2.invite(msg, getFullJID(2), "Meet me in this excellent room");
        Thread.sleep(350);
        assertEquals("Invitation was not received", "Meet me in this excellent room", answer[0]);
        assertEquals("Rejection was not received", "<body>Meet me in this excellent room</body>", answer[1]);
        // User2 leaves the room
        muc2.leave();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XHTMLExtension(org.jivesoftware.smackx.packet.XHTMLExtension) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Message (org.jivesoftware.smack.packet.Message)1 XHTMLExtension (org.jivesoftware.smackx.packet.XHTMLExtension)1