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