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);
}
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);
}
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"));
}
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);
}
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);
}
Aggregations