Search in sources :

Example 51 with XmlPullParser

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());
}
Also used : IdleElement(org.jivesoftware.smackx.last_interaction.element.IdleElement) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 52 with XmlPullParser

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());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) XmlElement(org.jivesoftware.smack.packet.XmlElement) NamedElement(org.jivesoftware.smack.packet.NamedElement) Test(org.junit.jupiter.api.Test)

Example 53 with XmlPullParser

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());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) XmlElement(org.jivesoftware.smack.packet.XmlElement) NamedElement(org.jivesoftware.smack.packet.NamedElement) Test(org.junit.jupiter.api.Test)

Example 54 with XmlPullParser

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());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) XmlElement(org.jivesoftware.smack.packet.XmlElement) NamedElement(org.jivesoftware.smack.packet.NamedElement) Test(org.junit.jupiter.api.Test)

Example 55 with XmlPullParser

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());
}
Also used : HeadersExtension(org.jivesoftware.smackx.shim.packet.HeadersExtension) Message(org.jivesoftware.smack.packet.Message) Header(org.jivesoftware.smackx.shim.packet.Header) 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