Search in sources :

Example 1 with StanzaIdElement

use of org.jivesoftware.smackx.sid.element.StanzaIdElement in project Smack by igniterealtime.

the class StableUniqueStanzaIdTest method fromMessageTest.

@Test
public void fromMessageTest() {
    MessageBuilder messageBuilder = StanzaBuilder.buildMessage();
    Message message = messageBuilder.build();
    assertFalse(OriginIdElement.hasOriginId(message));
    assertFalse(StanzaIdElement.hasStanzaId(message));
    OriginIdElement.addTo(messageBuilder);
    message = messageBuilder.build();
    assertTrue(OriginIdElement.hasOriginId(message));
    StanzaIdElement stanzaId = new StanzaIdElement("alice@wonderland.lit");
    message.addExtension(stanzaId);
    assertTrue(StanzaIdElement.hasStanzaId(message));
    assertEquals(stanzaId, StanzaIdElement.getStanzaId(message));
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Message(org.jivesoftware.smack.packet.Message) StanzaIdElement(org.jivesoftware.smackx.sid.element.StanzaIdElement) Test(org.junit.jupiter.api.Test)

Example 2 with StanzaIdElement

use of org.jivesoftware.smackx.sid.element.StanzaIdElement in project Smack by igniterealtime.

the class StableUniqueStanzaIdTest method stanzaIdProviderTest.

@Test
public void stanzaIdProviderTest() throws Exception {
    String xml = "<stanza-id xmlns='urn:xmpp:sid:0' id='de305d54-75b4-431b-adb2-eb6b9e546013' by='alice@wonderland.lit' />";
    StanzaIdElement element = new StanzaIdElement("de305d54-75b4-431b-adb2-eb6b9e546013", "alice@wonderland.lit");
    assertEquals("de305d54-75b4-431b-adb2-eb6b9e546013", element.getId());
    assertEquals("alice@wonderland.lit", element.getBy());
    assertXmlSimilar(xml, element.toXML().toString());
    StanzaIdElement parsed = StanzaIdProvider.INSTANCE.parse(TestUtils.getParser(xml));
    assertEquals(element.getId(), parsed.getId());
    assertEquals(element.getBy(), parsed.getBy());
}
Also used : StanzaIdElement(org.jivesoftware.smackx.sid.element.StanzaIdElement) Test(org.junit.jupiter.api.Test)

Aggregations

StanzaIdElement (org.jivesoftware.smackx.sid.element.StanzaIdElement)2 Test (org.junit.jupiter.api.Test)2 Message (org.jivesoftware.smack.packet.Message)1 MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)1