Search in sources :

Example 46 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class AMPExtensionTest method isCorrectFromXmlErrorHandling.

@Test
public void isCorrectFromXmlErrorHandling() throws Exception {
    AMPExtensionProvider ampProvider = new AMPExtensionProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(INCORRECT_RECEIVING_STANZA_STREAM);
    assertEquals(AMPExtension.ELEMENT, parser.getName());
    ExtensionElement extension = ampProvider.parse(parser);
    assertTrue(extension instanceof AMPExtension);
    AMPExtension amp = (AMPExtension) extension;
    assertEquals(0, amp.getRulesCount());
    assertEquals(AMPExtension.Status.alert, amp.getStatus());
    assertEquals("bernardo@hamlet.lit/elsinore", amp.getFrom());
    assertEquals("francisco@hamlet.lit", amp.getTo());
}
Also used : AMPExtensionProvider(org.jivesoftware.smackx.amp.provider.AMPExtensionProvider) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) AMPExtension(org.jivesoftware.smackx.amp.packet.AMPExtension) Test(org.junit.jupiter.api.Test)

Example 47 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class AMPExtensionTest method isCorrectFromXmlDeserialization.

@Test
public void isCorrectFromXmlDeserialization() throws Exception {
    AMPExtensionProvider ampProvider = new AMPExtensionProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(CORRECT_SENDING_STANZA_STREAM);
    assertEquals(AMPExtension.ELEMENT, parser.getName());
    ExtensionElement extension = ampProvider.parse(parser);
    assertTrue(extension instanceof AMPExtension);
    AMPExtension amp = (AMPExtension) extension;
    assertEquals(9, amp.getRulesCount());
}
Also used : AMPExtensionProvider(org.jivesoftware.smackx.amp.provider.AMPExtensionProvider) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) AMPExtension(org.jivesoftware.smackx.amp.packet.AMPExtension) Test(org.junit.jupiter.api.Test)

Example 48 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class MoodConcretisationTest method unknownConcretisationTest.

@Test
public void unknownConcretisationTest() throws Exception {
    String xml = "<mood xmlns='http://jabber.org/protocol/mood'>" + "<sad>" + "<owl xmlns='https://reddit.com/r/superbowl/'/>" + "</sad>" + "<text>Hoot hoot!</text>" + "</mood>";
    XmlPullParser parser = TestUtils.getParser(xml);
    MoodElement element = MoodProvider.INSTANCE.parse(parser);
    // We should not have a provider for sad owls, so the concretisation should not be there.
    assertFalse(element.hasConcretisation());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) Test(org.junit.jupiter.api.Test)

Example 49 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class PubSubProviderTest method subscriptionsOwnerResultTest.

@Test
public void subscriptionsOwnerResultTest() throws Exception {
    // @formatter:off
    final String resultStanza = "<iq from='pubsub.example.org' to='julia@example.org/Smack' id='HaT4m-13' type='result'>" + "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>" + "<subscriptions node='test'>" + "<subscription jid='foo@example.org/Smack' subscription='subscribed' subid='58C1A6F99F2A7'/>" + "<subscription jid='julia@example.org/Smack' subscription='subscribed' subid='58C18F8917321'/>" + "</subscriptions>" + "</pubsub>" + "</iq>";
    // @formatter:on
    XmlPullParser parser = TestUtils.getIQParser(resultStanza);
    PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser);
    SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS_OWNER);
    List<Subscription> subscriptions = subElem.getSubscriptions();
    assertEquals(2, subscriptions.size());
    Subscription sub1 = subscriptions.get(0);
    assertThat("foo@example.org/Smack", equalsCharSequence(sub1.getJid()));
    assertEquals(Subscription.State.subscribed, sub1.getState());
    assertEquals("58C1A6F99F2A7", sub1.getId());
    Subscription sub2 = subscriptions.get(1);
    assertThat("julia@example.org/Smack", equalsCharSequence(sub2.getJid()));
    assertEquals(Subscription.State.subscribed, sub2.getState());
    assertEquals("58C18F8917321", sub2.getId());
}
Also used : SubscriptionsExtension(org.jivesoftware.smackx.pubsub.SubscriptionsExtension) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Subscription(org.jivesoftware.smackx.pubsub.Subscription) Test(org.junit.jupiter.api.Test)

Example 50 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class MoodElementTest method unknownMoodValueExceptionTest.

@Test
public void unknownMoodValueExceptionTest() throws Exception {
    String xml = "<mood xmlns='http://jabber.org/protocol/mood'>" + "<unknown/>" + "</mood>";
    XmlPullParser parser = TestUtils.getParser(xml);
    assertThrows(XmlPullParserException.class, () -> {
        MoodProvider.INSTANCE.parse(parser);
    });
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Test(org.junit.jupiter.api.Test)

Aggregations

XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)139 Test (org.junit.jupiter.api.Test)69 Message (org.jivesoftware.smack.packet.Message)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Date (java.util.Date)12 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)11 Jid (org.jxmpp.jid.Jid)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 XmlPullParserException (org.jivesoftware.smack.xml.XmlPullParserException)10 EnumSource (org.junit.jupiter.params.provider.EnumSource)9 IQ (org.jivesoftware.smack.packet.IQ)8 Test (org.junit.Test)8 MarkupElement (org.jivesoftware.smackx.message_markup.element.MarkupElement)7 MarkupElementProvider (org.jivesoftware.smackx.message_markup.provider.MarkupElementProvider)7 XmlElement (org.jivesoftware.smack.packet.XmlElement)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 NamedElement (org.jivesoftware.smack.packet.NamedElement)4 HttpOverXmppResp (org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp)4