OfflineMessageStoreTest.java 3.38 KB
Newer Older
1 2 3 4 5 6
package org.jivesoftware.openfire;

import org.junit.Test;
import org.xmpp.packet.Message;
import org.xmpp.packet.PacketExtension;

7 8 9
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

10 11 12 13 14 15 16 17 18 19 20 21
/**
 * This tests the business rules for storing messages as described in <a href="http://xmpp.org/extensions/xep-0160.html#types">3. Handling of Message Types</a>.
 *
 * @author csh
 */
public class OfflineMessageStoreTest {

    @Test
    public void shouldNotStoreGroupChatMessages() {
        // XEP-0160: "groupchat" message types SHOULD NOT be stored offline
        Message message = new Message();
        message.setType(Message.Type.groupchat);
22
        assertFalse(OfflineMessageStore.shouldStoreMessage(message));
23 24 25 26 27 28 29
    }

    @Test
    public void shouldNotStoreHeadlineMessages() {
        // XEP-0160: "headline" message types SHOULD NOT be stored offline
        Message message = new Message();
        message.setType(Message.Type.headline);
30
        assertFalse(OfflineMessageStore.shouldStoreMessage(message));
31 32 33 34 35 36 37
    }

    @Test
    public void shouldNotStoreErrorMessages() {
        // XEP-0160: "error" message types SHOULD NOT be stored offline,
        Message message = new Message();
        message.setType(Message.Type.error);
38
        assertFalse(OfflineMessageStore.shouldStoreMessage(message));
39 40 41 42 43 44 45
    }

    @Test
    public void shouldStoreNormalMessages() {
        // XEP-0160: Messages with a 'type' attribute whose value is "normal" (or messages with no 'type' attribute) SHOULD be stored offline.
        Message message = new Message();
        message.setType(Message.Type.normal);
46
        assertTrue(OfflineMessageStore.shouldStoreMessage(message));
47 48

        Message message2 = new Message();
49
        assertTrue(OfflineMessageStore.shouldStoreMessage(message2));
50 51 52 53 54 55 56
    }

    @Test
    public void shouldNotStoreEmptyChatMessages() {
        // XEP-0160: "chat" message types SHOULD be stored offline unless they only contain chat state notifications
        Message message = new Message();
        message.setType(Message.Type.chat);
57
        assertFalse(OfflineMessageStore.shouldStoreMessage(message));
58 59 60 61 62 63 64 65
    }

    @Test
    public void shouldStoreNonEmptyChatMessages() {
        // XEP-0160: "chat" message types SHOULD be stored offline unless they only contain chat state notifications
        Message message = new Message();
        message.setType(Message.Type.chat);
        message.setBody(" ");
66
        assertTrue(OfflineMessageStore.shouldStoreMessage(message));
67 68 69 70 71 72 73 74
    }

    @Test
    public void shouldNotStoreEmptyChatMessagesWithOnlyChatStates() {
        Message message = new Message();
        message.setType(Message.Type.chat);
        PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
        message.addExtension(chatState);
75
        assertFalse(OfflineMessageStore.shouldStoreMessage(message));
76 77 78 79 80 81 82 83 84 85
    }

    @Test
    public void shouldStoreEmptyChatMessagesWithOtherExtensions() {
        Message message = new Message();
        message.setType(Message.Type.chat);
        PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
        message.addExtension(chatState);
        PacketExtension packetExtension2 = new PacketExtension("received", "urn:xmpp:receipts");
        message.addExtension(packetExtension2);
86
        assertTrue(OfflineMessageStore.shouldStoreMessage(message));
87 88
    }
}