Search in sources :

Example 16 with Packet

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

the class StanzaIDUtilTest method testParseUUIDValue.

/**
 * Test if {@link StanzaIDUtil#findFirstUniqueAndStableStanzaID(Packet, String)} can parse a stanza that contains a
 * stanza ID.
 */
@Test
public void testParseUUIDValue() throws Exception {
    // Setup fixture.
    final Packet input = new Message();
    final JID self = new JID("foobar");
    final String expected = "de305d54-75b4-431b-adb2-eb6b9e546013";
    final Element toOverwrite = input.getElement().addElement("stanza-id", "urn:xmpp:sid:0");
    toOverwrite.addAttribute("id", expected);
    toOverwrite.addAttribute("by", self.toString());
    // Execute system under test.
    final String result = StanzaIDUtil.findFirstUniqueAndStableStanzaID(input, self.toString());
    // Verify results.
    assertEquals(expected, result);
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Test(org.junit.Test)

Example 17 with Packet

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

the class StanzaIDUtilTest method testParseNonUUIDValue.

/**
 * Test if {@link StanzaIDUtil#findFirstUniqueAndStableStanzaID(Packet, String)} can parse a stanza that contains a
 * stanza ID that is not a UUID value. OF-2026
 */
@Test
public void testParseNonUUIDValue() throws Exception {
    // Setup fixture.
    final Packet input = new Message();
    final JID self = new JID("foobar");
    final String expected = "not-a-uuid";
    final Element toOverwrite = input.getElement().addElement("stanza-id", "urn:xmpp:sid:0");
    toOverwrite.addAttribute("id", expected);
    toOverwrite.addAttribute("by", self.toString());
    // Execute system under test.
    final String result = StanzaIDUtil.findFirstUniqueAndStableStanzaID(input, self.toString());
    // Verify results.
    assertEquals(expected, result);
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Test(org.junit.Test)

Example 18 with Packet

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

the class StanzaIDUtilTest method testGeneratesStanzaIDElement.

/**
 * Test if {@link StanzaIDUtil#ensureUniqueAndStableStanzaID(Packet, JID)} adds a stanza-id element
 * with proper 'by' and UUID value if the provided input does not have a 'origin-id'
 * element.
 */
@Test
public void testGeneratesStanzaIDElement() throws Exception {
    // Setup fixture.
    final Packet input = new Message();
    final JID self = new JID("foobar");
    // Execute system under test.
    final Packet result = StanzaIDUtil.ensureUniqueAndStableStanzaID(input, self);
    // Verify results.
    Assert.assertNotNull(result);
    final Element stanzaIDElement = result.getElement().element(QName.get("stanza-id", "urn:xmpp:sid:0"));
    Assert.assertNotNull(stanzaIDElement);
    try {
        UUID.fromString(stanzaIDElement.attributeValue("id"));
    } catch (IllegalArgumentException ex) {
        Assert.fail();
    }
    assertEquals(self.toString(), stanzaIDElement.attributeValue("by"));
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Test(org.junit.Test)

Example 19 with Packet

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

the class HttpSessionDeliverable method testNamespaceOnEmptyStanzaWithoutChildElement.

/**
 * Verifies that the default namespace is set on empty stanzas (that do not have a child element)
 *
 * @see <a href="https://igniterealtime.org/issues/browse/OF-1087">OF-1087</a>
 */
@Test
public void testNamespaceOnEmptyStanzaWithoutChildElement() throws Exception {
    // Setup fixture
    final Message message = new Message();
    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=\"jabber:client\"/>", result);
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 20 with Packet

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

the class HttpSessionDeliverable method testNamespaceOnEmptyStanza.

/**
 * Verifies that the default namespace is set on empty stanzas.
 *
 * @see <a href="https://igniterealtime.org/issues/browse/OF-1087">OF-1087</a>
 */
@Test
public void testNamespaceOnEmptyStanza() throws Exception {
    // Setup fixture
    final Message message = new Message();
    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=\"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

Packet (org.xmpp.packet.Packet)33 JID (org.xmpp.packet.JID)17 Element (org.dom4j.Element)16 Message (org.xmpp.packet.Message)16 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)10 IQ (org.xmpp.packet.IQ)9 Presence (org.xmpp.packet.Presence)7 NotFoundException (org.jivesoftware.util.NotFoundException)5 PacketInterceptor (org.jivesoftware.openfire.interceptor.PacketInterceptor)3 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)3 Session (org.jivesoftware.openfire.session.Session)3 Date (java.sql.Date)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 DefaultElement (org.dom4j.tree.DefaultElement)2 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)2