use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class IdleTest method providerTest.
@Test
public void providerTest() throws Exception {
String xml = "<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z' />";
XmlPullParser parser = TestUtils.getParser(xml);
assertNotNull(parser);
IdleElement parsed = IdleProvider.TEST_INSTANCE.parse(parser);
Date date = XmppDateTime.parseXEP0082Date("1969-07-21T02:56:15Z");
assertEquals(date, parsed.getSince());
IdleElement element = new IdleElement(date);
assertXmlSimilar("<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15.000+00:00'/>", element.toXML().toString());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class ItemValidationTest method parseSimplePayloadItem.
@Test
public void parseSimplePayloadItem() throws Exception {
String itemContent = "<foo xmlns='smack:test'>Some text</foo>";
XmlPullParser parser = PacketParserUtils.getParserFor("<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" + "<event xmlns='http://jabber.org/protocol/pubsub#event'>" + "<items node='testNode'>" + "<item id='testid1' >" + itemContent + "</item>" + "</items>" + "</event>" + "</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
XmlElement eventExt = message.getExtension(PubSubNamespace.event.getXmlns());
EventElement event = (EventElement) eventExt;
NamedElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>) itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
SimplePayload payload = (SimplePayload) item.getPayload();
assertEquals("foo", payload.getElementName());
assertEquals("smack:test", payload.getNamespace());
assertXmlSimilar(itemContent, payload.toXML().toString());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class ItemValidationTest method parseComplexItem.
@Test
public void parseComplexItem() throws Exception {
String itemContent = "<entry xmlns='http://www.w3.org/2005/Atom'>" + "<title>Soliloquy</title>" + "<summary>" + "To be, or not to be: that is the question:" + "Whether 'tis nobler in the mind to suffer" + "The slings and arrows of outrageous fortune," + "Or to take arms against a sea of troubles," + "And by opposing end them?" + "</summary>" + "<link rel='alternate' type='text/html' href='http://denmark.lit/2003/12/13/atom03'/>" + "<id>tag:denmark.lit,2003:entry-32397</id>" + "<published>2003-12-13T18:30:02Z</published>" + "<updated>2003-12-13T18:30:02Z</updated>" + "</entry>";
XmlPullParser parser = PacketParserUtils.getParserFor("<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" + "<event xmlns='http://jabber.org/protocol/pubsub#event'>" + "<items node='testNode'>" + "<item id='testid1' >" + itemContent + "</item>" + "</items>" + "</event>" + "</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
XmlElement eventExt = message.getExtension(PubSubNamespace.event.getXmlns());
EventElement event = (EventElement) eventExt;
NamedElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>) itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
SimplePayload payload = (SimplePayload) item.getPayload();
assertEquals("entry", payload.getElementName());
assertEquals("http://www.w3.org/2005/Atom", payload.getNamespace());
assertXmlSimilar(itemContent, payload.toXML().toString());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class ItemValidationTest method parseBasicItem.
@Test
public void parseBasicItem() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor("<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" + "<event xmlns='http://jabber.org/protocol/pubsub#event'>" + "<items node='testNode'>" + "<item id='testid1' />" + "</items>" + "</event>" + "</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
XmlElement eventExt = message.getExtension(PubSubNamespace.event.getXmlns());
assertTrue(eventExt instanceof EventElement);
EventElement event = (EventElement) eventExt;
assertEquals(EventElementType.items, event.getEventType());
assertEquals(1, event.getExtensions().size());
assertTrue(event.getExtensions().get(0) instanceof ItemsExtension);
assertEquals(1, ((ItemsExtension) event.getExtensions().get(0)).items.size());
NamedElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof Item);
assertEquals("testid1", ((Item) itemExt).getId());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class HeadersProviderTest method headersInMessageTest.
@Test
public void headersInMessageTest() throws Exception {
// @formatter:off
final String messageStanza = "<message xmlns='jabber:client' from='romeo@shakespeare.lit/orchard' to='juliet@capulet.com' type='chat'>" + "<body>Wherefore are thou?!?</body>" + "<headers xmlns='http://jabber.org/protocol/shim'>" + "<header name='Urgency'>high</header>" + "</headers>" + "</message>";
// @formatter:on
XmlPullParser parser = TestUtils.getMessageParser(messageStanza);
Message message = PacketParserUtils.parseMessage(parser);
HeadersExtension headers = HeadersExtension.from(message);
Header header = headers.getHeaders().get(0);
assertEquals("Urgency", header.getName());
assertEquals("high", header.getValue());
}
Aggregations