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