Search in sources :

Example 1 with OriginIdElement

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

the class RetractedElementProvider method parse.

@Override
public RetractedElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException, ParseException {
    Date date = ParserUtils.getDateFromXep82String(parser.getAttributeValue("", RetractedElement.ATTR_STAMP));
    OriginIdElement originIdElement = null;
    while (originIdElement == null) {
        XmlPullParser.TagEvent tag = parser.nextTag();
        if (tag == XmlPullParser.TagEvent.START_ELEMENT && OriginIdElement.ELEMENT.equals(parser.getName()) && StableUniqueStanzaIdManager.NAMESPACE.equals(parser.getNamespace())) {
            originIdElement = OriginIdProvider.INSTANCE.parse(parser);
        }
    }
    return new RetractedElement(date, originIdElement);
}
Also used : RetractedElement(org.jivesoftware.smackx.message_retraction.element.RetractedElement) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) OriginIdElement(org.jivesoftware.smackx.sid.element.OriginIdElement) Date(java.util.Date)

Example 2 with OriginIdElement

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

the class MessageFasteningElementsTest method fasteningDeserializationTest.

@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void fasteningDeserializationTest(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
    String xml = "<apply-to xmlns='urn:xmpp:fasten:0' id='origin-id-1'>" + "    <i-like-this xmlns='urn:example:like'/>" + "    <external name='custom' element-namespace='urn:example:custom'/>" + "    <external name='body'/>" + "</apply-to>";
    FasteningElement parsed = SmackTestUtil.parse(xml, FasteningElementProvider.class, parserKind);
    assertNotNull(parsed);
    assertEquals(new OriginIdElement("origin-id-1"), parsed.getReferencedStanzasOriginId());
    assertFalse(parsed.isRemovingElement());
    assertFalse(parsed.isShellElement());
    assertEquals(1, parsed.getWrappedPayloads().size());
    assertEquals("i-like-this", parsed.getWrappedPayloads().get(0).getElementName());
    assertEquals("urn:example:like", parsed.getWrappedPayloads().get(0).getNamespace());
    assertEquals(2, parsed.getExternalPayloads().size());
    ExternalElement custom = parsed.getExternalPayloads().get(0);
    assertEquals("custom", custom.getName());
    assertEquals("urn:example:custom", custom.getElementNamespace());
    ExternalElement body = parsed.getExternalPayloads().get(1);
    assertEquals("body", body.getName());
    assertNull(body.getElementNamespace());
}
Also used : FasteningElement(org.jivesoftware.smackx.message_fastening.element.FasteningElement) OriginIdElement(org.jivesoftware.smackx.sid.element.OriginIdElement) ExternalElement(org.jivesoftware.smackx.message_fastening.element.ExternalElement) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with OriginIdElement

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

the class MessageFasteningElementsTest method createShellElementSharesOriginIdTest.

@Test
public void createShellElementSharesOriginIdTest() {
    OriginIdElement originIdElement = new OriginIdElement("sensitive-stanza-1");
    FasteningElement sensitiveFastening = FasteningElement.builder().setOriginId(originIdElement).build();
    FasteningElement shellElement = FasteningElement.createShellElementForSensitiveElement(sensitiveFastening);
    assertEquals(originIdElement, shellElement.getReferencedStanzasOriginId());
}
Also used : FasteningElement(org.jivesoftware.smackx.message_fastening.element.FasteningElement) OriginIdElement(org.jivesoftware.smackx.sid.element.OriginIdElement) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with OriginIdElement

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

the class StableUniqueStanzaIdTest method originIdProviderTest.

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

Example 5 with OriginIdElement

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

the class StableUniqueStanzaIdTest method createOriginIdTest.

@Test
public void createOriginIdTest() {
    OriginIdElement element = new OriginIdElement();
    assertNotNull(element);
    assertEquals(StableUniqueStanzaIdManager.NAMESPACE, element.getNamespace());
    assertEquals(16, element.getId().length());
}
Also used : OriginIdElement(org.jivesoftware.smackx.sid.element.OriginIdElement) Test(org.junit.jupiter.api.Test)

Aggregations

OriginIdElement (org.jivesoftware.smackx.sid.element.OriginIdElement)6 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Date (java.util.Date)2 FasteningElement (org.jivesoftware.smackx.message_fastening.element.FasteningElement)2 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 ExternalElement (org.jivesoftware.smackx.message_fastening.element.ExternalElement)1 RetractedElement (org.jivesoftware.smackx.message_retraction.element.RetractedElement)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1