Search in sources :

Example 6 with DelayInformation

use of org.jivesoftware.smackx.delay.packet.DelayInformation in project Smack by igniterealtime.

the class QueryArchiveTest method checkMamQueryResults.

@Test
public void checkMamQueryResults() throws Exception {
    Message message = new Message();
    message.setStanzaId("iasd207");
    message.setFrom(JidCreate.from("coven@chat.shakespeare.lit"));
    message.setTo(JidCreate.from("hag66@shakespeare.lit/pda"));
    GregorianCalendar calendar = new GregorianCalendar(2002, 10 - 1, 13, 23, 58, 37);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = calendar.getTime();
    DelayInformation delay = new DelayInformation(date);
    Message forwardedMessage = new Message();
    forwardedMessage.setFrom(JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
    forwardedMessage.setStanzaId("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
    forwardedMessage.setType(Type.chat);
    forwardedMessage.setBody("Thrice the brinded cat hath mew.");
    Forwarded forwarded = new Forwarded(delay, forwardedMessage);
    message.addExtension(new MamResultExtension("g27", "34482-21985-73620", forwarded));
    Assert.assertEquals(message.toXML().toString(), mamQueryResultExample);
    MamResultExtension mamResultExtension = MamResultExtension.from(message);
    Assert.assertEquals(mamResultExtension.getId(), "34482-21985-73620");
    Assert.assertEquals(mamResultExtension.getForwarded().getDelayInformation().getStamp(), date);
    Message resultMessage = (Message) mamResultExtension.getForwarded().getForwardedStanza();
    Assert.assertEquals(resultMessage.getFrom(), JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
    Assert.assertEquals(resultMessage.getStanzaId(), "162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
    Assert.assertEquals(resultMessage.getType(), Type.chat);
    Assert.assertEquals(resultMessage.getBody(), "Thrice the brinded cat hath mew.");
}
Also used : Message(org.jivesoftware.smack.packet.Message) DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) GregorianCalendar(java.util.GregorianCalendar) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) MamResultExtension(org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension) Date(java.util.Date) Test(org.junit.Test)

Example 7 with DelayInformation

use of org.jivesoftware.smackx.delay.packet.DelayInformation in project Smack by igniterealtime.

the class AbstractDelayInformationProvider method parse.

@Override
public final DelayInformation parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
    String stampString = (parser.getAttributeValue("", "stamp"));
    String from = parser.getAttributeValue("", "from");
    String reason = null;
    if (!parser.isEmptyElementTag()) {
        int event = parser.next();
        switch(event) {
            case XmlPullParser.TEXT:
                reason = parser.getText();
                parser.next();
                break;
            case XmlPullParser.END_TAG:
                reason = "";
                break;
            default:
                throw new IllegalStateException("Unexpected event: " + event);
        }
    } else {
        parser.next();
    }
    Date stamp;
    try {
        stamp = parseDate(stampString);
    } catch (ParseException e) {
        throw new SmackException(e);
    }
    return new DelayInformation(stamp, from, reason);
}
Also used : DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) SmackException(org.jivesoftware.smack.SmackException) ParseException(java.text.ParseException) Date(java.util.Date)

Example 8 with DelayInformation

use of org.jivesoftware.smackx.delay.packet.DelayInformation in project Smack by igniterealtime.

the class DelayInformationTest method validatePresenceWithDelayedDelivery.

@Test
public void validatePresenceWithDelayedDelivery() throws Exception {
    String stanza = "<presence from='mercutio@example.com' to='juliet@example.com'>" + "<delay xmlns='urn:xmpp:delay' stamp='2002-09-10T23:41:07Z'/></presence>";
    Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
    DelayInformation delay = DelayInformationManager.getXep203DelayInformation(presence);
    assertNotNull(delay);
    Date date = XmppDateTime.parseDate("2002-09-10T23:41:07Z");
    assertEquals(date, delay.getStamp());
}
Also used : DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) Presence(org.jivesoftware.smack.packet.Presence) Date(java.util.Date) Test(org.junit.Test)

