Search in sources :

Example 66 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class OfflineMessageStoreTest method shouldNotStoreEmptyChatMessagesWithOnlyChatStates.

@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);
    assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
Also used : PacketExtension(org.xmpp.packet.PacketExtension) Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 67 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class OfflineMessageStoreTest method shouldNotStoreEmptyChatMessages.

@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);
    assertFalse(OfflineMessageStore.shouldStoreMessage(message));
}
Also used : Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 68 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class OfflineMessageStoreTest method shouldStoreNormalMessages.

@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);
    assertTrue(OfflineMessageStore.shouldStoreMessage(message));
    Message message2 = new Message();
    assertTrue(OfflineMessageStore.shouldStoreMessage(message2));
}
Also used : Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 69 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class HttpSessionDeliverable method testNamespaceOnStanzaWithNamespace.

/**
     * Verifies that the default namespace is not set on stanzas that already have defined a default namespace.
     *
     * @see <a href="https://igniterealtime.org/issues/browse/OF-1087">OF-1087</a>
     */
@Test
public void testNamespaceOnStanzaWithNamespace() throws Exception {
    // Setup fixture
    final Message message = new Message();
    message.getElement().setQName(QName.get("message", "unit:test:preexisting:namespace"));
    message.setTo("unittest@example.org/test");
    message.addChildElement("unittest", "unit:test:namespace");
    final List<Packet> packets = new ArrayList<>();
    packets.add(message);
    // Execute system under test
    final HttpSession.Deliverable deliverable = new HttpSession.Deliverable(packets);
    final String result = deliverable.getDeliverable();
    // verify results
    // Note that this assertion depends on the Openfire XML parser-specific ordering of attributes.
    assertEquals("<message xmlns=\"unit:test:preexisting:namespace\" to=\"unittest@example.org/test\"><unittest xmlns=\"unit:test:namespace\"/></message>", result);
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 70 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class HttpSessionDeliverable method testNamespaceOnStanza.

/**
     * Verifies that the default namespace is set on (non-empty) stanzas.
     *
     * @see <a href="https://igniterealtime.org/issues/browse/OF-1087">OF-1087</a>
     */
@Test
public void testNamespaceOnStanza() throws Exception {
    // Setup fixture
    final Message message = new Message();
    message.setTo("unittest@example.org/test");
    message.addChildElement("unittest", "unit:test:namespace");
    final List<Packet> packets = new ArrayList<>();
    packets.add(message);
    // Execute system under test
    final HttpSession.Deliverable deliverable = new HttpSession.Deliverable(packets);
    final String result = deliverable.getDeliverable();
    // verify results
    // Note that this assertion depends on the Openfire XML parser-specific ordering of attributes.
    assertEquals("<message to=\"unittest@example.org/test\" xmlns=\"jabber:client\"><unittest xmlns=\"unit:test:namespace\"/></message>", result);
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Message (org.xmpp.packet.Message)111 Element (org.dom4j.Element)35 JID (org.xmpp.packet.JID)25 Test (org.junit.Test)23 Presence (org.xmpp.packet.Presence)18 IQ (org.xmpp.packet.IQ)16 ArrayList (java.util.ArrayList)10 Packet (org.xmpp.packet.Packet)10 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)9 Date (java.util.Date)6 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 NotFoundException (org.jivesoftware.util.NotFoundException)6 StringReader (java.io.StringReader)4 List (java.util.List)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)4 User (org.jivesoftware.openfire.user.User)4 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 SAXReader (org.dom4j.io.SAXReader)3 DefaultElement (org.dom4j.tree.DefaultElement)3