Search in sources :

Example 1 with FasteningElement

use of org.jivesoftware.smackx.message_fastening.element.FasteningElement 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 2 with FasteningElement

use of org.jivesoftware.smackx.message_fastening.element.FasteningElement in project Smack by igniterealtime.

the class MessageFasteningElementsTest method fasteningElementSerializationTest.

/**
 * Test XML serialization of the {@link FasteningElement} using the example provided by
 * the XEP.
 *
 * @see <a href="https://xmpp.org/extensions/xep-0422.html#wrapped-payloads">XEP-0422 ยง3.1 Wrapped Payloads</a>
 */
@Test
public void fasteningElementSerializationTest() {
    String xml = "<apply-to xmlns='urn:xmpp:fasten:0' id='origin-id-1'>" + "    <i-like-this xmlns='urn:example:like'/>" + "</apply-to>";
    FasteningElement applyTo = FasteningElement.builder().setOriginId("origin-id-1").addWrappedPayload(new StandardExtensionElement("i-like-this", "urn:example:like")).build();
    assertXmlSimilar(xml, applyTo.toXML().toString());
}
Also used : FasteningElement(org.jivesoftware.smackx.message_fastening.element.FasteningElement) StandardExtensionElement(org.jivesoftware.smack.packet.StandardExtensionElement) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with FasteningElement

use of org.jivesoftware.smackx.message_fastening.element.FasteningElement in project Smack by igniterealtime.

the class MessageFasteningElementsTest method fasteningElementWithExternalElementsTest.

@Test
public void fasteningElementWithExternalElementsTest() {
    String xml = "<apply-to xmlns='urn:xmpp:fasten:0' id='origin-id-2'>" + "    <external name='body'/>" + "    <external name='custom' element-namespace='urn:example:custom'/>" + "    <edit xmlns='urn:example.edit'/>" + "</apply-to>";
    FasteningElement element = FasteningElement.builder().setOriginId("origin-id-2").addExternalPayloads(Arrays.asList(new ExternalElement("body"), new ExternalElement("custom", "urn:example:custom"))).addWrappedPayload(new StandardExtensionElement("edit", "urn:example.edit")).build();
    assertXmlSimilar(xml, element.toXML().toString());
}
Also used : FasteningElement(org.jivesoftware.smackx.message_fastening.element.FasteningElement) StandardExtensionElement(org.jivesoftware.smack.packet.StandardExtensionElement) ExternalElement(org.jivesoftware.smackx.message_fastening.element.ExternalElement) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with FasteningElement

use of org.jivesoftware.smackx.message_fastening.element.FasteningElement 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 5 with FasteningElement

use of org.jivesoftware.smackx.message_fastening.element.FasteningElement in project Smack by igniterealtime.

the class MessageFasteningElementsTest method fasteningRemoveSerializationTest.

@Test
public void fasteningRemoveSerializationTest() {
    String xml = "<apply-to xmlns='urn:xmpp:fasten:0' id='origin-id-1' clear='true'>" + "      <i-like-this xmlns='urn:example:like'>Very much</i-like-this>" + "</apply-to>";
    FasteningElement element = FasteningElement.builder().setOriginId("origin-id-1").setClear().addWrappedPayload(StandardExtensionElement.builder("i-like-this", "urn:example:like").setText("Very much").build()).build();
    assertXmlSimilar(xml, element.toXML().toString());
}
Also used : FasteningElement(org.jivesoftware.smackx.message_fastening.element.FasteningElement) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

FasteningElement (org.jivesoftware.smackx.message_fastening.element.FasteningElement)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Test (org.junit.jupiter.api.Test)6 ExternalElement (org.jivesoftware.smackx.message_fastening.element.ExternalElement)3 StandardExtensionElement (org.jivesoftware.smack.packet.StandardExtensionElement)2 OriginIdElement (org.jivesoftware.smackx.sid.element.OriginIdElement)2 MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)1 XmlElement (org.jivesoftware.smack.packet.XmlElement)1 RetractElement (org.jivesoftware.smackx.message_retraction.element.RetractElement)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1