Example 9 with DelayInformation

use of org.jivesoftware.smackx.delay.packet.DelayInformation in project Smack by igniterealtime.

the class DelayInformationTest method dateFormatsTest.

@Test
public void dateFormatsTest() throws Exception {
    DelayInformationProvider p = new DelayInformationProvider();
    DelayInformation delayInfo;
    String control;
    // XEP-0082 date format
    control = XMLBuilder.create("delay").a("xmlns", "urn:xmpp:delay").a("from", "capulet.com").a("stamp", "2002-09-10T23:08:25.12Z").asString(outputProperties);
    delayInfo = p.parse(PacketParserUtils.getParserFor(control));
    GregorianCalendar cal = (GregorianCalendar) calendar.clone();
    cal.add(Calendar.MILLISECOND, 120);
    assertEquals(cal.getTime(), delayInfo.getStamp());
    // XEP-0082 date format without milliseconds
    control = XMLBuilder.create("delay").a("xmlns", "urn:xmpp:delay").a("from", "capulet.com").a("stamp", "2002-09-10T23:08:25Z").asString(outputProperties);
    delayInfo = p.parse(PacketParserUtils.getParserFor(control));
    assertEquals(calendar.getTime(), delayInfo.getStamp());
    // XEP-0082 date format without milliseconds and leading 0 in month
    control = XMLBuilder.create("delay").a("xmlns", "urn:xmpp:delay").a("from", "capulet.com").a("stamp", "2002-9-10T23:08:25Z").asString(outputProperties);
    delayInfo = p.parse(PacketParserUtils.getParserFor(control));
    assertEquals(calendar.getTime(), delayInfo.getStamp());
}
Also used : DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Example 10 with DelayInformation

use of org.jivesoftware.smackx.delay.packet.DelayInformation in project Smack by igniterealtime.

the class DelayInformationTest method delayInformationTest.

@Test
public void delayInformationTest() throws Exception {
    DelayInformationProvider p = new DelayInformationProvider();
    DelayInformation delayInfo;
    XmlPullParser parser;
    String control;
    GregorianCalendar calendar = new GregorianCalendar(2002, 9 - 1, 10, 23, 8, 25);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = calendar.getTime();
    control = XMLBuilder.create("x").a("xmlns", "jabber:x:delay").a("from", "capulet.com").a("stamp", "2002-09-10T23:08:25Z").t("Offline Storage").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    delayInfo = p.parse(parser);
    assertEquals("capulet.com", delayInfo.getFrom());
    assertEquals(date, delayInfo.getStamp());
    assertEquals("Offline Storage", delayInfo.getReason());
    assertEquals(XmlPullParser.END_TAG, parser.getEventType());
    assertEquals("x", parser.getName());
    control = XMLBuilder.create("x").a("xmlns", "jabber:x:delay").a("from", "capulet.com").a("stamp", "2002-09-10T23:08:25Z").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    delayInfo = p.parse(parser);
    assertEquals("capulet.com", delayInfo.getFrom());
    assertEquals(date, delayInfo.getStamp());
    assertNull(delayInfo.getReason());
    assertEquals(XmlPullParser.END_TAG, parser.getEventType());
    assertEquals("x", parser.getName());
}
Also used : DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) XmlPullParser(org.xmlpull.v1.XmlPullParser) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)11 Test (org.junit.Test)7 Date (java.util.Date)6 GregorianCalendar (java.util.GregorianCalendar)4 SmackException (org.jivesoftware.smack.SmackException)3 Forwarded (org.jivesoftware.smackx.forward.packet.Forwarded)3 Message (org.jivesoftware.smack.packet.Message)2 Presence (org.jivesoftware.smack.packet.Presence)2 Stanza (org.jivesoftware.smack.packet.Stanza)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 NetworkException (com.xabber.android.data.NetworkException)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 DelayInformationProvider (org.jivesoftware.smackx.delay.provider.DelayInformationProvider)1 ForwardedProvider (org.jivesoftware.smackx.forward.provider.ForwardedProvider)1 MamResultExtension (org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension)1